From d5ffed216fd80add18af1a987490e1d7c3d49d9b Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 7 Aug 2021 10:40:01 +0300 Subject: [PATCH] feat(fields): update logic for setting `enabled`, affected all fields #564 --- src/flextype/Content/Fields/ContentField.php | 80 +++++------ .../Content/Fields/CreatedAtField.php | 35 +++-- .../Content/Fields/CreatedByField.php | 20 +-- src/flextype/Content/Fields/IdField.php | 20 +-- src/flextype/Content/Fields/MediaField.php | 129 ++++++------------ .../Content/Fields/ModifiedAtField.php | 19 +-- src/flextype/Content/Fields/ParsersField.php | 64 ++++----- .../Content/Fields/PublishedAtField.php | 38 ++++-- .../Content/Fields/PublishedByField.php | 19 +-- src/flextype/Content/Fields/RegistryField.php | 37 ++--- src/flextype/Content/Fields/RoutableField.php | 40 +++--- src/flextype/Content/Fields/SlugField.php | 20 +-- src/flextype/Content/Fields/UuidField.php | 19 +-- .../Content/Fields/VisibilityField.php | 46 ++++--- src/flextype/Media/Fields/CreatedAtField.php | 35 +++-- src/flextype/Media/Fields/CreatedByField.php | 19 +-- src/flextype/Media/Fields/IdField.php | 20 +-- src/flextype/Media/Fields/ModifiedAtField.php | 19 +-- src/flextype/Media/Fields/UuidField.php | 19 +-- src/flextype/settings.yaml | 61 ++++----- 20 files changed, 390 insertions(+), 369 deletions(-) diff --git a/src/flextype/Content/Fields/ContentField.php b/src/flextype/Content/Fields/ContentField.php index 4518aeab..9554cc48 100644 --- a/src/flextype/Content/Fields/ContentField.php +++ b/src/flextype/Content/Fields/ContentField.php @@ -9,49 +9,53 @@ declare(strict_types=1); use Atomastic\Arrays\Arrays; -if (registry()->get('flextype.settings.storage.content.fields.content.fetch.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->has('fetch.data.content.fetch')) { - // Get fetch. - $original = content()->registry()->get('fetch'); - $data = []; - switch (registry()->get('flextype.settings.storage.content.fields.content.fetch.result')) { - case 'toArray': - $resultTo = 'toArray'; - break; +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - case 'toObject': - default: - $resultTo = 'copy'; - break; - } + if (! registry()->get('flextype.settings.entries.content.fields.content.fetch.enabled')) { + return; + } - // Modify fetch. - foreach (content()->registry()->get('fetch.data.content.fetch') as $field => $body) { + if (content()->registry()->has('fetch.data.content.fetch')) { + // Get fetch. + $original = content()->registry()->get('fetch'); + $data = []; - if (isset($body['options']['method']) && - strpos($body['options']['method'], 'fetch') !== false && - is_callable([content(), $body['options']['method']])) { - $fetchFromCallbackMethod = $body['options']['method']; - } else { - $fetchFromCallbackMethod = 'fetch'; - } + switch (registry()->get('flextype.settings.entries.content.fields.content.fetch.result')) { + case 'toArray': + $resultTo = 'toArray'; + break; - $result = isset($body['result']) && in_array($body['result'], ['toArray', 'toObject']) ? $body['result'] : $resultTo; + case 'toObject': + default: + $resultTo = 'copy'; + break; + } - $data[$field] = content()->{$fetchFromCallbackMethod}($body['id'], - isset($body['options']) ? - $body['options'] : - []); + // Modify fetch. + foreach (content()->registry()->get('fetch.data.content.fetch') as $field => $body) { - $data[$field] = ($data[$field] instanceof Arrays) ? $data[$field]->{$result}() : $data[$field]; - } + if (isset($body['options']['method']) && + strpos($body['options']['method'], 'fetch') !== false && + is_callable([content(), $body['options']['method']])) { + $fetchFromCallbackMethod = $body['options']['method']; + } else { + $fetchFromCallbackMethod = 'fetch'; + } - // Save fetch. - content()->registry()->set('fetch.id', $original['id']); - content()->registry()->set('fetch.options', $original['options']); - content()->registry()->set('fetch.data', arrays($original['data'])->merge($data)->toArray()); - } - }); -} + $result = isset($body['result']) && in_array($body['result'], ['toArray', 'toObject']) ? $body['result'] : $resultTo; + + $data[$field] = content()->{$fetchFromCallbackMethod}($body['id'], + isset($body['options']) ? + $body['options'] : + []); + + $data[$field] = ($data[$field] instanceof Arrays) ? $data[$field]->{$result}() : $data[$field]; + } + + // Save fetch. + content()->registry()->set('fetch.id', $original['id']); + content()->registry()->set('fetch.options', $original['options']); + content()->registry()->set('fetch.data', arrays($original['data'])->merge($data)->toArray()); + } +}); \ No newline at end of file diff --git a/src/flextype/Content/Fields/CreatedAtField.php b/src/flextype/Content/Fields/CreatedAtField.php index d061b041..92fd6658 100644 --- a/src/flextype/Content/Fields/CreatedAtField.php +++ b/src/flextype/Content/Fields/CreatedAtField.php @@ -7,23 +7,28 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { -if (registry()->get('flextype.settings.storage.content.fields.created_at.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->get('fetch.data.created_at') === null) { - content()->registry()->set('fetch.data.created_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); - } else { - content()->registry()->set('fetch.data.created_at', (int) strtotime((string) content()->registry()->get('fetch.data.created_at'))); - } - }); + if (! registry()->get('flextype.settings.entries.content.fields.created_at.enabled')) { + return; + } - emitter()->addListener('onContentCreate', static function (): void { - if (content()->registry()->get('create.data.created_at') !== null) { - return; - } + if (content()->registry()->get('fetch.data.created_at') === null) { + content()->registry()->set('fetch.data.created_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); + } else { + content()->registry()->set('fetch.data.created_at', (int) strtotime((string) content()->registry()->get('fetch.data.created_at'))); + } +}); - content()->registry()->set('create.data.created_at', date(registry()->get('flextype.settings.date_format'), time())); - }); -} +emitter()->addListener('onContentCreate', static function (): void { + if (registry()->get('flextype.settings.entries.content.fields.created_at.enabled')) { + return; + } + if (content()->registry()->get('create.data.created_at') !== null) { + return; + } + + content()->registry()->set('create.data.created_at', date(registry()->get('flextype.settings.date_format'), time())); +}); diff --git a/src/flextype/Content/Fields/CreatedByField.php b/src/flextype/Content/Fields/CreatedByField.php index 0df4e3f1..df760c6b 100644 --- a/src/flextype/Content/Fields/CreatedByField.php +++ b/src/flextype/Content/Fields/CreatedByField.php @@ -7,12 +7,16 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.storage.content.fields.created_by.enabled')) { - emitter()->addListener('onContentCreate', static function (): void { - if (content()->registry()->get('create.data.created_by') !== null) { - return; - } +emitter()->addListener('onContentCreate', static function (): void { + + if (! registry()->get('flextype.settings.entries.content.fields.created_by.enabled')) { + return; + } + + if (content()->registry()->get('create.data.created_by') !== null) { + return; + } + + content()->registry()->set('create.data.created_by', ''); +}); - content()->registry()->set('create.data.created_by', ''); - }); -} diff --git a/src/flextype/Content/Fields/IdField.php b/src/flextype/Content/Fields/IdField.php index 2ead7dab..29196aa8 100644 --- a/src/flextype/Content/Fields/IdField.php +++ b/src/flextype/Content/Fields/IdField.php @@ -7,15 +7,15 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ - -if (registry()->get('flextype.settings.storage.content.fields.id.enabled')) { +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - - if (content()->registry()->get('fetch.data.id') !== null) { - return; - } + if (! registry()->get('flextype.settings.entries.content.fields.id.enabled')) { + return; + } - content()->registry()->set('fetch.data.id', (string) strings(content()->registry()->get('fetch.id'))->trimSlashes()); - }); -} + if (content()->registry()->get('fetch.data.id') !== null) { + return; + } + + content()->registry()->set('fetch.data.id', strings(content()->registry()->get('fetch.id'))->trimSlashes()->toString()); +}); \ No newline at end of file diff --git a/src/flextype/Content/Fields/MediaField.php b/src/flextype/Content/Fields/MediaField.php index 0508121e..dc505749 100644 --- a/src/flextype/Content/Fields/MediaField.php +++ b/src/flextype/Content/Fields/MediaField.php @@ -9,100 +9,53 @@ declare(strict_types=1); use Atomastic\Arrays\Arrays; -if (registry()->get('flextype.settings.storage.content.fields.media.files.fetch.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->has('fetch.data.media.files.fetch')) { - // Get fetch. - $original = content()->registry()->get('fetch'); - $data = []; +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { + + if (! registry()->get('flextype.settings.entries.content.fields.media.enabled')) { + return; + } - switch (registry()->get('flextype.settings.storage.content.fields.media.files.fetch.result')) { - case 'toArray': - $resultTo = 'toArray'; - break; + if (content()->registry()->has('fetch.data.media.fetch')) { + // Get fetch. + $original = content()->registry()->get('fetch'); + $data = []; - case 'toObject': - default: - $resultTo = 'copy'; - break; - } + switch (registry()->get('flextype.settings.entries.content.fields.media.files.fetch.result')) { + case 'toArray': + $resultTo = 'toArray'; + break; - // Modify fetch. - foreach (content()->registry()->get('fetch.data.media.files.fetch') as $field => $body) { + case 'toObject': + default: + $resultTo = 'copy'; + break; + } - if (isset($body['options']['method']) && - strpos($body['options']['method'], 'fetch') !== false && - is_callable([flextype('media')->files(), $body['options']['method']])) { - $fetchFromCallbackMethod = $body['options']['method']; - } else { - $fetchFromCallbackMethod = 'fetch'; - } + // Modify fetch. + foreach (content()->registry()->get('fetch.data.media.files.fetch') as $field => $body) { + + if (isset($body['options']['method']) && + strpos($body['options']['method'], 'fetch') !== false && + is_callable([flextype('media')->files(), $body['options']['method']])) { + $fetchFromCallbackMethod = $body['options']['method']; + } else { + $fetchFromCallbackMethod = 'fetch'; + } - $result = isset($body['result']) && in_array($body['result'], ['toArray', 'toObject']) ? $body['result'] : $resultTo; + $result = isset($body['result']) && in_array($body['result'], ['toArray', 'toObject']) ? $body['result'] : $resultTo; - $data[$field] = flextype('media')->files()->{$fetchFromCallbackMethod}($body['id'], - isset($body['options']) ? - $body['options'] : - []); + $data[$field] = flextype('media')->files()->{$fetchFromCallbackMethod}($body['id'], + isset($body['options']) ? + $body['options'] : + []); - $data[$field] = ($data[$field] instanceof Arrays) ? $data[$field]->{$result}() : $data[$field]; - } + $data[$field] = ($data[$field] instanceof Arrays) ? $data[$field]->{$result}() : $data[$field]; + } - // Save fetch. - content()->registry()->set('fetch.id', $original['id']); - content()->registry()->set('fetch.options', $original['options']); - content()->registry()->set('fetch.data', arrays($original['data'])->merge($data)->toArray()); - } - }); -} - - -if (registry()->get('flextype.settings.storage.content.fields.media.folders.fetch.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->has('fetch.data.media.folders.fetch')) { - - // Get fetch. - $original = content()->registry()->get('fetch'); - $data = []; - - switch (registry()->get('flextype.settings.storage.content.fields.media.folders.fetch.result')) { - case 'toArray': - $resultTo = 'toArray'; - break; - - case 'toObject': - default: - $resultTo = 'copy'; - break; - } - - // Modify fetch. - foreach (content()->registry()->get('fetch.data.media.folders.fetch') as $field => $body) { - - if (isset($body['options']['method']) && - strpos($body['options']['method'], 'fetch') !== false && - is_callable([flextype('media')->folders(), $body['options']['method']])) { - $fetchFromCallbackMethod = $body['options']['method']; - } else { - $fetchFromCallbackMethod = 'fetch'; - } - - - $result = isset($body['result']) && in_array($body['result'], ['toArray', 'toObject']) ? $body['result'] : $resultTo; - - $data[$field] = flextype('media')->folders()->{$fetchFromCallbackMethod}($body['id'], - isset($body['options']) ? - $body['options'] : - []); - - $data[$field] = ($data[$field] instanceof Arrays) ? $data[$field]->{$result}() : $data[$field]; - } - - // Save fetch. - content()->registry()->set('fetch.id', $original['id']); - content()->registry()->set('fetch.options', $original['options']); - content()->registry()->set('fetch.data', arrays($original['data'])->merge($data)->toArray()); - } - }); -} + // Save fetch. + content()->registry()->set('fetch.id', $original['id']); + content()->registry()->set('fetch.options', $original['options']); + content()->registry()->set('fetch.data', arrays($original['data'])->merge($data)->toArray()); + } +}); \ No newline at end of file diff --git a/src/flextype/Content/Fields/ModifiedAtField.php b/src/flextype/Content/Fields/ModifiedAtField.php index 96f03e53..c9682d15 100644 --- a/src/flextype/Content/Fields/ModifiedAtField.php +++ b/src/flextype/Content/Fields/ModifiedAtField.php @@ -7,12 +7,15 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.storage.content.fields.modified_at.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->get('fetch.data.modified_at') !== null) { - return; - } +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { + + if (! registry()->get('flextype.settings.entries.content.fields.modified_at.enabled')) { + return; + } + + if (content()->registry()->get('fetch.data.modified_at') !== null) { + return; + } - content()->registry()->set('fetch.data.modified_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); - }); -} + content()->registry()->set('fetch.data.modified_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); +}); diff --git a/src/flextype/Content/Fields/ParsersField.php b/src/flextype/Content/Fields/ParsersField.php index 21c771a0..ad664d5f 100644 --- a/src/flextype/Content/Fields/ParsersField.php +++ b/src/flextype/Content/Fields/ParsersField.php @@ -7,37 +7,39 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.storage.content.fields.parsers.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { + + if (registry()->get('flextype.settings.entries.content.fields.parsers.enabled')) { + return; + } + + if (content()->registry()->get('fetch.data.cache.enabled') == null) { + $cache = false; + } else { + $cache = (bool) content()->registry()->get('fetch.data.cache.enabled'); + } + + if (content()->registry()->get('fetch.data.parsers') != null) { - if (content()->registry()->get('fetch.data.cache.enabled') == null) { - $cache = false; - } else { - $cache = (bool) content()->registry()->get('fetch.data.cache.enabled'); - } - - if (content()->registry()->get('fetch.data.parsers') != null) { - - foreach (content()->registry()->get('fetch.data.parsers') as $parserName => $parserData) { - if (in_array($parserName, ['shortcodes', 'markdown'])) { - - if (content()->registry()->get('fetch.data.parsers.'.$parserName.'.enabled') === true) { - if (content()->registry()->get('fetch.data.parsers.'.$parserName.'.fields') != null) { - if (is_array(content()->registry()->get('fetch.data.parsers.'.$parserName.'.fields'))) { - foreach (content()->registry()->get('fetch.data.parsers.'.$parserName.'.fields') as $field) { - if (! in_array($field, registry()->get('flextype.settings.storage.content.fields'))) { - if ($parserName == 'markdown') { - if (arrays(content()->registry()->get('fetch.data'))->has($field)) { - content()->registry()->set('fetch.data.'.$field, - parsers()->markdown()->parse(content()->registry()->get('fetch.data.'.$field), $cache)); - } + foreach (content()->registry()->get('fetch.data.parsers') as $parserName => $parserData) { + if (in_array($parserName, ['shortcodes', 'markdown'])) { + + if (content()->registry()->get('fetch.data.parsers.'.$parserName.'.enabled') === true) { + if (content()->registry()->get('fetch.data.parsers.'.$parserName.'.fields') != null) { + if (is_array(content()->registry()->get('fetch.data.parsers.'.$parserName.'.fields'))) { + foreach (content()->registry()->get('fetch.data.parsers.'.$parserName.'.fields') as $field) { + if (! in_array($field, registry()->get('flextype.settings.entries.content.fields'))) { + if ($parserName == 'markdown') { + if (arrays(content()->registry()->get('fetch.data'))->has($field)) { + content()->registry()->set('fetch.data.'.$field, + parsers()->markdown()->parse(content()->registry()->get('fetch.data.'.$field), $cache)); } - - if ($parserName == 'shortcodes') { - if (arrays(content()->registry()->get('fetch.data'))->has($field)) { - content()->registry()->set('fetch.data.'.$field, - parsers()->shortcodes()->parse(content()->registry()->get('fetch.data.'.$field), $cache)); - } + } + + if ($parserName == 'shortcodes') { + if (arrays(content()->registry()->get('fetch.data'))->has($field)) { + content()->registry()->set('fetch.data.'.$field, + parsers()->shortcodes()->parse(content()->registry()->get('fetch.data.'.$field), $cache)); } } } @@ -47,5 +49,5 @@ if (registry()->get('flextype.settings.storage.content.fields.parsers.enabled')) } } } - }); -} + } +}); diff --git a/src/flextype/Content/Fields/PublishedAtField.php b/src/flextype/Content/Fields/PublishedAtField.php index 7ece602b..96f4f80e 100644 --- a/src/flextype/Content/Fields/PublishedAtField.php +++ b/src/flextype/Content/Fields/PublishedAtField.php @@ -7,20 +7,28 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.storage.content.fields.published_at.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->get('fetch.data.published_at') === null) { - content()->registry()->set('fetch.data.published_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); - } else { - content()->registry()->set('fetch.data.published_at', (int) strtotime((string) content()->registry()->get('fetch.data.published_at'))); - } - }); +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - emitter()->addListener('onContentCreate', static function (): void { - if (content()->registry()->get('create.data.published_at') !== null) { - return; - } + if (registry()->get('flextype.settings.entries.content.fields.published_at.enabled')) { + return; + } - content()->registry()->set('create.data.published_at', date(registry()->get('flextype.settings.date_format'), time())); - }); -} \ No newline at end of file + if (content()->registry()->get('fetch.data.published_at') === null) { + content()->registry()->set('fetch.data.published_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); + } else { + content()->registry()->set('fetch.data.published_at', (int) strtotime((string) content()->registry()->get('fetch.data.published_at'))); + } +}); + +emitter()->addListener('onContentCreate', static function (): void { + + if (registry()->get('flextype.settings.entries.content.fields.published_at.enabled')) { + return; + } + + if (content()->registry()->get('create.data.published_at') !== null) { + return; + } + + content()->registry()->set('create.data.published_at', date(registry()->get('flextype.settings.date_format'), time())); +}); \ No newline at end of file diff --git a/src/flextype/Content/Fields/PublishedByField.php b/src/flextype/Content/Fields/PublishedByField.php index dffec238..c1a8f74b 100644 --- a/src/flextype/Content/Fields/PublishedByField.php +++ b/src/flextype/Content/Fields/PublishedByField.php @@ -7,12 +7,15 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.storage.content.fields.published_by.enabled')) { - emitter()->addListener('onContentCreate', static function (): void { - if (content()->registry()->get('create.data.published_by') !== null) { - return; - } +emitter()->addListener('onContentCreate', static function (): void { + + if (registry()->get('flextype.settings.entries.content.fields.published_by.enabled')) { + return; + } - content()->registry()->set('create.data.published_by', ''); - }); -} + if (content()->registry()->get('create.data.published_by') !== null) { + return; + } + + content()->registry()->set('create.data.published_by', ''); +}); \ No newline at end of file diff --git a/src/flextype/Content/Fields/RegistryField.php b/src/flextype/Content/Fields/RegistryField.php index 4b4f016c..5a74da3d 100644 --- a/src/flextype/Content/Fields/RegistryField.php +++ b/src/flextype/Content/Fields/RegistryField.php @@ -7,25 +7,28 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.storage.content.fields.registry.get.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->has('fetch.data.registry.get')) { - // Get fetch. - $original = content()->registry()->get('fetch'); +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - $data = []; + if (registry()->get('flextype.settings.entries.content.fields.registry.enabled')) { + return; + } - // Modify fetch. - foreach (content()->registry()->get('fetch.data.registry.get') as $field => $body) { - $data = arrays($data)->merge(arrays($data)->set($field, registry()->get($body['key'], - isset($body['default']) ? - $body['default'] : - []))->toArray())->toArray(); + if (content()->registry()->has('fetch.data.registry.get')) { + // Get fetch. + $original = content()->registry()->get('fetch'); - } + $data = []; + + // Modify fetch. + foreach (content()->registry()->get('fetch.data.registry.get') as $field => $body) { + $data = arrays($data)->merge(arrays($data)->set($field, registry()->get($body['key'], + isset($body['default']) ? + $body['default'] : + []))->toArray())->toArray(); - // Save fetch. - content()->registry()->set('fetch.data', arrays($original['data'])->merge($data)->toArray()); } - }); -} + + // Save fetch. + content()->registry()->set('fetch.data', arrays($original['data'])->merge($data)->toArray()); + } +}); \ No newline at end of file diff --git a/src/flextype/Content/Fields/RoutableField.php b/src/flextype/Content/Fields/RoutableField.php index 7147980f..c89b613a 100644 --- a/src/flextype/Content/Fields/RoutableField.php +++ b/src/flextype/Content/Fields/RoutableField.php @@ -7,21 +7,29 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { + + if (registry()->get('flextype.settings.entries.content.fields.routable.enabled')) { + return; + } -if (registry()->get('flextype.settings.storage.content.fields.routable.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->get('fetch.data.routable') === null) { - content()->registry()->set('fetch.data.routable', true); - } else { - content()->registry()->set('fetch.data.routable', (bool) content()->registry()->get('fetch.data.routable')); - } - }); + if (content()->registry()->get('fetch.data.routable') === null) { + content()->registry()->set('fetch.data.routable', true); + } else { + content()->registry()->set('fetch.data.routable', (bool) content()->registry()->get('fetch.data.routable')); + } - emitter()->addListener('onContentCreate', static function (): void { - if (content()->registry()->get('create.data.routable') === null) { - content()->registry()->set('create.data.routable', true); - } else { - content()->registry()->set('create.data.routable', (bool) content()->registry()->get('create.data.routable')); - } - }); -} +}); + +emitter()->addListener('onContentCreate', static function (): void { + + if (registry()->get('flextype.settings.entries.content.fields.routable.enabled')) { + return; + } + + if (content()->registry()->get('create.data.routable') === null) { + content()->registry()->set('create.data.routable', true); + } else { + content()->registry()->set('create.data.routable', (bool) content()->registry()->get('create.data.routable')); + } +}); diff --git a/src/flextype/Content/Fields/SlugField.php b/src/flextype/Content/Fields/SlugField.php index c2a77133..e77af90f 100644 --- a/src/flextype/Content/Fields/SlugField.php +++ b/src/flextype/Content/Fields/SlugField.php @@ -7,14 +7,16 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { -if (registry()->get('flextype.settings.storage.content.fields.slug.enabled')) { - emitter()->addListener('onContentFetchSingleHasResult', static function (): void { - if (content()->registry()->get('fetch.data.slug') !== null) { - return; - } + if (registry()->get('flextype.settings.entries.content.fields.slug.enabled')) { + return; + } - $parts = explode('/', ltrim(rtrim(content()->registry()->get('fetch.id'), '/'), '/')); - content()->registry()->set('fetch.data.slug', (string) end($parts)); - }); -} + if (content()->registry()->get('fetch.data.slug') !== null) { + return; + } + + $parts = explode('/', ltrim(rtrim(content()->registry()->get('fetch.id'), '/'), '/')); + content()->registry()->set('fetch.data.slug', (string) end($parts)); +}); diff --git a/src/flextype/Content/Fields/UuidField.php b/src/flextype/Content/Fields/UuidField.php index fa1333a4..75ed1fd4 100644 --- a/src/flextype/Content/Fields/UuidField.php +++ b/src/flextype/Content/Fields/UuidField.php @@ -9,12 +9,15 @@ declare(strict_types=1); use Ramsey\Uuid\Uuid; -if (registry()->get('flextype.settings.storage.content.fields.uuid.enabled')) { - emitter()->addListener('onContentCreate', static function (): void { - if (content()->registry()->get('create.data.uuid') !== null) { - return; - } +emitter()->addListener('onContentCreate', static function (): void { - content()->registry()->set('create.data.uuid', Uuid::uuid4()->toString()); - }); -} + if (registry()->get('flextype.settings.entries.content.fields.uuid.enabled')) { + return; + } + + if (content()->registry()->get('create.data.uuid') !== null) { + return; + } + + content()->registry()->set('create.data.uuid', Uuid::uuid4()->toString()); +}); diff --git a/src/flextype/Content/Fields/VisibilityField.php b/src/flextype/Content/Fields/VisibilityField.php index d8af7a26..3796e9ba 100644 --- a/src/flextype/Content/Fields/VisibilityField.php +++ b/src/flextype/Content/Fields/VisibilityField.php @@ -7,26 +7,40 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.storage.content.fields.visibility.enabled')) { +emitter()->addListener('onContentFetchSingleHasResult', static function (): void { + $visibility = [ 'draft' => 'draft', 'hidden' => 'hidden', 'visible' => 'visible', ]; - emitter()->addListener('onContentFetchSingleHasResult', static function () use ($visibility): void { - if (content()->registry()->get('fetch.data.visibility') !== null && in_array(content()->registry()->get('fetch.data.visibility'), $visibility)) { - content()->registry()->set('fetch.data.visibility', (string) $visibility[content()->registry()->get('fetch.data.visibility')]); - } else { - content()->registry()->set('fetch.data.visibility', (string) $visibility['visible']); - } - }); + if (registry()->get('flextype.settings.entries.content.fields.visibility.enabled')) { + return; + } - emitter()->addListener('onContentCreate', static function () use ($visibility): void { - if (content()->registry()->get('create.data.visibility') !== null && in_array(content()->registry()->get('create.data.visibility'), $visibility)) { - content()->registry()->set('create.data.visibility', (string) $visibility[content()->registry()->get('create.data.visibility')]); - } else { - content()->registry()->set('create.data.visibility', (string) $visibility['visible']); - } - }); -} + if (content()->registry()->get('fetch.data.visibility') !== null && in_array(content()->registry()->get('fetch.data.visibility'), $visibility)) { + content()->registry()->set('fetch.data.visibility', (string) $visibility[content()->registry()->get('fetch.data.visibility')]); + } else { + content()->registry()->set('fetch.data.visibility', (string) $visibility['visible']); + } +}); + +emitter()->addListener('onContentCreate', static function (): void { + + $visibility = [ + 'draft' => 'draft', + 'hidden' => 'hidden', + 'visible' => 'visible', + ]; + + if (registry()->get('flextype.settings.entries.content.fields.visibility.enabled')) { + return; + } + + if (content()->registry()->get('create.data.visibility') !== null && in_array(content()->registry()->get('create.data.visibility'), $visibility)) { + content()->registry()->set('create.data.visibility', (string) $visibility[content()->registry()->get('create.data.visibility')]); + } else { + content()->registry()->set('create.data.visibility', (string) $visibility['visible']); + } +}); \ No newline at end of file diff --git a/src/flextype/Media/Fields/CreatedAtField.php b/src/flextype/Media/Fields/CreatedAtField.php index 648fabf5..69b5d45a 100644 --- a/src/flextype/Media/Fields/CreatedAtField.php +++ b/src/flextype/Media/Fields/CreatedAtField.php @@ -7,23 +7,28 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ +emitter()->addListener('onMediaFetchSingleHasResult', static function (): void { -if (registry()->get('flextype.settings.entries.media.fields.created_at.enabled')) { - emitter()->addListener('onMediaFetchSingleHasResult', static function (): void { - if (media()->registry()->get('fetch.data.created_at') === null) { - media()->registry()->set('fetch.data.created_at', (int) filesystem()->file(media()->getFileLocation(media()->registry()->get('fetch.id')))->lastModified()); - } else { - media()->registry()->set('fetch.data.created_at', (int) strtotime((string) media()->registry()->get('fetch.data.created_at'))); - } - }); + if (registry()->get('flextype.settings.entries.media.fields.created_at.enabled')) { + return; + } - emitter()->addListener('onMediaCreate', static function (): void { - if (media()->registry()->get('create.data.created_at') !== null) { - return; - } + if (media()->registry()->get('fetch.data.created_at') === null) { + media()->registry()->set('fetch.data.created_at', (int) filesystem()->file(media()->getFileLocation(media()->registry()->get('fetch.id')))->lastModified()); + } else { + media()->registry()->set('fetch.data.created_at', (int) strtotime((string) media()->registry()->get('fetch.data.created_at'))); + } +}); - media()->registry()->set('create.data.created_at', date(registry()->get('flextype.settings.date_format'), time())); - }); -} +emitter()->addListener('onMediaCreate', static function (): void { + + if (registry()->get('flextype.settings.entries.media.fields.created_at.enabled')) { + return; + } + if (media()->registry()->get('create.data.created_at') !== null) { + return; + } + media()->registry()->set('create.data.created_at', date(registry()->get('flextype.settings.date_format'), time())); +}); diff --git a/src/flextype/Media/Fields/CreatedByField.php b/src/flextype/Media/Fields/CreatedByField.php index bff919cf..27802599 100644 --- a/src/flextype/Media/Fields/CreatedByField.php +++ b/src/flextype/Media/Fields/CreatedByField.php @@ -7,12 +7,15 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.entries.media.fields.created_by.enabled')) { - emitter()->addListener('onMediaCreate', static function (): void { - if (media()->registry()->get('create.data.created_by') !== null) { - return; - } +emitter()->addListener('onMediaCreate', static function (): void { - media()->registry()->set('create.data.created_by', ''); - }); -} + if (registry()->get('flextype.settings.entries.media.fields.created_by.enabled')) { + return; + } + + if (media()->registry()->get('create.data.created_by') !== null) { + return; + } + + media()->registry()->set('create.data.created_by', ''); +}); diff --git a/src/flextype/Media/Fields/IdField.php b/src/flextype/Media/Fields/IdField.php index 418dab97..b3eb5e6b 100644 --- a/src/flextype/Media/Fields/IdField.php +++ b/src/flextype/Media/Fields/IdField.php @@ -7,15 +7,15 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ +emitter()->addListener('onMediaFetchSingleHasResult', static function (): void { -if (registry()->get('flextype.settings.entries.media.fields.id.enabled')) { - - emitter()->addListener('onMediaFetchSingleHasResult', static function (): void { - - if (media()->registry()->get('fetch.data.id') !== null) { - return; - } + if (registry()->get('flextype.settings.entries.media.fields.id.enabled')) { + return; + } - media()->registry()->set('fetch.data.id', (string) strings(media()->registry()->get('fetch.id'))->trimSlashes()); - }); -} + if (media()->registry()->get('fetch.data.id') !== null) { + return; + } + + media()->registry()->set('fetch.data.id', (string) strings(media()->registry()->get('fetch.id'))->trimSlashes()); +}); \ No newline at end of file diff --git a/src/flextype/Media/Fields/ModifiedAtField.php b/src/flextype/Media/Fields/ModifiedAtField.php index c33c6580..558e113e 100644 --- a/src/flextype/Media/Fields/ModifiedAtField.php +++ b/src/flextype/Media/Fields/ModifiedAtField.php @@ -7,12 +7,15 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -if (registry()->get('flextype.settings.entries.media.fields.modified_at.enabled')) { - emitter()->addListener('onMediaFetchSingleHasResult', static function (): void { - if (content()->registry()->get('fetch.data.modified_at') !== null) { - return; - } +emitter()->addListener('onMediaFetchSingleHasResult', static function (): void { - content()->registry()->set('fetch.data.modified_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); - }); -} + if (registry()->get('flextype.settings.entries.media.fields.modified_at.enabled')) { + return; + } + + if (content()->registry()->get('fetch.data.modified_at') !== null) { + return; + } + + content()->registry()->set('fetch.data.modified_at', (int) filesystem()->file(content()->getFileLocation(content()->registry()->get('fetch.id')))->lastModified()); +}); diff --git a/src/flextype/Media/Fields/UuidField.php b/src/flextype/Media/Fields/UuidField.php index 6bbb14ef..58ae21f4 100644 --- a/src/flextype/Media/Fields/UuidField.php +++ b/src/flextype/Media/Fields/UuidField.php @@ -9,12 +9,15 @@ declare(strict_types=1); use Ramsey\Uuid\Uuid; -if (registry()->get('flextype.settings.entries.media.fields.uuid.enabled')) { - emitter()->addListener('onMediaCreate', static function (): void { - if (media()->registry()->get('create.data.uuid') !== null) { - return; - } +emitter()->addListener('onMediaCreate', static function (): void { - media()->registry()->set('create.data.uuid', Uuid::uuid4()->toString()); - }); -} + if (registry()->get('flextype.settings.entries.media.fields.uuid.enabled')) { + return; + } + + if (media()->registry()->get('create.data.uuid') !== null) { + return; + } + + media()->registry()->set('create.data.uuid', Uuid::uuid4()->toString()); +}); diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 0864f5fa..cf593f65 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -62,20 +62,20 @@ entries: serializer: yaml fields: modified_at: + enabled: true path: "/src/flextype/Media/Fields/ModifiedAtField.php" - enabled: true created_at: + enabled: true path: "/src/flextype/Media/Fields/CreatedAtField.php" - enabled: true created_by: + enabled: true path: "/src/flextype/Media/Fields/CreatedByField.php" - enabled: true uuid: + enabled: true path: "/src/flextype/Media/Fields/UuidField.php" - enabled: true id: - path: "/src/flextype/Media/Fields/IdField.php" enabled: true + path: "/src/flextype/Media/Fields/IdField.php" content: directory: content filename: content @@ -83,56 +83,51 @@ entries: serializer: yaml fields: media: - files: - fetch: - enabled: true - result: toObject - folders: - fetch: - enabled: true - result: toObject + enabled: true + path: "/src/flextype/Content/Fields/MediaField.php" + fetch: + result: toObject registry: + enabled: true path: "/src/flextype/Content/Fields/RegistryField.php" - get: - enabled: true content: + enabled: true path: "/src/flextype/Content/Fields/ContentField.php" fetch: - enabled: true result: toObject slug: + enabled: true path: "/src/flextype/Content/Fields/SlugField.php" - enabled: true published_at: + enabled: true path: "/src/flextype/Content/Fields/PublishedAtField.php" - enabled: true published_by: + enabled: true path: "/src/flextype/Content/Fields/PublishedByField.php" - enabled: true modified_at: + enabled: true path: "/src/flextype/Content/Fields/ModifiedAtField.php" - enabled: true created_at: + enabled: true path: "/src/flextype/Content/Fields/CreatedAtField.php" - enabled: true created_by: + enabled: true path: "/src/flextype/Content/Fields/CreatedByField.php" - enabled: true routable: + enabled: true path: "/src/flextype/Content/Fields/RoutableField.php" - enabled: true parsers: + enabled: true path: "/src/flextype/Content/Fields/ParsersField.php" - enabled: true visibility: + enabled: true path: "/src/flextype/Content/Fields/VisibilityField.php" - enabled: true uuid: + enabled: true path: "/src/flextype/Content/Fields/UuidField.php" - enabled: true id: - path: "/src/flextype/Content/Fields/IdField.php" enabled: true + path: "/src/flextype/Content/Fields/IdField.php" # Cache # @@ -177,7 +172,7 @@ entries: # - drivers.files.cache_slams_timeout: This option defines the cache slams timeout in seconds. cache: - enabled: true + enabled: false router: routes auto_reload: storage: false @@ -475,20 +470,20 @@ parsers: cache: true shortcodes: media: + enabled: true path: "/src/flextype/Parsers/Shortcodes/MediaShortcode.php" - enabled: true content: + enabled: true path: "/src/flextype/Parsers/Shortcodes/ContentShortcode.php" - enabled: true raw: + enabled: true path: "/src/flextype/Parsers/Shortcodes/RawShortcode.php" - enabled: true registry: + enabled: true path: "/src/flextype/Parsers/Shortcodes/RegistryShortcode.php" - enabled: true url: - path: "/src/flextype/Parsers/Shortcodes/UrlShortcode.php" enabled: true + path: "/src/flextype/Parsers/Shortcodes/UrlShortcode.php" # CORS #