1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-06 05:07:41 +02:00

feat(entries): add _include directive for entries fields collections

This feature will allow to reuse fields from another entries collection

Example of usage:

```
    shop:
      pattern: shop
      filename: entry
      extension: yaml
      serializer: yaml
      fields:
        _include:
          collection: default
          except: ['id', 'visibility']
```
This commit is contained in:
Awilum
2022-05-04 17:55:13 +03:00
parent 9065dba5c4
commit fab2c4dc0e

View File

@@ -162,7 +162,7 @@ class Entries
}
$fields = collection($fields)->unique()->toArray();
foreach ($fields as $field) {
if (filesystem()->file($field)->exists()) {
include_once $field;
@@ -182,12 +182,21 @@ class Entries
private function getCollectionOptions(string $id): array
{
$result = $this->options['collections']['default'];
$fieldsToInclude = [];
foreach ($this->options['collections'] as $collection) {
if (isset($collection['fields']['_include']['collection'])) {
$fieldsToInclude = $this->options['collections'][$collection['fields']['_include']['collection']]['fields'];
if (isset($collection['fields']['_include']['except'])) {
$fieldsToInclude = collection($fieldsToInclude)->except($collection['fields']['_include']['except'])->toArray();
}
}
if (isset($collection['pattern'])) {
if (boolval(preg_match_all('#^' . $collection['pattern'] . '$#', $id, $matches, PREG_OFFSET_CAPTURE))) {
$result = $collection;
$result['fields'] = array_merge($fieldsToInclude, $result['fields'] ?? []);
}
}
}