Skip to content

Commit

Permalink
[FEATURE] Implement enum-precursor option name constants
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Aug 13, 2023
1 parent c068901 commit 6539943
Show file tree
Hide file tree
Showing 52 changed files with 256 additions and 203 deletions.
3 changes: 2 additions & 1 deletion Classes/Backend/PageLayoutDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Service\PageService;
use FluidTYPO3\Flux\Utility\ExtensionNamingUtility;
Expand Down Expand Up @@ -122,7 +123,7 @@ protected function renderOption(Form $form, array $parameters): array
$thumbnail = $thumbnail ? MiscellaneousUtility::createIcon($thumbnail) : null;
}
/** @var string|null $template */
$template = $form->getOption(Form::OPTION_TEMPLATEFILE_RELATIVE);
$template = $form->getOption(FormOption::TEMPLATE_FILE_RELATIVE);
if ($template === null) {
return [];
}
Expand Down
3 changes: 2 additions & 1 deletion Classes/Builder/ContentTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

use FluidTYPO3\Flux\Controller\AbstractFluxController;
use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Hooks\HookHandler;
use FluidTYPO3\Flux\Provider\Interfaces\BasicProviderInterface;
Expand Down Expand Up @@ -271,7 +272,7 @@ protected function addPageTsConfig(Form $form, string $contentType, string $icon
// Icons required solely for use in the "new content element" wizard
$formId = $form->getId() ?: $contentType;
/** @var string|null $group */
$group = $form->getOption(Form::OPTION_GROUP);
$group = $form->getOption(FormOption::GROUP);
$groupName = $this->sanitizeString($group ?? 'fluxContent');
$extensionName = $form->getExtensionName() ?? 'FluidTYPO3.Flux';
$extensionKey = ExtensionNamingUtility::getExtensionKey($extensionName);
Expand Down
4 changes: 2 additions & 2 deletions Classes/Builder/FlexFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Provider\Interfaces\DataStructureProviderInterface;
use FluidTYPO3\Flux\Provider\Interfaces\FormProviderInterface;
use FluidTYPO3\Flux\Provider\ProviderResolver;
Expand Down Expand Up @@ -126,7 +126,7 @@ public function parseDataStructureByIdentifier(array $identifier): array
$dataStructArray = $this->patchTceformsWrapper($dataStructArray);
}

if ($form && $form->getOption(Form::OPTION_STATIC)) {
if ($form && $form->getOption(FormOption::STATIC)) {
// This provider has requested static DS caching; stop attempting
// to process any other DS, cache and return this DS as final result:
$this->cacheService->setInCaches($dataStructArray, true, $cacheKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Enum\ExtensionOption;
use FluidTYPO3\Flux\Provider\Provider;
use FluidTYPO3\Flux\Utility\ExtensionConfigurationUtility;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
Expand Down Expand Up @@ -68,7 +69,7 @@ public function __construct(
*/
public static function fetchContentTypes(): iterable
{
if (!ExtensionConfigurationUtility::getOption(ExtensionConfigurationUtility::OPTION_PLUG_AND_PLAY)) {
if (!ExtensionConfigurationUtility::getOption(ExtensionOption::OPTION_PLUG_AND_PLAY)) {
// Do not return or auto-create any plug and play templates if the extension config option is disabled.
// Option default value is ENABLED (hence null coalesce to TRUE if not defined)
return [];
Expand All @@ -77,7 +78,7 @@ public static function fetchContentTypes(): iterable
// 1) auto-create if missing, the required file structure and dummy files
// 2) iterate all content types found in the file structure
$plugAndPlayDirectory = ExtensionConfigurationUtility::getOption(
ExtensionConfigurationUtility::OPTION_PLUG_AND_PLAY_DIRECTORY
ExtensionOption::OPTION_PLUG_AND_PLAY_DIRECTORY
);
if (!is_scalar($plugAndPlayDirectory)) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use FluidTYPO3\Flux\Content\TypeDefinition\FluidRenderingContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Content\TypeDefinition\SerializeSafeInterface;
use FluidTYPO3\Flux\Content\TypeDefinition\SerializeSafeTrait;
use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\Container\Column;
use FluidTYPO3\Flux\Form\Container\Grid;
Expand Down Expand Up @@ -103,9 +104,9 @@ public function getForm(array $record = []): Form
{
$instance = Form::create();
$instance->remove('options');
$instance->setOption(Form::OPTION_ICON, $this->getIconReference());
$instance->setOption(Form::OPTION_GROUP, 'fluxContent');
$instance->setOption(Form::OPTION_SORTING, $this->record['sorting']);
$instance->setOption(FormOption::ICON, $this->getIconReference());
$instance->setOption(FormOption::GROUP, 'fluxContent');
$instance->setOption(FormOption::SORTING, $this->record['sorting']);
$instance->setLabel($this->record['title']);
$instance->setDescription($this->record['description']);
foreach ($this->getContentConfiguration() as $item) {
Expand Down
15 changes: 15 additions & 0 deletions Classes/Enum/ExtensionOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Enum;

class ExtensionOption
{
public const OPTION_DEBUG_MODE = 'debugMode';
public const OPTION_DOKTYPES = 'doktypes';
public const OPTION_HANDLE_ERRORS = 'handleErrors';
public const OPTION_AUTOLOAD = 'autoload';
public const OPTION_PLUG_AND_PLAY = 'plugAndPlay';
public const OPTION_PLUG_AND_PLAY_DIRECTORY = 'plugAndPlayDirectory';
public const OPTION_PAGE_INTEGRATION = 'pageIntegration';
public const OPTION_FLEXFORM_TO_IRRE = 'flexFormToIrre';
}
18 changes: 18 additions & 0 deletions Classes/Enum/FormOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Enum;

class FormOption
{
public const STATIC = 'static';
public const SORTING = 'sorting';
public const GROUP = 'group';
public const ICON = 'icon';
public const TEMPLATE_FILE = 'templateFile';
public const TEMPLATE_FILE_RELATIVE = 'templateFileRelative';
public const RECORD = 'record';
public const RECORD_FIELD = 'recordField';
public const RECORD_TABLE = 'recordTable';
public const TRANSFORM = 'transform';
public const HIDE_NATIVE_FIELDS = 'hideNativeFields';
}
14 changes: 14 additions & 0 deletions Classes/Enum/InlineFieldControls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Enum;

class InlineFieldControls
{
public const INFO = 'info';
public const NEW = 'new';
public const DRAGDROP = 'dragdrop';
public const SORT = 'sort';
public const HIDE = 'hide';
public const DELETE = 'delete';
public const LOCALIZE = 'localize';
}
11 changes: 11 additions & 0 deletions Classes/Enum/InlineFieldNewRecordButtonPosition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Enum;

class InlineFieldNewRecordButtonPosition
{
public const TOP = 'top';
public const BOTTOM = 'bottom';
public const BOTH = 'both';
public const NONE = 'none';
}
13 changes: 13 additions & 0 deletions Classes/Enum/PreviewOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace FluidTYPO3\Flux\Enum;

class PreviewOption
{
const PREVIEW = 'preview';
const MODE = 'mode';
const MODE_APPEND = 'append';
const MODE_PREPEND = 'prepend';
const MODE_NONE = 'none';
const TOGGLE = 'toggle';
}
29 changes: 0 additions & 29 deletions Classes/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,6 @@

class Form extends Form\AbstractFormContainer implements Form\FieldContainerInterface, Form\OptionCarryingInterface
{
const OPTION_STATIC = 'static';
const OPTION_SORTING = 'sorting';
const OPTION_GROUP = 'group';
const OPTION_ICON = 'icon';
const OPTION_TCA_LABELS = 'labels';
const OPTION_TCA_HIDE = 'hide';
const OPTION_TCA_START = 'start';
const OPTION_TCA_END = 'end';
const OPTION_TCA_DELETE = 'delete';
const OPTION_TCA_FEGROUP = 'frontendUserGroup';
const OPTION_TEMPLATEFILE = 'templateFile';
const OPTION_TEMPLATEFILE_RELATIVE = 'templateFileRelative';
const OPTION_RECORD = 'record';
const OPTION_RECORD_FIELD = 'recordField';
const OPTION_RECORD_TABLE = 'recordTable';
const OPTION_DEFAULT_VALUES = 'defaultValues';
const OPTION_TRANSFORM = 'transform';
const OPTION_HIDE_NATIVE_FIELDS = 'hideNativeFields';
const POSITION_TOP = 'top';
const POSITION_BOTTOM = 'bottom';
const POSITION_BOTH = 'both';
const POSITION_NONE = 'none';
const CONTROL_INFO = 'info';
const CONTROL_NEW = 'new';
const CONTROL_DRAGDROP = 'dragdrop';
const CONTROL_SORT = 'sort';
const CONTROL_HIDE = 'hide';
const CONTROL_DELETE = 'delete';
const CONTROL_LOCALISE = 'localize';
const DEFAULT_LANGUAGEFILE = '/Resources/Private/Language/locallang.xlf';

/**
Expand Down
3 changes: 2 additions & 1 deletion Classes/Form/AbstractFormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\Container\Column;
use FluidTYPO3\Flux\Form\Container\Container;
Expand Down Expand Up @@ -120,7 +121,7 @@ public function setTransform(?string $transform): self
if ($transform) {
$root = $this->getRoot();
if ($root instanceof Form) {
$root->setOption(Form::OPTION_TRANSFORM, true);
$root->setOption(FormOption::TRANSFORM, true);
}
}
return $this;
Expand Down
3 changes: 2 additions & 1 deletion Classes/Form/AbstractFormContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Hooks\HookHandler;

Expand Down Expand Up @@ -46,7 +47,7 @@ public function add(FormInterface $child): self
if ($child->getTransform()) {
$root = $this->getRoot();
if ($root instanceof Form) {
$root->setOption(Form::OPTION_TRANSFORM, true);
$root->setOption(FormOption::TRANSFORM, true);
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions Classes/Form/AbstractInlineFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Enum\InlineFieldControls;
use FluidTYPO3\Flux\Enum\InlineFieldNewRecordButtonPosition;

/**
* AbstractInlineFormField
Expand Down Expand Up @@ -44,7 +45,7 @@ abstract class AbstractInlineFormField extends AbstractRelationFormField impleme
*
* @var string
*/
protected $newRecordLinkPosition = Form::POSITION_TOP;
protected $newRecordLinkPosition = InlineFieldNewRecordButtonPosition::TOP;

/**
* For use on bidirectional relations using an intermediary table.
Expand Down Expand Up @@ -99,13 +100,13 @@ abstract class AbstractInlineFormField extends AbstractRelationFormField impleme
* @var array
*/
protected $enabledControls = [
Form::CONTROL_INFO => false,
Form::CONTROL_NEW => true,
Form::CONTROL_DRAGDROP => true,
Form::CONTROL_SORT => true,
Form::CONTROL_HIDE => true,
Form::CONTROL_DELETE => false,
Form::CONTROL_LOCALISE => false,
InlineFieldControls::INFO => false,
InlineFieldControls::NEW => true,
InlineFieldControls::DRAGDROP => true,
InlineFieldControls::SORT => true,
InlineFieldControls::HIDE => true,
InlineFieldControls::DELETE => false,
InlineFieldControls::LOCALIZE => false,
];

/**
Expand Down
4 changes: 2 additions & 2 deletions Classes/Form/Container/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form\AbstractFormContainer;
use FluidTYPO3\Flux\Form\ContainerInterface;
use FluidTYPO3\Flux\Integration\FormEngine\SelectOption;
Expand Down Expand Up @@ -66,7 +66,7 @@ public function buildBackendLayoutArray(int $parentRecordUid): array
$key = ($index + 1) . '.';
$columns[$key] = [
'name' => $column->getLabel(),
'icon' => $column->getVariable(Form::OPTION_ICON),
'icon' => $column->getVariable(FormOption::ICON),
'colPos' => ColumnNumberUtility::calculateColumnNumberForParentAndColumn(
$parentRecordUid,
$column->getColumnPosition()
Expand Down
16 changes: 8 additions & 8 deletions Classes/Form/Field/Inline/Fal.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Enum\InlineFieldControls;
use FluidTYPO3\Flux\Form\AbstractInlineFormField;

class Fal extends AbstractInlineFormField
Expand Down Expand Up @@ -92,13 +92,13 @@ class Fal extends AbstractInlineFormField
* @var array
*/
protected $enabledControls = [
Form::CONTROL_INFO => false,
Form::CONTROL_NEW => false,
Form::CONTROL_DRAGDROP => true,
Form::CONTROL_SORT => true,
Form::CONTROL_HIDE => true,
Form::CONTROL_DELETE => true,
Form::CONTROL_LOCALISE => true,
InlineFieldControls::INFO => false,
InlineFieldControls::NEW => false,
InlineFieldControls::DRAGDROP => true,
InlineFieldControls::SORT => true,
InlineFieldControls::HIDE => true,
InlineFieldControls::DELETE => true,
InlineFieldControls::LOCALIZE => true,
];

/**
Expand Down
7 changes: 4 additions & 3 deletions Classes/Form/Transformation/FormDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\ContainerInterface;
use FluidTYPO3\Flux\Form\FieldInterface;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function convertFlexFormContentToArray(
$languagePointer,
$valuePointer
);
if (null !== $form && $form->getOption(Form::OPTION_TRANSFORM)) {
if (null !== $form && $form->getOption(FormOption::TRANSFORM)) {
$settings = $this->transformAccordingToConfiguration($settings, $form);
}
return $settings;
Expand Down Expand Up @@ -148,9 +149,9 @@ protected function transformValueToType(string $value, string $dataType, string
{
if (in_array($dataType, ['file', 'files', 'filereference', 'filereferences'], true)) {
/** @var string $table */
$table = $form->getOption(Form::OPTION_RECORD_TABLE);
$table = $form->getOption(FormOption::RECORD_TABLE);
/** @var array $record */
$record = $form->getOption(Form::OPTION_RECORD);
$record = $form->getOption(FormOption::RECORD);
$references = $this->fileRepository->findByRelation($table, $fieldName, $record['uid']);
switch ($dataType) {
case 'file':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use FluidTYPO3\Flux\Content\ContentTypeManager;
use FluidTYPO3\Flux\Content\TypeDefinition\FluidRenderingContentTypeDefinitionInterface;
use FluidTYPO3\Flux\Core;
use FluidTYPO3\Flux\Enum\FormOption;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Provider\Provider;
use FluidTYPO3\Flux\Provider\ProviderInterface;
Expand Down Expand Up @@ -220,11 +221,11 @@ private function resolveSortingValue(?Form $form): string
{
$sortingOptionValue = 0;
if ($form instanceof Form\FormInterface) {
if ($form->hasOption(Form::OPTION_SORTING)) {
$sortingOptionValue = $form->getOption(Form::OPTION_SORTING);
} elseif ($form->hasOption(Form::OPTION_TEMPLATEFILE)) {
if ($form->hasOption(FormOption::SORTING)) {
$sortingOptionValue = $form->getOption(FormOption::SORTING);
} elseif ($form->hasOption(FormOption::TEMPLATE_FILE)) {
/** @var string $templateFilename */
$templateFilename = $form->getOption(Form::OPTION_TEMPLATEFILE);
$templateFilename = $form->getOption(FormOption::TEMPLATE_FILE);
$sortingOptionValue = basename($templateFilename);
} else {
$sortingOptionValue = $form->getId();
Expand Down
Loading

0 comments on commit 6539943

Please sign in to comment.