diff --git a/src/flextype/core/Entries/Fields/Default/CreatedAtField.php b/src/flextype/core/Entries/Fields/Default/CreatedAtField.php index edf88346..024ad20c 100644 --- a/src/flextype/core/Entries/Fields/Default/CreatedAtField.php +++ b/src/flextype/core/Entries/Fields/Default/CreatedAtField.php @@ -16,10 +16,16 @@ declare(strict_types=1); emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.fetch.collection.fields.created_at.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.created_at.path'))) { + return; + } + if (entries()->registry()->get('methods.fetch.result.created_at') === null) { entries()->registry()->set('methods.fetch.result.created_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('methods.fetch.params.id')))->lastModified()); } else { @@ -29,10 +35,17 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! registry()->get('methods.fetch.collection.fields.created_at.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.create.collection.fields.created_at.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.created_at') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Default/CreatedByField.php b/src/flextype/core/Entries/Fields/Default/CreatedByField.php index e6308088..8d64b279 100644 --- a/src/flextype/core/Entries/Fields/Default/CreatedByField.php +++ b/src/flextype/core/Entries/Fields/Default/CreatedByField.php @@ -16,10 +16,17 @@ declare(strict_types=1); emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.created_by.enabled')) { return; } + + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.created_by.path'))) { + return; + } + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.created_by') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Default/IdField.php b/src/flextype/core/Entries/Fields/Default/IdField.php index ba14b804..317b90d9 100644 --- a/src/flextype/core/Entries/Fields/Default/IdField.php +++ b/src/flextype/core/Entries/Fields/Default/IdField.php @@ -16,13 +16,20 @@ declare(strict_types=1); emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.fetch.collection.fields.id.enabled')) { return; } - - if (entries()->registry()->get('methods.fetch.result.id') !== null) { + + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.id.path'))) { return; } + // Determine is the current field is not null. + if (entries()->registry()->get('methods.fetch.result.id') !== null) { + return; + } + entries()->registry()->set('methods.fetch.result.id', strings(entries()->registry()->get('methods.fetch.params.id'))->trimSlashes()->toString()); }); \ No newline at end of file diff --git a/src/flextype/core/Entries/Fields/Default/ModifiedAtField.php b/src/flextype/core/Entries/Fields/Default/ModifiedAtField.php index 555a9aa0..469b499b 100644 --- a/src/flextype/core/Entries/Fields/Default/ModifiedAtField.php +++ b/src/flextype/core/Entries/Fields/Default/ModifiedAtField.php @@ -16,10 +16,17 @@ declare(strict_types=1); emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.fetch.collection.fields.modified_at.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.modified_at.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.fetch.result.modified_at') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Default/PublishedAtField.php b/src/flextype/core/Entries/Fields/Default/PublishedAtField.php index 2701dc10..0d6be195 100644 --- a/src/flextype/core/Entries/Fields/Default/PublishedAtField.php +++ b/src/flextype/core/Entries/Fields/Default/PublishedAtField.php @@ -16,10 +16,16 @@ declare(strict_types=1); emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.fetch.collection.fields.published_at.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.published_at.path'))) { + return; + } + if (entries()->registry()->get('methods.fetch.result.published_at') === null) { entries()->registry()->set('methods.fetch.result.published_at', (int) filesystem()->file(entries()->getFileLocation(entries()->registry()->get('methods.fetch.params.id')))->lastModified()); } else { @@ -29,10 +35,17 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.published_at.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.create.collection.fields.published_at.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.published_at') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Default/PublishedByField.php b/src/flextype/core/Entries/Fields/Default/PublishedByField.php index cdfe6b54..f22c7907 100644 --- a/src/flextype/core/Entries/Fields/Default/PublishedByField.php +++ b/src/flextype/core/Entries/Fields/Default/PublishedByField.php @@ -16,10 +16,17 @@ declare(strict_types=1); emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.published_by.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.published_by.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.published_by') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Default/RoutableField.php b/src/flextype/core/Entries/Fields/Default/RoutableField.php index bdce98e3..36a17498 100644 --- a/src/flextype/core/Entries/Fields/Default/RoutableField.php +++ b/src/flextype/core/Entries/Fields/Default/RoutableField.php @@ -16,10 +16,16 @@ declare(strict_types=1); emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.fetch.collection.fields.routable.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.routable.path'))) { + return; + } + if (entries()->registry()->get('methods.fetch.result.routable') === null) { entries()->registry()->set('methods.fetch.result.routable', true); } else { @@ -30,10 +36,16 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.routable.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.create.collection.fields.routable.path'))) { + return; + } + if (entries()->registry()->get('methods.create.params.data.routable') === null) { entries()->registry()->set('methods.create.params.data.routable', true); } else { diff --git a/src/flextype/core/Entries/Fields/Default/SlugField.php b/src/flextype/core/Entries/Fields/Default/SlugField.php index 870abd28..cbb7bb39 100644 --- a/src/flextype/core/Entries/Fields/Default/SlugField.php +++ b/src/flextype/core/Entries/Fields/Default/SlugField.php @@ -16,10 +16,17 @@ declare(strict_types=1); emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.fetch.collection.fields.slug.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.slug.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.fetch.result.slug') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Default/UuidField.php b/src/flextype/core/Entries/Fields/Default/UuidField.php index 172411da..06fa3730 100644 --- a/src/flextype/core/Entries/Fields/Default/UuidField.php +++ b/src/flextype/core/Entries/Fields/Default/UuidField.php @@ -18,10 +18,17 @@ use Ramsey\Uuid\Uuid; emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.uuid.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.uuid.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.uuid') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Default/VisibilityField.php b/src/flextype/core/Entries/Fields/Default/VisibilityField.php index 9c5e3c14..6fe951ae 100644 --- a/src/flextype/core/Entries/Fields/Default/VisibilityField.php +++ b/src/flextype/core/Entries/Fields/Default/VisibilityField.php @@ -16,16 +16,22 @@ declare(strict_types=1); emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void { + // Determine is the current field is set and enabled. + if (! entries()->registry()->get('methods.fetch.collection.fields.visibility.enabled')) { + return; + } + + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.visibility.path'))) { + return; + } + $visibility = [ 'draft' => 'draft', 'hidden' => 'hidden', 'visible' => 'visible', ]; - if (! entries()->registry()->get('methods.fetch.collection.fields.visibility.enabled')) { - return; - } - if (entries()->registry()->get('methods.fetch.result.visibility') !== null && in_array(entries()->registry()->get('methods.fetch.result.visibility'), $visibility)) { entries()->registry()->set('methods.fetch.result.visibility', (string) $visibility[entries()->registry()->get('methods.fetch.result.visibility')]); } else { @@ -35,15 +41,21 @@ emitter()->addListener('onEntriesFetchSingleHasResult', static function (): void emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. + if (! entries()->registry()->get('methods.create.collection.fields.visibility.enabled')) { + return; + } + + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.create.collection.fields.visibility.path'))) { + return; + } + $visibility = [ 'draft' => 'draft', 'hidden' => 'hidden', 'visible' => 'visible', ]; - - if (! entries()->registry()->get('methods.create.collection.fields.visibility.enabled')) { - return; - } if (entries()->registry()->get('methods.create.params.data.visibility') !== null && in_array(entries()->registry()->get('methods.create.params.data.visibility'), $visibility)) { entries()->registry()->set('methods.create.params.data.visibility', (string) $visibility[entries()->registry()->get('methods.create.params.data.visibility')]); diff --git a/src/flextype/core/Entries/Fields/Tokens/Items/CallsField.php b/src/flextype/core/Entries/Fields/Tokens/Items/CallsField.php index 1220de0e..e8487598 100644 --- a/src/flextype/core/Entries/Fields/Tokens/Items/CallsField.php +++ b/src/flextype/core/Entries/Fields/Tokens/Items/CallsField.php @@ -16,10 +16,17 @@ declare(strict_types=1); emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.calls.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.calls.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.calls') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Tokens/Items/IdField.php b/src/flextype/core/Entries/Fields/Tokens/Items/IdField.php new file mode 100644 index 00000000..ef8722ec --- /dev/null +++ b/src/flextype/core/Entries/Fields/Tokens/Items/IdField.php @@ -0,0 +1,35 @@ +addListener('onEntriesFetchSingleHasResult', static function (): void { + + // Determine is the current field is set and enabled. + if (! entries()->registry()->get('methods.fetch.collection.fields.id.enabled')) { + return; + } + + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.id.path'))) { + return; + } + + // Determine is the current field is not null. + if (entries()->registry()->get('methods.fetch.result.id') !== null) { + return; + } + + entries()->registry()->set('methods.fetch.result.id', strings(entries()->registry()->get('methods.fetch.params.id'))->replace('tokens', '')->trimSlashes()->toString()); +}); \ No newline at end of file diff --git a/src/flextype/core/Entries/Fields/Tokens/Items/LimitCallsField.php b/src/flextype/core/Entries/Fields/Tokens/Items/LimitCallsField.php index ca8aed9a..23c48c9e 100644 --- a/src/flextype/core/Entries/Fields/Tokens/Items/LimitCallsField.php +++ b/src/flextype/core/Entries/Fields/Tokens/Items/LimitCallsField.php @@ -16,10 +16,17 @@ declare(strict_types=1); emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.limit_calls.enabled')) { return; } + + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.limit_calls.path'))) { + return; + } + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.limit_calls') !== null) { return; } diff --git a/src/flextype/core/Entries/Fields/Tokens/Items/StateField.php b/src/flextype/core/Entries/Fields/Tokens/Items/StateField.php index a4ec4cb8..ea8a9233 100644 --- a/src/flextype/core/Entries/Fields/Tokens/Items/StateField.php +++ b/src/flextype/core/Entries/Fields/Tokens/Items/StateField.php @@ -16,10 +16,17 @@ declare(strict_types=1); emitter()->addListener('onEntriesCreate', static function (): void { + // Determine is the current field is set and enabled. if (! entries()->registry()->get('methods.create.collection.fields.state.enabled')) { return; } + // Determine is the current field file path is the same. + if (! strings(__FILE__)->replace(ROOT_DIR, '')->isEqual(entries()->registry()->get('methods.fetch.collection.fields.state.path'))) { + return; + } + + // Determine is the current field is not null. if (entries()->registry()->get('methods.create.params.data.state') !== null) { return; }