mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(fields): add ability to override fields
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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());
|
||||
});
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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 {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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')]);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
35
src/flextype/core/Entries/Fields/Tokens/Items/IdField.php
Normal file
35
src/flextype/core/Entries/Fields/Tokens/Items/IdField.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
|
||||
* and with the full functionality of a traditional CMS!
|
||||
*
|
||||
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
|
||||
*
|
||||
* Licensed under The MIT License.
|
||||
*
|
||||
* For full copyright and license information, please see the LICENSE
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// 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());
|
||||
});
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user