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:
@@ -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'] ?? []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user