1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-10 15:14:20 +02:00

feat(fields): update logic for setting enabled, affected all fields #564

This commit is contained in:
Awilum
2021-08-07 10:40:01 +03:00
parent 8104775dfd
commit d5ffed216f
20 changed files with 390 additions and 369 deletions

View File

@@ -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());
}
});

View File

@@ -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()));
});

View File

@@ -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', '');
});
}

View File

@@ -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());
});

View File

@@ -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());
}
});

View File

@@ -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());
});

View File

@@ -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'))
}
}
}
});
}
}
});

View File

@@ -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()));
});
}
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()));
});

View File

@@ -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', '');
});

View File

@@ -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());
}
});

View File

@@ -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'));
}
});

View File

@@ -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));
});

View File

@@ -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());
});

View File

@@ -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']);
}
});

View File

@@ -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()));
});

View File

@@ -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', '');
});

View File

@@ -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());
});

View File

@@ -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());
});

View File

@@ -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());
});

View File

@@ -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
#