@@ -18,24 +18,24 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class TitleViewHelper extends AbstractViewHelper |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @return void |
|
| 23 | - */ |
|
| 24 | - public function initializeArguments() |
|
| 25 | - { |
|
| 26 | - $this->registerArgument('content', Content::class, '', true); |
|
| 27 | - } |
|
| 21 | + /** |
|
| 22 | + * @return void |
|
| 23 | + */ |
|
| 24 | + public function initializeArguments() |
|
| 25 | + { |
|
| 26 | + $this->registerArgument('content', Content::class, '', true); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns the title of a content object. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function render() |
|
| 35 | - { |
|
| 36 | - /** @var Content $content */ |
|
| 37 | - $content = $this->arguments['content']; |
|
| 38 | - $table = Tca::table($content->getDataType()); |
|
| 39 | - return $content[$table->getLabelField()]; |
|
| 40 | - } |
|
| 29 | + /** |
|
| 30 | + * Returns the title of a content object. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function render() |
|
| 35 | + { |
|
| 36 | + /** @var Content $content */ |
|
| 37 | + $content = $this->arguments['content']; |
|
| 38 | + $table = Tca::table($content->getDataType()); |
|
| 39 | + return $content[$table->getLabelField()]; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class LanguageFileGenerator implements SingletonInterface |
| 21 | 21 | { |
| 22 | - protected $template = '<?xml version="1.0" encoding="UTF-8"?> |
|
| 22 | + protected $template = '<?xml version="1.0" encoding="UTF-8"?> |
|
| 23 | 23 | <xliff version="1.0"> |
| 24 | 24 | <file source-language="en" datatype="plaintext" original="messages" date="" product-name="local lang module"> |
| 25 | 25 | <header/> |
@@ -37,57 +37,57 @@ discard block |
||
| 37 | 37 | </file> |
| 38 | 38 | </xliff>'; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param string $dataType |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function generate($dataType) |
|
| 45 | - { |
|
| 46 | - $label = $dataType; |
|
| 47 | - if (!empty($GLOBALS['TCA'][$dataType]['ctrl']['title'])) { |
|
| 48 | - $label = $this->getLanguageService()->sL($GLOBALS['TCA'][$dataType]['ctrl']['title']); |
|
| 49 | - } |
|
| 40 | + /** |
|
| 41 | + * @param string $dataType |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function generate($dataType) |
|
| 45 | + { |
|
| 46 | + $label = $dataType; |
|
| 47 | + if (!empty($GLOBALS['TCA'][$dataType]['ctrl']['title'])) { |
|
| 48 | + $label = $this->getLanguageService()->sL($GLOBALS['TCA'][$dataType]['ctrl']['title']); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - // Generate language file. |
|
| 52 | - $languageFile = $this->getLanguageFile($dataType); |
|
| 53 | - $content = str_replace('{module_name}', $label, $this->template); |
|
| 54 | - GeneralUtility::writeFileToTypo3tempDir($languageFile, $content); |
|
| 51 | + // Generate language file. |
|
| 52 | + $languageFile = $this->getLanguageFile($dataType); |
|
| 53 | + $content = str_replace('{module_name}', $label, $this->template); |
|
| 54 | + GeneralUtility::writeFileToTypo3tempDir($languageFile, $content); |
|
| 55 | 55 | |
| 56 | - return 'LLL:' . $languageFile; |
|
| 57 | - } |
|
| 56 | + return 'LLL:' . $languageFile; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param $dataType |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - protected function getLanguageFile($dataType) |
|
| 64 | - { |
|
| 65 | - return $this->getLanguageDirectory() . '/' . $dataType . '.xlf'; |
|
| 66 | - } |
|
| 59 | + /** |
|
| 60 | + * @param $dataType |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + protected function getLanguageFile($dataType) |
|
| 64 | + { |
|
| 65 | + return $this->getLanguageDirectory() . '/' . $dataType . '.xlf'; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - protected function getLanguageDirectory() |
|
| 72 | - { |
|
| 73 | - // Create language file dynamically |
|
| 74 | - $languageDirectory = Environment::getPublicPath() . '/typo3temp/vidi'; |
|
| 75 | - if (!is_dir($languageDirectory)) { |
|
| 76 | - GeneralUtility::mkdir($languageDirectory); |
|
| 77 | - } |
|
| 78 | - return $languageDirectory; |
|
| 79 | - } |
|
| 68 | + /** |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + protected function getLanguageDirectory() |
|
| 72 | + { |
|
| 73 | + // Create language file dynamically |
|
| 74 | + $languageDirectory = Environment::getPublicPath() . '/typo3temp/vidi'; |
|
| 75 | + if (!is_dir($languageDirectory)) { |
|
| 76 | + GeneralUtility::mkdir($languageDirectory); |
|
| 77 | + } |
|
| 78 | + return $languageDirectory; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return LanguageService |
|
| 83 | - */ |
|
| 84 | - protected function getLanguageService() |
|
| 85 | - { |
|
| 86 | - $locale = $GLOBALS['BE_USER']->uc['lang'] ?? ''; |
|
| 87 | - if ($locale === '') { |
|
| 88 | - $locale = 'en'; |
|
| 89 | - } |
|
| 90 | - $languageServiceFactory = GeneralUtility::makeInstance(LanguageServiceFactory::class); |
|
| 91 | - return $languageServiceFactory->create($locale); |
|
| 92 | - } |
|
| 81 | + /** |
|
| 82 | + * @return LanguageService |
|
| 83 | + */ |
|
| 84 | + protected function getLanguageService() |
|
| 85 | + { |
|
| 86 | + $locale = $GLOBALS['BE_USER']->uc['lang'] ?? ''; |
|
| 87 | + if ($locale === '') { |
|
| 88 | + $locale = 'en'; |
|
| 89 | + } |
|
| 90 | + $languageServiceFactory = GeneralUtility::makeInstance(LanguageServiceFactory::class); |
|
| 91 | + return $languageServiceFactory->create($locale); |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -16,32 +16,32 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Datetime implements FormatterInterface, SingletonInterface |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Format a date |
|
| 21 | - * |
|
| 22 | - * @param int $value |
|
| 23 | - * @return string |
|
| 24 | - * @throws \Exception |
|
| 25 | - */ |
|
| 26 | - public function format($value) |
|
| 27 | - { |
|
| 28 | - $result = ''; |
|
| 29 | - if ($value > 0) { |
|
| 30 | - $timeStamp = '@' . $value; |
|
| 31 | - try { |
|
| 32 | - $date = new \DateTime($timeStamp); |
|
| 33 | - $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
|
| 34 | - } catch (\Exception $exception) { |
|
| 35 | - throw new \Exception('"' . $timeStamp . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1447153621); |
|
| 36 | - } |
|
| 19 | + /** |
|
| 20 | + * Format a date |
|
| 21 | + * |
|
| 22 | + * @param int $value |
|
| 23 | + * @return string |
|
| 24 | + * @throws \Exception |
|
| 25 | + */ |
|
| 26 | + public function format($value) |
|
| 27 | + { |
|
| 28 | + $result = ''; |
|
| 29 | + if ($value > 0) { |
|
| 30 | + $timeStamp = '@' . $value; |
|
| 31 | + try { |
|
| 32 | + $date = new \DateTime($timeStamp); |
|
| 33 | + $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
|
| 34 | + } catch (\Exception $exception) { |
|
| 35 | + throw new \Exception('"' . $timeStamp . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1447153621); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']; |
|
| 39 | - if (strpos($format, '%') !== false) { |
|
| 40 | - $result = strftime($format, $date->format('U')); |
|
| 41 | - } else { |
|
| 42 | - $result = $date->format($format); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - return $result; |
|
| 46 | - } |
|
| 38 | + $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm']; |
|
| 39 | + if (strpos($format, '%') !== false) { |
|
| 40 | + $result = strftime($format, $date->format('U')); |
|
| 41 | + } else { |
|
| 42 | + $result = $date->format($format); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + return $result; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -14,11 +14,11 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | interface FormatterInterface |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Format a date |
|
| 19 | - * |
|
| 20 | - * @param string $value |
|
| 21 | - * @return string |
|
| 22 | - */ |
|
| 23 | - public function format($value); |
|
| 17 | + /** |
|
| 18 | + * Format a date |
|
| 19 | + * |
|
| 20 | + * @param string $value |
|
| 21 | + * @return string |
|
| 22 | + */ |
|
| 23 | + public function format($value); |
|
| 24 | 24 | } |
@@ -16,32 +16,32 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Date implements FormatterInterface, SingletonInterface |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Format a date |
|
| 21 | - * |
|
| 22 | - * @param int $value |
|
| 23 | - * @return string |
|
| 24 | - * @throws \Exception |
|
| 25 | - */ |
|
| 26 | - public function format($value) |
|
| 27 | - { |
|
| 28 | - $result = ''; |
|
| 29 | - if ((int)$value > 0) { |
|
| 30 | - $timeStamp = '@' . $value; |
|
| 31 | - try { |
|
| 32 | - $date = new \DateTime($timeStamp); |
|
| 33 | - $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
|
| 34 | - } catch (\Exception $exception) { |
|
| 35 | - throw new \Exception('"' . $timeStamp . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1447153621); |
|
| 36 | - } |
|
| 19 | + /** |
|
| 20 | + * Format a date |
|
| 21 | + * |
|
| 22 | + * @param int $value |
|
| 23 | + * @return string |
|
| 24 | + * @throws \Exception |
|
| 25 | + */ |
|
| 26 | + public function format($value) |
|
| 27 | + { |
|
| 28 | + $result = ''; |
|
| 29 | + if ((int)$value > 0) { |
|
| 30 | + $timeStamp = '@' . $value; |
|
| 31 | + try { |
|
| 32 | + $date = new \DateTime($timeStamp); |
|
| 33 | + $date->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
|
| 34 | + } catch (\Exception $exception) { |
|
| 35 | + throw new \Exception('"' . $timeStamp . '" could not be parsed by \DateTime constructor: ' . $exception->getMessage(), 1447153621); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d'; |
|
| 39 | - if (strpos($format, '%') !== false) { |
|
| 40 | - $result = strftime($format, $date->format('U')); |
|
| 41 | - } else { |
|
| 42 | - $result = $date->format($format); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - return $result; |
|
| 46 | - } |
|
| 38 | + $format = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] ?: 'Y-m-d'; |
|
| 39 | + if (strpos($format, '%') !== false) { |
|
| 40 | + $result = strftime($format, $date->format('U')); |
|
| 41 | + } else { |
|
| 42 | + $result = $date->format($format); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + return $result; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -18,27 +18,27 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class VidiModulesAspect implements TableConfigurationPostProcessingHookInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Initialize and populate TBE_MODULES_EXT with default data. |
|
| 23 | - * |
|
| 24 | - * @return void |
|
| 25 | - */ |
|
| 26 | - public function processData() |
|
| 27 | - { |
|
| 28 | - /** @var ModuleLoader $moduleLoader */ |
|
| 29 | - $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 21 | + /** |
|
| 22 | + * Initialize and populate TBE_MODULES_EXT with default data. |
|
| 23 | + * |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + public function processData() |
|
| 27 | + { |
|
| 28 | + /** @var ModuleLoader $moduleLoader */ |
|
| 29 | + $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - $configuration = GeneralUtility::makeInstance( |
|
| 33 | - ExtensionConfiguration::class |
|
| 34 | - )->get('vidi'); |
|
| 32 | + $configuration = GeneralUtility::makeInstance( |
|
| 33 | + ExtensionConfiguration::class |
|
| 34 | + )->get('vidi'); |
|
| 35 | 35 | |
| 36 | - foreach (GeneralUtility::trimExplode(',', $configuration['data_types'], true) as $dataType) { |
|
| 37 | - if (!$moduleLoader->isRegistered($dataType)) { |
|
| 38 | - $moduleLoader->setDataType($dataType) |
|
| 39 | - #->isShown(false) |
|
| 40 | - ->register(); |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 36 | + foreach (GeneralUtility::trimExplode(',', $configuration['data_types'], true) as $dataType) { |
|
| 37 | + if (!$moduleLoader->isRegistered($dataType)) { |
|
| 38 | + $moduleLoader->setDataType($dataType) |
|
| 39 | + #->isShown(false) |
|
| 40 | + ->register(); |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | } |
@@ -18,68 +18,68 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class ConfigurationUtility implements SingletonInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $extensionKey = 'vidi'; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $extensionKey = 'vidi'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $configuration = []; |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $configuration = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Returns a class instance. |
|
| 33 | - * |
|
| 34 | - * @return ConfigurationUtility|object |
|
| 35 | - * @throws \InvalidArgumentException |
|
| 36 | - */ |
|
| 37 | - public static function getInstance() |
|
| 38 | - { |
|
| 39 | - return GeneralUtility::makeInstance(self::class); |
|
| 40 | - } |
|
| 31 | + /** |
|
| 32 | + * Returns a class instance. |
|
| 33 | + * |
|
| 34 | + * @return ConfigurationUtility|object |
|
| 35 | + * @throws \InvalidArgumentException |
|
| 36 | + */ |
|
| 37 | + public static function getInstance() |
|
| 38 | + { |
|
| 39 | + return GeneralUtility::makeInstance(self::class); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor |
|
| 44 | - */ |
|
| 45 | - public function __construct() |
|
| 46 | - { |
|
| 47 | - $configuration = $configuration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get($this->extensionKey); |
|
| 42 | + /** |
|
| 43 | + * Constructor |
|
| 44 | + */ |
|
| 45 | + public function __construct() |
|
| 46 | + { |
|
| 47 | + $configuration = $configuration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get($this->extensionKey); |
|
| 48 | 48 | |
| 49 | - // Fill up configuration array with relevant values. |
|
| 50 | - foreach ($configuration as $key => $value) { |
|
| 51 | - $this->configuration[$key] = $value; |
|
| 52 | - } |
|
| 53 | - } |
|
| 49 | + // Fill up configuration array with relevant values. |
|
| 50 | + foreach ($configuration as $key => $value) { |
|
| 51 | + $this->configuration[$key] = $value; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Returns a setting key. |
|
| 57 | - * |
|
| 58 | - * @param string $key |
|
| 59 | - * @return array |
|
| 60 | - */ |
|
| 61 | - public function get($key) |
|
| 62 | - { |
|
| 63 | - return isset($this->configuration[$key]) ? $this->configuration[$key] : null; |
|
| 64 | - } |
|
| 55 | + /** |
|
| 56 | + * Returns a setting key. |
|
| 57 | + * |
|
| 58 | + * @param string $key |
|
| 59 | + * @return array |
|
| 60 | + */ |
|
| 61 | + public function get($key) |
|
| 62 | + { |
|
| 63 | + return isset($this->configuration[$key]) ? $this->configuration[$key] : null; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Set a setting key. |
|
| 68 | - * |
|
| 69 | - * @param string $key |
|
| 70 | - * @param mixed $value |
|
| 71 | - * @return void |
|
| 72 | - */ |
|
| 73 | - public function set($key, $value) |
|
| 74 | - { |
|
| 75 | - $this->configuration[$key] = $value; |
|
| 76 | - } |
|
| 66 | + /** |
|
| 67 | + * Set a setting key. |
|
| 68 | + * |
|
| 69 | + * @param string $key |
|
| 70 | + * @param mixed $value |
|
| 71 | + * @return void |
|
| 72 | + */ |
|
| 73 | + public function set($key, $value) |
|
| 74 | + { |
|
| 75 | + $this->configuration[$key] = $value; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function getConfiguration() |
|
| 82 | - { |
|
| 83 | - return $this->configuration; |
|
| 84 | - } |
|
| 78 | + /** |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function getConfiguration() |
|
| 82 | + { |
|
| 83 | + return $this->configuration; |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -20,87 +20,87 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class TcaGridAspect implements TableConfigurationPostProcessingHookInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Scans each data type of the TCA and add a Grid TCA if missing. |
|
| 25 | - * |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - public function processData() |
|
| 29 | - { |
|
| 30 | - $configuration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi'); |
|
| 23 | + /** |
|
| 24 | + * Scans each data type of the TCA and add a Grid TCA if missing. |
|
| 25 | + * |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + public function processData() |
|
| 29 | + { |
|
| 30 | + $configuration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi'); |
|
| 31 | 31 | |
| 32 | - $dataTypes = GeneralUtility::trimExplode(',', $configuration['data_types'], true); |
|
| 32 | + $dataTypes = GeneralUtility::trimExplode(',', $configuration['data_types'], true); |
|
| 33 | 33 | |
| 34 | - if (ExtensionManagementUtility::isLoaded('vidi_frontend')) { |
|
| 35 | - $extendedConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi_frontend'); |
|
| 36 | - $vidiFrontendContentTypes = GeneralUtility::trimExplode(',', $extendedConfiguration['content_types'], true); |
|
| 37 | - $extendedDataTypes = array_merge($dataTypes, $vidiFrontendContentTypes); |
|
| 38 | - $dataTypes = array_unique($extendedDataTypes); |
|
| 39 | - } |
|
| 34 | + if (ExtensionManagementUtility::isLoaded('vidi_frontend')) { |
|
| 35 | + $extendedConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('vidi_frontend'); |
|
| 36 | + $vidiFrontendContentTypes = GeneralUtility::trimExplode(',', $extendedConfiguration['content_types'], true); |
|
| 37 | + $extendedDataTypes = array_merge($dataTypes, $vidiFrontendContentTypes); |
|
| 38 | + $dataTypes = array_unique($extendedDataTypes); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - foreach ($dataTypes as $dataType) { |
|
| 42 | - $this->ensureMinimumTcaForGrid($dataType); |
|
| 43 | - } |
|
| 41 | + foreach ($dataTypes as $dataType) { |
|
| 42 | + $this->ensureMinimumTcaForGrid($dataType); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - return array($GLOBALS['TCA']); |
|
| 46 | - } |
|
| 45 | + return array($GLOBALS['TCA']); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $dataType |
|
| 50 | - */ |
|
| 51 | - protected function ensureMinimumTcaForGrid($dataType) |
|
| 52 | - { |
|
| 53 | - $labelField = $this->getLabelField($dataType); |
|
| 54 | - if (empty($GLOBALS['TCA'][$dataType]['grid'])) { |
|
| 55 | - $GLOBALS['TCA'][$dataType]['grid'] = []; |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * @param string $dataType |
|
| 50 | + */ |
|
| 51 | + protected function ensureMinimumTcaForGrid($dataType) |
|
| 52 | + { |
|
| 53 | + $labelField = $this->getLabelField($dataType); |
|
| 54 | + if (empty($GLOBALS['TCA'][$dataType]['grid'])) { |
|
| 55 | + $GLOBALS['TCA'][$dataType]['grid'] = []; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - if (empty($GLOBALS['TCA'][$dataType]['grid']['facets'])) { |
|
| 59 | - $GLOBALS['TCA'][$dataType]['grid']['facets'] = [ |
|
| 60 | - 'uid', |
|
| 61 | - $labelField, |
|
| 62 | - ]; |
|
| 63 | - } |
|
| 58 | + if (empty($GLOBALS['TCA'][$dataType]['grid']['facets'])) { |
|
| 59 | + $GLOBALS['TCA'][$dataType]['grid']['facets'] = [ |
|
| 60 | + 'uid', |
|
| 61 | + $labelField, |
|
| 62 | + ]; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - if (empty($GLOBALS['TCA'][$dataType]['grid']['columns'])) { |
|
| 66 | - $GLOBALS['TCA'][$dataType]['grid']['columns'] = [ |
|
| 67 | - '__checkbox' => [ |
|
| 68 | - 'renderer' => CheckBoxRenderer::class, |
|
| 69 | - ], |
|
| 70 | - 'uid' => [ |
|
| 71 | - 'visible' => false, |
|
| 72 | - 'label' => '', |
|
| 73 | - 'width' => '5px', |
|
| 74 | - ], |
|
| 75 | - $labelField => [ |
|
| 76 | - 'editable' => true, |
|
| 77 | - ], |
|
| 78 | - '__buttons' => [ |
|
| 79 | - 'renderer' => ButtonGroupRenderer::class, |
|
| 80 | - ], |
|
| 81 | - ]; |
|
| 82 | - } |
|
| 83 | - } |
|
| 65 | + if (empty($GLOBALS['TCA'][$dataType]['grid']['columns'])) { |
|
| 66 | + $GLOBALS['TCA'][$dataType]['grid']['columns'] = [ |
|
| 67 | + '__checkbox' => [ |
|
| 68 | + 'renderer' => CheckBoxRenderer::class, |
|
| 69 | + ], |
|
| 70 | + 'uid' => [ |
|
| 71 | + 'visible' => false, |
|
| 72 | + 'label' => '', |
|
| 73 | + 'width' => '5px', |
|
| 74 | + ], |
|
| 75 | + $labelField => [ |
|
| 76 | + 'editable' => true, |
|
| 77 | + ], |
|
| 78 | + '__buttons' => [ |
|
| 79 | + 'renderer' => ButtonGroupRenderer::class, |
|
| 80 | + ], |
|
| 81 | + ]; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Get the label name of table name. |
|
| 87 | - * |
|
| 88 | - * @param string $dataType |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - protected function getLabelField($dataType) |
|
| 92 | - { |
|
| 93 | - return $GLOBALS['TCA'][$dataType]['ctrl']['label']; |
|
| 94 | - } |
|
| 85 | + /** |
|
| 86 | + * Get the label name of table name. |
|
| 87 | + * |
|
| 88 | + * @param string $dataType |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + protected function getLabelField($dataType) |
|
| 92 | + { |
|
| 93 | + return $GLOBALS['TCA'][$dataType]['ctrl']['label']; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Tell whether the table has a label field. |
|
| 98 | - * |
|
| 99 | - * @param string $dataType |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - protected function hasLabelField($dataType) |
|
| 103 | - { |
|
| 104 | - return isset($GLOBALS['TCA'][$dataType]['ctrl']['label']); |
|
| 105 | - } |
|
| 96 | + /** |
|
| 97 | + * Tell whether the table has a label field. |
|
| 98 | + * |
|
| 99 | + * @param string $dataType |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + protected function hasLabelField($dataType) |
|
| 103 | + { |
|
| 104 | + return isset($GLOBALS['TCA'][$dataType]['ctrl']['label']); |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -19,443 +19,443 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class TableService extends AbstractTca |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $tca; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $columnTca; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $tableName; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $instances; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @throws InvalidKeyInArrayException |
|
| 44 | - * @param string $tableName |
|
| 45 | - * @return \Fab\Vidi\Tca\TableService |
|
| 46 | - */ |
|
| 47 | - public function __construct($tableName) |
|
| 48 | - { |
|
| 49 | - $this->tableName = $tableName; |
|
| 50 | - if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
| 51 | - throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106); |
|
| 52 | - } |
|
| 53 | - $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl']; |
|
| 54 | - $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns']; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Tell whether the table has a label field. |
|
| 59 | - * |
|
| 60 | - * @throws InvalidKeyInArrayException |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function hasLabelField() |
|
| 64 | - { |
|
| 65 | - return $this->has('label'); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Get the label name of table name. |
|
| 70 | - * |
|
| 71 | - * @throws InvalidKeyInArrayException |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getLabelField() |
|
| 75 | - { |
|
| 76 | - $labelField = $this->get('label'); |
|
| 77 | - if (empty($labelField)) { |
|
| 78 | - throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726); |
|
| 79 | - } |
|
| 80 | - return $labelField; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Returns the translated label of the table name. |
|
| 85 | - * |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public function getLabel() |
|
| 89 | - { |
|
| 90 | - $label = ''; |
|
| 91 | - try { |
|
| 92 | - $label = LocalizationUtility::translate($this->getLabelField(), ''); |
|
| 93 | - } catch (\InvalidArgumentException $e) { |
|
| 94 | - } |
|
| 95 | - if (empty($label)) { |
|
| 96 | - $label = $this->getLabelField(); |
|
| 97 | - } |
|
| 98 | - return $label; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Returns the title of the table. |
|
| 103 | - * |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - public function getTitle() |
|
| 107 | - { |
|
| 108 | - $title = ''; |
|
| 109 | - try { |
|
| 110 | - $title = LocalizationUtility::translate((string)$this->get('title'), ''); |
|
| 111 | - } catch (\InvalidArgumentException $e) { |
|
| 112 | - } |
|
| 113 | - if (empty($title)) { |
|
| 114 | - $title = $this->get('title'); |
|
| 115 | - } |
|
| 116 | - return $title; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Return the "disabled" field. |
|
| 121 | - * |
|
| 122 | - * @throws InvalidKeyInArrayException |
|
| 123 | - * @return string|null |
|
| 124 | - */ |
|
| 125 | - public function getHiddenField() |
|
| 126 | - { |
|
| 127 | - $hiddenField = null; |
|
| 128 | - $enableColumns = $this->get('enablecolumns'); |
|
| 129 | - if (is_array($enableColumns) && !empty($enableColumns['disabled'])) { |
|
| 130 | - $hiddenField = $enableColumns['disabled']; |
|
| 131 | - } |
|
| 132 | - return $hiddenField; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Return the "starttime" field. |
|
| 137 | - * |
|
| 138 | - * @throws InvalidKeyInArrayException |
|
| 139 | - * @return string|null |
|
| 140 | - */ |
|
| 141 | - public function getStartTimeField() |
|
| 142 | - { |
|
| 143 | - $startTimeField = null; |
|
| 144 | - $enableColumns = $this->get('enablecolumns'); |
|
| 145 | - if (is_array($enableColumns) && !empty($enableColumns['starttime'])) { |
|
| 146 | - $startTimeField = $enableColumns['starttime']; |
|
| 147 | - } |
|
| 148 | - return $startTimeField; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Return the "endtime" field. |
|
| 153 | - * |
|
| 154 | - * @throws InvalidKeyInArrayException |
|
| 155 | - * @return string|null |
|
| 156 | - */ |
|
| 157 | - public function getEndTimeField() |
|
| 158 | - { |
|
| 159 | - $endTimeField = null; |
|
| 160 | - $enableColumns = $this->get('enablecolumns'); |
|
| 161 | - if (is_array($enableColumns) && !empty($enableColumns['endtime'])) { |
|
| 162 | - $endTimeField = $enableColumns['endtime']; |
|
| 163 | - } |
|
| 164 | - return $endTimeField; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Tells whether the table is hidden. |
|
| 169 | - * |
|
| 170 | - * @return bool |
|
| 171 | - */ |
|
| 172 | - public function isHidden() |
|
| 173 | - { |
|
| 174 | - return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Tells whether the table is not hidden. |
|
| 179 | - * |
|
| 180 | - * @return bool |
|
| 181 | - */ |
|
| 182 | - public function isNotHidden() |
|
| 183 | - { |
|
| 184 | - return !$this->isHidden(); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Get the "deleted" field for the table. |
|
| 189 | - * |
|
| 190 | - * @return string|null |
|
| 191 | - */ |
|
| 192 | - public function getDeletedField() |
|
| 193 | - { |
|
| 194 | - return $this->get('delete'); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Get the modification time stamp field. |
|
| 199 | - * |
|
| 200 | - * @return string|null |
|
| 201 | - */ |
|
| 202 | - public function getTimeModificationField() |
|
| 203 | - { |
|
| 204 | - return $this->get('tstamp'); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Get the creation time stamp field. |
|
| 209 | - * |
|
| 210 | - * @return string|null |
|
| 211 | - */ |
|
| 212 | - public function getTimeCreationField() |
|
| 213 | - { |
|
| 214 | - return $this->get('crdate'); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Get the language field for the table. |
|
| 219 | - * |
|
| 220 | - * @return string|null |
|
| 221 | - */ |
|
| 222 | - public function getLanguageField() |
|
| 223 | - { |
|
| 224 | - return $this->get('languageField'); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Get the field which points to the parent. |
|
| 229 | - * |
|
| 230 | - * @return string|null |
|
| 231 | - */ |
|
| 232 | - public function getLanguageParentField() |
|
| 233 | - { |
|
| 234 | - return $this->get('transOrigPointerField'); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Returns the default order in the form of a SQL segment. |
|
| 239 | - * |
|
| 240 | - * @return string|null |
|
| 241 | - */ |
|
| 242 | - public function getDefaultOrderSql() |
|
| 243 | - { |
|
| 244 | - // "sortby" typically has "sorting" as value. |
|
| 245 | - $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby'); |
|
| 246 | - return $order; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Returns the parsed default orderings. |
|
| 251 | - * Returns array looks like array('title' => 'ASC'); |
|
| 252 | - * |
|
| 253 | - * @return array |
|
| 254 | - */ |
|
| 255 | - public function getDefaultOrderings() |
|
| 256 | - { |
|
| 257 | - // first clean up the sql segment |
|
| 258 | - $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql()); |
|
| 259 | - $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true); |
|
| 260 | - |
|
| 261 | - $orderings = []; |
|
| 262 | - foreach ($defaultOrderParts as $defaultOrderPart) { |
|
| 263 | - $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart); |
|
| 264 | - if (empty($parts[1])) { |
|
| 265 | - $parts[1] = QueryInterface::ORDER_DESCENDING; |
|
| 266 | - } |
|
| 267 | - $orderings[$parts[0]] = $parts[1]; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - return $orderings; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Returns the searchable fields. |
|
| 275 | - * |
|
| 276 | - * @return string|null |
|
| 277 | - */ |
|
| 278 | - public function getSearchFields() |
|
| 279 | - { |
|
| 280 | - return $this->get('searchFields'); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Returns an array containing the field names. |
|
| 285 | - * |
|
| 286 | - * @return array |
|
| 287 | - */ |
|
| 288 | - public function getFields() |
|
| 289 | - { |
|
| 290 | - return array_keys($this->columnTca); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Returns an array containing the fields and their configuration. |
|
| 295 | - * |
|
| 296 | - * @return array |
|
| 297 | - */ |
|
| 298 | - public function getFieldsAndConfiguration() |
|
| 299 | - { |
|
| 300 | - return $this->columnTca; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Tell whether we have a field "sorting". |
|
| 305 | - * |
|
| 306 | - * @return bool |
|
| 307 | - */ |
|
| 308 | - public function hasSortableField() |
|
| 309 | - { |
|
| 310 | - return $this->has('sortby'); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Tell whether the field exists or not. |
|
| 315 | - * |
|
| 316 | - * @param string $fieldName |
|
| 317 | - * @return bool |
|
| 318 | - */ |
|
| 319 | - public function hasField($fieldName) |
|
| 320 | - { |
|
| 321 | - if ($this->isComposite($fieldName)) { |
|
| 322 | - $parts = explode('.', $fieldName); |
|
| 323 | - list($strippedFieldPath, $possibleTableName) = $parts; |
|
| 324 | - $hasField = isset($this->columnTca[$strippedFieldPath], $GLOBALS['TCA'][$possibleTableName]); |
|
| 325 | - |
|
| 326 | - // Continue checking that the $strippedFieldName is of type "group" |
|
| 327 | - if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldPath]) && count($parts) > 2) { |
|
| 328 | - $hasField = Tca::table($this->tableName)->field($strippedFieldPath)->isGroup(); // Group |
|
| 329 | - } elseif (isset($this->columnTca[$strippedFieldPath]['config']['readOnly']) && (bool)$this->columnTca[$strippedFieldPath]['config']['readOnly']) { |
|
| 330 | - $hasField = false; // handle case metadata.fe_groups where "fe_groups" is a tableName. |
|
| 331 | - } |
|
| 332 | - } else { |
|
| 333 | - $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields(), true); |
|
| 334 | - } |
|
| 335 | - return $hasField; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * Tell whether the field name contains a path, e.g. metadata.title |
|
| 340 | - * |
|
| 341 | - * @param string $fieldName |
|
| 342 | - * @return boolean |
|
| 343 | - */ |
|
| 344 | - public function isComposite($fieldName) |
|
| 345 | - { |
|
| 346 | - return strpos($fieldName, '.') > 0; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Tells whether the $key exists. |
|
| 351 | - * |
|
| 352 | - * @param string $key |
|
| 353 | - * @return string |
|
| 354 | - */ |
|
| 355 | - public function has($key) |
|
| 356 | - { |
|
| 357 | - return isset($this->tca[$key]); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Tells whether the table name has "workspace" support. |
|
| 362 | - * |
|
| 363 | - * @return string |
|
| 364 | - */ |
|
| 365 | - public function hasWorkspaceSupport() |
|
| 366 | - { |
|
| 367 | - return isset($this->tca['versioningWS']); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Tells whether the table name has "language" support. |
|
| 372 | - * |
|
| 373 | - * @return string |
|
| 374 | - */ |
|
| 375 | - public function hasLanguageSupport() |
|
| 376 | - { |
|
| 377 | - return isset($this->tca['languageField']); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Return configuration value given a key. |
|
| 382 | - * |
|
| 383 | - * @param string $key |
|
| 384 | - * @return string|null |
|
| 385 | - */ |
|
| 386 | - public function get($key) |
|
| 387 | - { |
|
| 388 | - return $this->has($key) ? $this->tca[$key] : null; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @return array |
|
| 393 | - */ |
|
| 394 | - public function getTca() |
|
| 395 | - { |
|
| 396 | - return $this->tca; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Tell whether the current BE User has access to this field. |
|
| 401 | - * |
|
| 402 | - * @return bool |
|
| 403 | - */ |
|
| 404 | - public function hasAccess() |
|
| 405 | - { |
|
| 406 | - $hasAccess = true; |
|
| 407 | - if ($this->isBackendMode()) { |
|
| 408 | - $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName); |
|
| 409 | - } |
|
| 410 | - return $hasAccess; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * @param string $fieldName |
|
| 415 | - * @throws \Exception |
|
| 416 | - * @return FieldService |
|
| 417 | - */ |
|
| 418 | - public function field($fieldName) |
|
| 419 | - { |
|
| 420 | - // In case field contains items.tx_table for field type "group" |
|
| 421 | - $compositeField = ''; |
|
| 422 | - if (strpos($fieldName, '.') !== false) { |
|
| 423 | - $compositeField = $fieldName; |
|
| 424 | - $fieldParts = explode('.', $compositeField, 2); |
|
| 425 | - $fieldName = $fieldParts[0]; |
|
| 426 | - |
|
| 427 | - // Special when field has been instantiated without the field name and path. |
|
| 428 | - if (!empty($this->instances[$fieldName])) { |
|
| 429 | - /** @var FieldService $field */ |
|
| 430 | - $field = $this->instances[$fieldName]; |
|
| 431 | - $field->setCompositeField($compositeField); |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // True for system fields such as uid, pid that don't necessarily have a TCA. |
|
| 436 | - if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) { |
|
| 437 | - $this->columnTca[$fieldName] = []; |
|
| 438 | - } elseif (empty($this->columnTca[$fieldName])) { |
|
| 439 | - $message = sprintf( |
|
| 440 | - 'Does the field really exist? No TCA entry found for field "%s" for table "%s"', |
|
| 441 | - $fieldName, |
|
| 442 | - $this->tableName |
|
| 443 | - ); |
|
| 444 | - throw new \Exception($message, 1385554481); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - if (empty($this->instances[$fieldName])) { |
|
| 449 | - $instance = GeneralUtility::makeInstance( |
|
| 450 | - 'Fab\Vidi\Tca\FieldService', |
|
| 451 | - $fieldName, |
|
| 452 | - $this->columnTca[$fieldName], |
|
| 453 | - $this->tableName, |
|
| 454 | - $compositeField |
|
| 455 | - ); |
|
| 456 | - |
|
| 457 | - $this->instances[$fieldName] = $instance; |
|
| 458 | - } |
|
| 459 | - return $this->instances[$fieldName]; |
|
| 460 | - } |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $tca; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $columnTca; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $tableName; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $instances; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @throws InvalidKeyInArrayException |
|
| 44 | + * @param string $tableName |
|
| 45 | + * @return \Fab\Vidi\Tca\TableService |
|
| 46 | + */ |
|
| 47 | + public function __construct($tableName) |
|
| 48 | + { |
|
| 49 | + $this->tableName = $tableName; |
|
| 50 | + if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
| 51 | + throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106); |
|
| 52 | + } |
|
| 53 | + $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl']; |
|
| 54 | + $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns']; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Tell whether the table has a label field. |
|
| 59 | + * |
|
| 60 | + * @throws InvalidKeyInArrayException |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function hasLabelField() |
|
| 64 | + { |
|
| 65 | + return $this->has('label'); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Get the label name of table name. |
|
| 70 | + * |
|
| 71 | + * @throws InvalidKeyInArrayException |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getLabelField() |
|
| 75 | + { |
|
| 76 | + $labelField = $this->get('label'); |
|
| 77 | + if (empty($labelField)) { |
|
| 78 | + throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726); |
|
| 79 | + } |
|
| 80 | + return $labelField; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Returns the translated label of the table name. |
|
| 85 | + * |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public function getLabel() |
|
| 89 | + { |
|
| 90 | + $label = ''; |
|
| 91 | + try { |
|
| 92 | + $label = LocalizationUtility::translate($this->getLabelField(), ''); |
|
| 93 | + } catch (\InvalidArgumentException $e) { |
|
| 94 | + } |
|
| 95 | + if (empty($label)) { |
|
| 96 | + $label = $this->getLabelField(); |
|
| 97 | + } |
|
| 98 | + return $label; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Returns the title of the table. |
|
| 103 | + * |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + public function getTitle() |
|
| 107 | + { |
|
| 108 | + $title = ''; |
|
| 109 | + try { |
|
| 110 | + $title = LocalizationUtility::translate((string)$this->get('title'), ''); |
|
| 111 | + } catch (\InvalidArgumentException $e) { |
|
| 112 | + } |
|
| 113 | + if (empty($title)) { |
|
| 114 | + $title = $this->get('title'); |
|
| 115 | + } |
|
| 116 | + return $title; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Return the "disabled" field. |
|
| 121 | + * |
|
| 122 | + * @throws InvalidKeyInArrayException |
|
| 123 | + * @return string|null |
|
| 124 | + */ |
|
| 125 | + public function getHiddenField() |
|
| 126 | + { |
|
| 127 | + $hiddenField = null; |
|
| 128 | + $enableColumns = $this->get('enablecolumns'); |
|
| 129 | + if (is_array($enableColumns) && !empty($enableColumns['disabled'])) { |
|
| 130 | + $hiddenField = $enableColumns['disabled']; |
|
| 131 | + } |
|
| 132 | + return $hiddenField; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Return the "starttime" field. |
|
| 137 | + * |
|
| 138 | + * @throws InvalidKeyInArrayException |
|
| 139 | + * @return string|null |
|
| 140 | + */ |
|
| 141 | + public function getStartTimeField() |
|
| 142 | + { |
|
| 143 | + $startTimeField = null; |
|
| 144 | + $enableColumns = $this->get('enablecolumns'); |
|
| 145 | + if (is_array($enableColumns) && !empty($enableColumns['starttime'])) { |
|
| 146 | + $startTimeField = $enableColumns['starttime']; |
|
| 147 | + } |
|
| 148 | + return $startTimeField; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Return the "endtime" field. |
|
| 153 | + * |
|
| 154 | + * @throws InvalidKeyInArrayException |
|
| 155 | + * @return string|null |
|
| 156 | + */ |
|
| 157 | + public function getEndTimeField() |
|
| 158 | + { |
|
| 159 | + $endTimeField = null; |
|
| 160 | + $enableColumns = $this->get('enablecolumns'); |
|
| 161 | + if (is_array($enableColumns) && !empty($enableColumns['endtime'])) { |
|
| 162 | + $endTimeField = $enableColumns['endtime']; |
|
| 163 | + } |
|
| 164 | + return $endTimeField; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Tells whether the table is hidden. |
|
| 169 | + * |
|
| 170 | + * @return bool |
|
| 171 | + */ |
|
| 172 | + public function isHidden() |
|
| 173 | + { |
|
| 174 | + return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Tells whether the table is not hidden. |
|
| 179 | + * |
|
| 180 | + * @return bool |
|
| 181 | + */ |
|
| 182 | + public function isNotHidden() |
|
| 183 | + { |
|
| 184 | + return !$this->isHidden(); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Get the "deleted" field for the table. |
|
| 189 | + * |
|
| 190 | + * @return string|null |
|
| 191 | + */ |
|
| 192 | + public function getDeletedField() |
|
| 193 | + { |
|
| 194 | + return $this->get('delete'); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Get the modification time stamp field. |
|
| 199 | + * |
|
| 200 | + * @return string|null |
|
| 201 | + */ |
|
| 202 | + public function getTimeModificationField() |
|
| 203 | + { |
|
| 204 | + return $this->get('tstamp'); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Get the creation time stamp field. |
|
| 209 | + * |
|
| 210 | + * @return string|null |
|
| 211 | + */ |
|
| 212 | + public function getTimeCreationField() |
|
| 213 | + { |
|
| 214 | + return $this->get('crdate'); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Get the language field for the table. |
|
| 219 | + * |
|
| 220 | + * @return string|null |
|
| 221 | + */ |
|
| 222 | + public function getLanguageField() |
|
| 223 | + { |
|
| 224 | + return $this->get('languageField'); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Get the field which points to the parent. |
|
| 229 | + * |
|
| 230 | + * @return string|null |
|
| 231 | + */ |
|
| 232 | + public function getLanguageParentField() |
|
| 233 | + { |
|
| 234 | + return $this->get('transOrigPointerField'); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Returns the default order in the form of a SQL segment. |
|
| 239 | + * |
|
| 240 | + * @return string|null |
|
| 241 | + */ |
|
| 242 | + public function getDefaultOrderSql() |
|
| 243 | + { |
|
| 244 | + // "sortby" typically has "sorting" as value. |
|
| 245 | + $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby'); |
|
| 246 | + return $order; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Returns the parsed default orderings. |
|
| 251 | + * Returns array looks like array('title' => 'ASC'); |
|
| 252 | + * |
|
| 253 | + * @return array |
|
| 254 | + */ |
|
| 255 | + public function getDefaultOrderings() |
|
| 256 | + { |
|
| 257 | + // first clean up the sql segment |
|
| 258 | + $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql()); |
|
| 259 | + $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true); |
|
| 260 | + |
|
| 261 | + $orderings = []; |
|
| 262 | + foreach ($defaultOrderParts as $defaultOrderPart) { |
|
| 263 | + $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart); |
|
| 264 | + if (empty($parts[1])) { |
|
| 265 | + $parts[1] = QueryInterface::ORDER_DESCENDING; |
|
| 266 | + } |
|
| 267 | + $orderings[$parts[0]] = $parts[1]; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + return $orderings; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Returns the searchable fields. |
|
| 275 | + * |
|
| 276 | + * @return string|null |
|
| 277 | + */ |
|
| 278 | + public function getSearchFields() |
|
| 279 | + { |
|
| 280 | + return $this->get('searchFields'); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Returns an array containing the field names. |
|
| 285 | + * |
|
| 286 | + * @return array |
|
| 287 | + */ |
|
| 288 | + public function getFields() |
|
| 289 | + { |
|
| 290 | + return array_keys($this->columnTca); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Returns an array containing the fields and their configuration. |
|
| 295 | + * |
|
| 296 | + * @return array |
|
| 297 | + */ |
|
| 298 | + public function getFieldsAndConfiguration() |
|
| 299 | + { |
|
| 300 | + return $this->columnTca; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Tell whether we have a field "sorting". |
|
| 305 | + * |
|
| 306 | + * @return bool |
|
| 307 | + */ |
|
| 308 | + public function hasSortableField() |
|
| 309 | + { |
|
| 310 | + return $this->has('sortby'); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Tell whether the field exists or not. |
|
| 315 | + * |
|
| 316 | + * @param string $fieldName |
|
| 317 | + * @return bool |
|
| 318 | + */ |
|
| 319 | + public function hasField($fieldName) |
|
| 320 | + { |
|
| 321 | + if ($this->isComposite($fieldName)) { |
|
| 322 | + $parts = explode('.', $fieldName); |
|
| 323 | + list($strippedFieldPath, $possibleTableName) = $parts; |
|
| 324 | + $hasField = isset($this->columnTca[$strippedFieldPath], $GLOBALS['TCA'][$possibleTableName]); |
|
| 325 | + |
|
| 326 | + // Continue checking that the $strippedFieldName is of type "group" |
|
| 327 | + if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldPath]) && count($parts) > 2) { |
|
| 328 | + $hasField = Tca::table($this->tableName)->field($strippedFieldPath)->isGroup(); // Group |
|
| 329 | + } elseif (isset($this->columnTca[$strippedFieldPath]['config']['readOnly']) && (bool)$this->columnTca[$strippedFieldPath]['config']['readOnly']) { |
|
| 330 | + $hasField = false; // handle case metadata.fe_groups where "fe_groups" is a tableName. |
|
| 331 | + } |
|
| 332 | + } else { |
|
| 333 | + $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields(), true); |
|
| 334 | + } |
|
| 335 | + return $hasField; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * Tell whether the field name contains a path, e.g. metadata.title |
|
| 340 | + * |
|
| 341 | + * @param string $fieldName |
|
| 342 | + * @return boolean |
|
| 343 | + */ |
|
| 344 | + public function isComposite($fieldName) |
|
| 345 | + { |
|
| 346 | + return strpos($fieldName, '.') > 0; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Tells whether the $key exists. |
|
| 351 | + * |
|
| 352 | + * @param string $key |
|
| 353 | + * @return string |
|
| 354 | + */ |
|
| 355 | + public function has($key) |
|
| 356 | + { |
|
| 357 | + return isset($this->tca[$key]); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Tells whether the table name has "workspace" support. |
|
| 362 | + * |
|
| 363 | + * @return string |
|
| 364 | + */ |
|
| 365 | + public function hasWorkspaceSupport() |
|
| 366 | + { |
|
| 367 | + return isset($this->tca['versioningWS']); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Tells whether the table name has "language" support. |
|
| 372 | + * |
|
| 373 | + * @return string |
|
| 374 | + */ |
|
| 375 | + public function hasLanguageSupport() |
|
| 376 | + { |
|
| 377 | + return isset($this->tca['languageField']); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Return configuration value given a key. |
|
| 382 | + * |
|
| 383 | + * @param string $key |
|
| 384 | + * @return string|null |
|
| 385 | + */ |
|
| 386 | + public function get($key) |
|
| 387 | + { |
|
| 388 | + return $this->has($key) ? $this->tca[$key] : null; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @return array |
|
| 393 | + */ |
|
| 394 | + public function getTca() |
|
| 395 | + { |
|
| 396 | + return $this->tca; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Tell whether the current BE User has access to this field. |
|
| 401 | + * |
|
| 402 | + * @return bool |
|
| 403 | + */ |
|
| 404 | + public function hasAccess() |
|
| 405 | + { |
|
| 406 | + $hasAccess = true; |
|
| 407 | + if ($this->isBackendMode()) { |
|
| 408 | + $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName); |
|
| 409 | + } |
|
| 410 | + return $hasAccess; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * @param string $fieldName |
|
| 415 | + * @throws \Exception |
|
| 416 | + * @return FieldService |
|
| 417 | + */ |
|
| 418 | + public function field($fieldName) |
|
| 419 | + { |
|
| 420 | + // In case field contains items.tx_table for field type "group" |
|
| 421 | + $compositeField = ''; |
|
| 422 | + if (strpos($fieldName, '.') !== false) { |
|
| 423 | + $compositeField = $fieldName; |
|
| 424 | + $fieldParts = explode('.', $compositeField, 2); |
|
| 425 | + $fieldName = $fieldParts[0]; |
|
| 426 | + |
|
| 427 | + // Special when field has been instantiated without the field name and path. |
|
| 428 | + if (!empty($this->instances[$fieldName])) { |
|
| 429 | + /** @var FieldService $field */ |
|
| 430 | + $field = $this->instances[$fieldName]; |
|
| 431 | + $field->setCompositeField($compositeField); |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // True for system fields such as uid, pid that don't necessarily have a TCA. |
|
| 436 | + if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) { |
|
| 437 | + $this->columnTca[$fieldName] = []; |
|
| 438 | + } elseif (empty($this->columnTca[$fieldName])) { |
|
| 439 | + $message = sprintf( |
|
| 440 | + 'Does the field really exist? No TCA entry found for field "%s" for table "%s"', |
|
| 441 | + $fieldName, |
|
| 442 | + $this->tableName |
|
| 443 | + ); |
|
| 444 | + throw new \Exception($message, 1385554481); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + if (empty($this->instances[$fieldName])) { |
|
| 449 | + $instance = GeneralUtility::makeInstance( |
|
| 450 | + 'Fab\Vidi\Tca\FieldService', |
|
| 451 | + $fieldName, |
|
| 452 | + $this->columnTca[$fieldName], |
|
| 453 | + $this->tableName, |
|
| 454 | + $compositeField |
|
| 455 | + ); |
|
| 456 | + |
|
| 457 | + $this->instances[$fieldName] = $instance; |
|
| 458 | + } |
|
| 459 | + return $this->instances[$fieldName]; |
|
| 460 | + } |
|
| 461 | 461 | } |