From f63ce6efcd7edb3077585dcfa40abc9f91b69517 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 17 Aug 2021 16:29:50 +0300 Subject: [PATCH] feat(entries): remove content instance with fields #563 --- src/flextype/core/Content/Content.php | 18 ------ .../core/Content/Fields/CreatedAtField.php | 34 ----------- .../core/Content/Fields/CreatedByField.php | 22 ------- .../core/Content/Fields/MediaField.php | 61 ------------------- .../core/Content/Fields/ModifiedAtField.php | 21 ------- .../core/Content/Fields/PublishedAtField.php | 34 ----------- .../core/Content/Fields/PublishedByField.php | 21 ------- .../core/Content/Fields/RoutableField.php | 35 ----------- .../core/Content/Fields/SlugField.php | 22 ------- .../core/Content/Fields/UuidField.php | 23 ------- .../core/Content/Fields/VisibilityField.php | 46 -------------- 11 files changed, 337 deletions(-) delete mode 100644 src/flextype/core/Content/Content.php delete mode 100644 src/flextype/core/Content/Fields/CreatedAtField.php delete mode 100644 src/flextype/core/Content/Fields/CreatedByField.php delete mode 100644 src/flextype/core/Content/Fields/MediaField.php delete mode 100644 src/flextype/core/Content/Fields/ModifiedAtField.php delete mode 100644 src/flextype/core/Content/Fields/PublishedAtField.php delete mode 100644 src/flextype/core/Content/Fields/PublishedByField.php delete mode 100644 src/flextype/core/Content/Fields/RoutableField.php delete mode 100644 src/flextype/core/Content/Fields/SlugField.php delete mode 100644 src/flextype/core/Content/Fields/UuidField.php delete mode 100644 src/flextype/core/Content/Fields/VisibilityField.php diff --git a/src/flextype/core/Content/Content.php b/src/flextype/core/Content/Content.php deleted file mode 100644 index 30fdd904..00000000 --- a/src/flextype/core/Content/Content.php +++ /dev/null @@ -1,18 +0,0 @@ -addListener('onContentFetchSingleHasResult', static function (): void { - - if (! registry()->get('flextype.settings.entries.content.fields.created_at.enabled')) { - 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'))); - } -}); - -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/core/Content/Fields/CreatedByField.php b/src/flextype/core/Content/Fields/CreatedByField.php deleted file mode 100644 index df760c6b..00000000 --- a/src/flextype/core/Content/Fields/CreatedByField.php +++ /dev/null @@ -1,22 +0,0 @@ -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', ''); -}); - diff --git a/src/flextype/core/Content/Fields/MediaField.php b/src/flextype/core/Content/Fields/MediaField.php deleted file mode 100644 index dc505749..00000000 --- a/src/flextype/core/Content/Fields/MediaField.php +++ /dev/null @@ -1,61 +0,0 @@ -addListener('onContentFetchSingleHasResult', static function (): void { - - if (! registry()->get('flextype.settings.entries.content.fields.media.enabled')) { - return; - } - - if (content()->registry()->has('fetch.data.media.fetch')) { - // Get fetch. - $original = content()->registry()->get('fetch'); - $data = []; - - switch (registry()->get('flextype.settings.entries.content.fields.media.files.fetch.result')) { - case 'toArray': - $resultTo = 'toArray'; - break; - - case 'toObject': - default: - $resultTo = 'copy'; - break; - } - - // 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; - - $data[$field] = flextype('media')->files()->{$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/core/Content/Fields/ModifiedAtField.php b/src/flextype/core/Content/Fields/ModifiedAtField.php deleted file mode 100644 index c9682d15..00000000 --- a/src/flextype/core/Content/Fields/ModifiedAtField.php +++ /dev/null @@ -1,21 +0,0 @@ -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()); -}); diff --git a/src/flextype/core/Content/Fields/PublishedAtField.php b/src/flextype/core/Content/Fields/PublishedAtField.php deleted file mode 100644 index 4b612d72..00000000 --- a/src/flextype/core/Content/Fields/PublishedAtField.php +++ /dev/null @@ -1,34 +0,0 @@ -addListener('onContentFetchSingleHasResult', static function (): void { - - if (! registry()->get('flextype.settings.entries.content.fields.published_at.enabled')) { - return; - } - - 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/core/Content/Fields/PublishedByField.php b/src/flextype/core/Content/Fields/PublishedByField.php deleted file mode 100644 index 621b685e..00000000 --- a/src/flextype/core/Content/Fields/PublishedByField.php +++ /dev/null @@ -1,21 +0,0 @@ -addListener('onContentCreate', static function (): void { - - if (! registry()->get('flextype.settings.entries.content.fields.published_by.enabled')) { - return; - } - - 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/core/Content/Fields/RoutableField.php b/src/flextype/core/Content/Fields/RoutableField.php deleted file mode 100644 index a14d9910..00000000 --- a/src/flextype/core/Content/Fields/RoutableField.php +++ /dev/null @@ -1,35 +0,0 @@ -addListener('onContentFetchSingleHasResult', static function (): void { - - if (registry()->get('flextype.settings.entries.content.fields.routable.enabled')) { - return; - } - - 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 (! 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/core/Content/Fields/SlugField.php b/src/flextype/core/Content/Fields/SlugField.php deleted file mode 100644 index 036219bd..00000000 --- a/src/flextype/core/Content/Fields/SlugField.php +++ /dev/null @@ -1,22 +0,0 @@ -addListener('onContentFetchSingleHasResult', static function (): void { - - if (! registry()->get('flextype.settings.entries.content.fields.slug.enabled')) { - return; - } - - 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/core/Content/Fields/UuidField.php b/src/flextype/core/Content/Fields/UuidField.php deleted file mode 100644 index 373a0204..00000000 --- a/src/flextype/core/Content/Fields/UuidField.php +++ /dev/null @@ -1,23 +0,0 @@ -addListener('onContentCreate', static function (): void { - - 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/core/Content/Fields/VisibilityField.php b/src/flextype/core/Content/Fields/VisibilityField.php deleted file mode 100644 index 0f7f7def..00000000 --- a/src/flextype/core/Content/Fields/VisibilityField.php +++ /dev/null @@ -1,46 +0,0 @@ -addListener('onContentFetchSingleHasResult', 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('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