mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(entries): remove content instance with fields #563
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype\Content;
|
||||
|
||||
use Atomastic\Macroable\Macroable;
|
||||
use Flextype\Entries;
|
||||
|
||||
class Content extends Entries
|
||||
{
|
||||
use Macroable;
|
||||
}
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
emitter()->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()));
|
||||
});
|
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
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', '');
|
||||
});
|
||||
|
@@ -1,61 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
use Atomastic\Arrays\Arrays;
|
||||
|
||||
emitter()->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());
|
||||
}
|
||||
});
|
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
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());
|
||||
});
|
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
emitter()->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()));
|
||||
});
|
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
emitter()->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', '');
|
||||
});
|
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* 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 (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'));
|
||||
}
|
||||
});
|
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
emitter()->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));
|
||||
});
|
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
emitter()->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());
|
||||
});
|
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
emitter()->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']);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user