@@ -18,34 +18,34 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class EditUri extends AbstractComponentView |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Renders a "edit" button to be placed in the grid. |
|
| 23 | - * |
|
| 24 | - * @param Content $object |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function render(Content $object = null) |
|
| 28 | - { |
|
| 29 | - $uri = BackendUtility::getModuleUrl( |
|
| 30 | - 'record_edit', |
|
| 31 | - array( |
|
| 32 | - $this->getEditParameterName($object) => 'edit', |
|
| 33 | - 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 36 | - return $uri; |
|
| 37 | - } |
|
| 21 | + /** |
|
| 22 | + * Renders a "edit" button to be placed in the grid. |
|
| 23 | + * |
|
| 24 | + * @param Content $object |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function render(Content $object = null) |
|
| 28 | + { |
|
| 29 | + $uri = BackendUtility::getModuleUrl( |
|
| 30 | + 'record_edit', |
|
| 31 | + array( |
|
| 32 | + $this->getEditParameterName($object) => 'edit', |
|
| 33 | + 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | + return $uri; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param Content $object |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - protected function getEditParameterName(Content $object) |
|
| 44 | - { |
|
| 45 | - return sprintf( |
|
| 46 | - 'edit[%s][%s]', |
|
| 47 | - $object->getDataType(), |
|
| 48 | - $object->getUid() |
|
| 49 | - ); |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Content $object |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + protected function getEditParameterName(Content $object) |
|
| 44 | + { |
|
| 45 | + return sprintf( |
|
| 46 | + 'edit[%s][%s]', |
|
| 47 | + $object->getDataType(), |
|
| 48 | + $object->getUid() |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -19,46 +19,46 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class DeleteButton extends AbstractComponentView |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Renders a "delete" button to be placed in the grid. |
|
| 24 | - * |
|
| 25 | - * @param Content $object |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function render(Content $object = null) |
|
| 29 | - { |
|
| 30 | - $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
| 31 | - $label = $object[$labelField] ? $object[$labelField] : $object->getUid(); |
|
| 22 | + /** |
|
| 23 | + * Renders a "delete" button to be placed in the grid. |
|
| 24 | + * |
|
| 25 | + * @param Content $object |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function render(Content $object = null) |
|
| 29 | + { |
|
| 30 | + $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
| 31 | + $label = $object[$labelField] ? $object[$labelField] : $object->getUid(); |
|
| 32 | 32 | |
| 33 | - return $this->makeLinkButton() |
|
| 34 | - ->setHref($this->getDeleteUri($object)) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - 'label' => $label, |
|
| 39 | - ]) |
|
| 40 | - ->setClasses('btn-delete') |
|
| 41 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:delete')) |
|
| 42 | - ->setIcon($this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL)) |
|
| 43 | - ->render(); |
|
| 44 | - } |
|
| 33 | + return $this->makeLinkButton() |
|
| 34 | + ->setHref($this->getDeleteUri($object)) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + 'label' => $label, |
|
| 39 | + ]) |
|
| 40 | + ->setClasses('btn-delete') |
|
| 41 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:delete')) |
|
| 42 | + ->setIcon($this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL)) |
|
| 43 | + ->render(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param Content $object |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - protected function getDeleteUri(Content $object) |
|
| 51 | - { |
|
| 52 | - $additionalParameters = array( |
|
| 53 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 54 | - 'controller' => 'Content', |
|
| 55 | - 'action' => 'delete', |
|
| 56 | - 'format' => 'json', |
|
| 57 | - 'matches' => array( |
|
| 58 | - 'uid' => $object->getUid(), |
|
| 59 | - ), |
|
| 60 | - ), |
|
| 61 | - ); |
|
| 62 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 63 | - } |
|
| 46 | + /** |
|
| 47 | + * @param Content $object |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + protected function getDeleteUri(Content $object) |
|
| 51 | + { |
|
| 52 | + $additionalParameters = array( |
|
| 53 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 54 | + 'controller' => 'Content', |
|
| 55 | + 'action' => 'delete', |
|
| 56 | + 'format' => 'json', |
|
| 57 | + 'matches' => array( |
|
| 58 | + 'uid' => $object->getUid(), |
|
| 59 | + ), |
|
| 60 | + ), |
|
| 61 | + ); |
|
| 62 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -22,108 +22,108 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class NewButton extends AbstractComponentView |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * Renders a "new" button to be placed in the doc header. |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function render(): string |
|
| 31 | - { |
|
| 32 | - $output = ''; |
|
| 25 | + /** |
|
| 26 | + * Renders a "new" button to be placed in the doc header. |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function render(): string |
|
| 31 | + { |
|
| 32 | + $output = ''; |
|
| 33 | 33 | |
| 34 | - // New button only for the current data type. |
|
| 35 | - if ($this->getModulePidService()->isConfiguredPidValid()) { |
|
| 36 | - $output = $this->makeLinkButton()->setHref($this->getNewUri()) |
|
| 37 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:newRecordGeneral')) |
|
| 38 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL)) |
|
| 39 | - ->render(); |
|
| 40 | - } |
|
| 41 | - return $output; |
|
| 42 | - } |
|
| 34 | + // New button only for the current data type. |
|
| 35 | + if ($this->getModulePidService()->isConfiguredPidValid()) { |
|
| 36 | + $output = $this->makeLinkButton()->setHref($this->getNewUri()) |
|
| 37 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:newRecordGeneral')) |
|
| 38 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL)) |
|
| 39 | + ->render(); |
|
| 40 | + } |
|
| 41 | + return $output; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Render a create URI given a data type. |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - protected function getUriWizardNew(): string |
|
| 50 | - { |
|
| 51 | - // Return URL in any case. |
|
| 52 | - $arguments['returnUrl'] = $this->getModuleLoader()->getModuleUrl(); |
|
| 44 | + /** |
|
| 45 | + * Render a create URI given a data type. |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + protected function getUriWizardNew(): string |
|
| 50 | + { |
|
| 51 | + // Return URL in any case. |
|
| 52 | + $arguments['returnUrl'] = $this->getModuleLoader()->getModuleUrl(); |
|
| 53 | 53 | |
| 54 | - // Add possible id parameter |
|
| 55 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 56 | - $arguments['id'] = GeneralUtility::_GP(Parameter::PID); |
|
| 57 | - } |
|
| 54 | + // Add possible id parameter |
|
| 55 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 56 | + $arguments['id'] = GeneralUtility::_GP(Parameter::PID); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $uri = BackendUtility::getModuleUrl( |
|
| 60 | - 'db_new', |
|
| 61 | - $arguments |
|
| 62 | - ); |
|
| 59 | + $uri = BackendUtility::getModuleUrl( |
|
| 60 | + 'db_new', |
|
| 61 | + $arguments |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | - return $uri; |
|
| 65 | - } |
|
| 64 | + return $uri; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Render a create URI given a data type. |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - protected function getNewUri(): string |
|
| 73 | - { |
|
| 74 | - $uri = BackendUtility::getModuleUrl( |
|
| 75 | - 'record_edit', |
|
| 76 | - array( |
|
| 77 | - $this->getNewParameterName() => 'new', |
|
| 78 | - 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 79 | - ) |
|
| 80 | - ); |
|
| 81 | - return $uri; |
|
| 82 | - } |
|
| 67 | + /** |
|
| 68 | + * Render a create URI given a data type. |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + protected function getNewUri(): string |
|
| 73 | + { |
|
| 74 | + $uri = BackendUtility::getModuleUrl( |
|
| 75 | + 'record_edit', |
|
| 76 | + array( |
|
| 77 | + $this->getNewParameterName() => 'new', |
|
| 78 | + 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 79 | + ) |
|
| 80 | + ); |
|
| 81 | + return $uri; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - protected function getNewParameterName(): string |
|
| 88 | - { |
|
| 89 | - return sprintf( |
|
| 90 | - 'edit[%s][%s]', |
|
| 91 | - $this->getModuleLoader()->getDataType(), |
|
| 92 | - $this->getStoragePid() |
|
| 93 | - ); |
|
| 94 | - } |
|
| 84 | + /** |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + protected function getNewParameterName(): string |
|
| 88 | + { |
|
| 89 | + return sprintf( |
|
| 90 | + 'edit[%s][%s]', |
|
| 91 | + $this->getModuleLoader()->getDataType(), |
|
| 92 | + $this->getStoragePid() |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Return the default configured pid. |
|
| 98 | - * |
|
| 99 | - * @return int |
|
| 100 | - */ |
|
| 101 | - protected function getStoragePid(): int |
|
| 102 | - { |
|
| 103 | - if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 104 | - $pid = GeneralUtility::_GP(Parameter::PID); |
|
| 105 | - } elseif ((int)Tca::table()->get('rootLevel') === 1) { |
|
| 106 | - $pid = 0; |
|
| 107 | - } else { |
|
| 108 | - // Get configuration from User TSConfig if any |
|
| 109 | - $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->getModuleLoader()->getDataType()); |
|
| 110 | - $tsConfig = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
| 111 | - $pid = $tsConfig['value']; |
|
| 96 | + /** |
|
| 97 | + * Return the default configured pid. |
|
| 98 | + * |
|
| 99 | + * @return int |
|
| 100 | + */ |
|
| 101 | + protected function getStoragePid(): int |
|
| 102 | + { |
|
| 103 | + if (GeneralUtility::_GP(Parameter::PID)) { |
|
| 104 | + $pid = GeneralUtility::_GP(Parameter::PID); |
|
| 105 | + } elseif ((int)Tca::table()->get('rootLevel') === 1) { |
|
| 106 | + $pid = 0; |
|
| 107 | + } else { |
|
| 108 | + // Get configuration from User TSConfig if any |
|
| 109 | + $tsConfigPath = sprintf('tx_vidi.dataType.%s.storagePid', $this->getModuleLoader()->getDataType()); |
|
| 110 | + $tsConfig = $this->getBackendUser()->getTSConfig($tsConfigPath); |
|
| 111 | + $pid = $tsConfig['value']; |
|
| 112 | 112 | |
| 113 | - // Get pid from Module Loader |
|
| 114 | - if (null === $pid) { |
|
| 115 | - $pid = $this->getModuleLoader()->getDefaultPid(); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - return (int)$pid; |
|
| 119 | - } |
|
| 113 | + // Get pid from Module Loader |
|
| 114 | + if (null === $pid) { |
|
| 115 | + $pid = $this->getModuleLoader()->getDefaultPid(); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + return (int)$pid; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @return ModulePidService|object |
|
| 123 | - */ |
|
| 124 | - public function getModulePidService() |
|
| 125 | - { |
|
| 126 | - /** @var ModulePidService $modulePidService */ |
|
| 127 | - return GeneralUtility::makeInstance(ModulePidService::class); |
|
| 128 | - } |
|
| 121 | + /** |
|
| 122 | + * @return ModulePidService|object |
|
| 123 | + */ |
|
| 124 | + public function getModulePidService() |
|
| 125 | + { |
|
| 126 | + /** @var ModulePidService $modulePidService */ |
|
| 127 | + return GeneralUtility::makeInstance(ModulePidService::class); |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -17,31 +17,31 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class ToolButton extends AbstractComponentView |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Renders a dropdown menu for storage. |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public function render() |
|
| 26 | - { |
|
| 27 | - $result = ''; |
|
| 20 | + /** |
|
| 21 | + * Renders a dropdown menu for storage. |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public function render() |
|
| 26 | + { |
|
| 27 | + $result = ''; |
|
| 28 | 28 | |
| 29 | - // Compute the additional parameters. |
|
| 30 | - $additionalParameters = array( |
|
| 31 | - $this->getModuleLoader()->getParameterPrefix() => array('controller' => 'Tool', 'action' => 'welcome'), |
|
| 32 | - ); |
|
| 29 | + // Compute the additional parameters. |
|
| 30 | + $additionalParameters = array( |
|
| 31 | + $this->getModuleLoader()->getParameterPrefix() => array('controller' => 'Tool', 'action' => 'welcome'), |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | - // Get current data type and tell whether there are registered tools. |
|
| 35 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
| 34 | + // Get current data type and tell whether there are registered tools. |
|
| 35 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
| 36 | 36 | |
| 37 | - if (ToolRegistry::getInstance()->hasAnyTools($dataType)) { |
|
| 38 | - $result = sprintf( |
|
| 39 | - '<a href="%s&returnUrl=%s" class="btn btn-default btn-sm btn-doc-header" title="%s"><span class="t3-icon fa fa-cog" aria-hidden="true"></span></a>', |
|
| 40 | - $this->getModuleLoader()->getModuleUrl($additionalParameters), |
|
| 41 | - urlencode($this->getModuleLoader()->getModuleUrl()), |
|
| 42 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:open_tools') |
|
| 43 | - ); |
|
| 44 | - } |
|
| 45 | - return $result; |
|
| 46 | - } |
|
| 37 | + if (ToolRegistry::getInstance()->hasAnyTools($dataType)) { |
|
| 38 | + $result = sprintf( |
|
| 39 | + '<a href="%s&returnUrl=%s" class="btn btn-default btn-sm btn-doc-header" title="%s"><span class="t3-icon fa fa-cog" aria-hidden="true"></span></a>', |
|
| 40 | + $this->getModuleLoader()->getModuleUrl($additionalParameters), |
|
| 41 | + urlencode($this->getModuleLoader()->getModuleUrl()), |
|
| 42 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:open_tools') |
|
| 43 | + ); |
|
| 44 | + } |
|
| 45 | + return $result; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -20,34 +20,34 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class EditButton extends AbstractComponentView |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Renders a "edit" button to be placed in the grid. |
|
| 25 | - * |
|
| 26 | - * @param Content $object |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 29 | - public function render(Content $object = null) |
|
| 30 | - { |
|
| 31 | - $editUri = $this->getUriRenderer()->render($object); |
|
| 23 | + /** |
|
| 24 | + * Renders a "edit" button to be placed in the grid. |
|
| 25 | + * |
|
| 26 | + * @param Content $object |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | + public function render(Content $object = null) |
|
| 30 | + { |
|
| 31 | + $editUri = $this->getUriRenderer()->render($object); |
|
| 32 | 32 | |
| 33 | - return $this->makeLinkButton() |
|
| 34 | - ->setHref($editUri) |
|
| 35 | - ->setDataAttributes([ |
|
| 36 | - 'uid' => $object->getUid(), |
|
| 37 | - 'toggle' => 'tooltip', |
|
| 38 | - ]) |
|
| 39 | - ->setClasses('btn-edit') |
|
| 40 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:edit')) |
|
| 41 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
| 42 | - ->render(); |
|
| 43 | - } |
|
| 33 | + return $this->makeLinkButton() |
|
| 34 | + ->setHref($editUri) |
|
| 35 | + ->setDataAttributes([ |
|
| 36 | + 'uid' => $object->getUid(), |
|
| 37 | + 'toggle' => 'tooltip', |
|
| 38 | + ]) |
|
| 39 | + ->setClasses('btn-edit') |
|
| 40 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf:edit')) |
|
| 41 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-open', Icon::SIZE_SMALL)) |
|
| 42 | + ->render(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return EditUri |
|
| 47 | - * @throws \InvalidArgumentException |
|
| 48 | - */ |
|
| 49 | - protected function getUriRenderer() |
|
| 50 | - { |
|
| 51 | - return GeneralUtility::makeInstance(EditUri::class); |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * @return EditUri |
|
| 47 | + * @throws \InvalidArgumentException |
|
| 48 | + */ |
|
| 49 | + protected function getUriRenderer() |
|
| 50 | + { |
|
| 51 | + return GeneralUtility::makeInstance(EditUri::class); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -18,51 +18,51 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class ClipboardButton extends AbstractComponentView |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Renders a "clipboard" button to be placed in the doc header. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - $button = $this->makeLinkButton() |
|
| 29 | - ->setHref($this->getShowClipboardUri()) |
|
| 30 | - ->setDataAttributes([ |
|
| 31 | - 'style' => $this->getClipboardService()->hasItems() ? '' : 'display: none;', |
|
| 32 | - ]) |
|
| 33 | - ->setClasses('btn-clipboard-copy-or-move') |
|
| 34 | - ->setTitle($this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:clipboard.copy_or_move')) |
|
| 35 | - ->setIcon($this->getIconFactory()->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)) |
|
| 36 | - ->render(); |
|
| 21 | + /** |
|
| 22 | + * Renders a "clipboard" button to be placed in the doc header. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + $button = $this->makeLinkButton() |
|
| 29 | + ->setHref($this->getShowClipboardUri()) |
|
| 30 | + ->setDataAttributes([ |
|
| 31 | + 'style' => $this->getClipboardService()->hasItems() ? '' : 'display: none;', |
|
| 32 | + ]) |
|
| 33 | + ->setClasses('btn-clipboard-copy-or-move') |
|
| 34 | + ->setTitle($this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:clipboard.copy_or_move')) |
|
| 35 | + ->setIcon($this->getIconFactory()->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)) |
|
| 36 | + ->render(); |
|
| 37 | 37 | |
| 38 | - // Hack! No API for adding a style upon a button |
|
| 39 | - $button = str_replace('data-style', 'style', $button); |
|
| 38 | + // Hack! No API for adding a style upon a button |
|
| 39 | + $button = str_replace('data-style', 'style', $button); |
|
| 40 | 40 | |
| 41 | - $output = sprintf('<div style="float: left; margin-right: 3px">%s</div>', $button); |
|
| 42 | - return $output; |
|
| 43 | - } |
|
| 41 | + $output = sprintf('<div style="float: left; margin-right: 3px">%s</div>', $button); |
|
| 42 | + return $output; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - protected function getShowClipboardUri() |
|
| 49 | - { |
|
| 50 | - $additionalParameters = array( |
|
| 51 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 52 | - 'controller' => 'Clipboard', |
|
| 53 | - 'action' => 'show', |
|
| 54 | - ), |
|
| 55 | - ); |
|
| 56 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 57 | - } |
|
| 45 | + /** |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + protected function getShowClipboardUri() |
|
| 49 | + { |
|
| 50 | + $additionalParameters = array( |
|
| 51 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 52 | + 'controller' => 'Clipboard', |
|
| 53 | + 'action' => 'show', |
|
| 54 | + ), |
|
| 55 | + ); |
|
| 56 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get the Vidi Module Loader. |
|
| 61 | - * |
|
| 62 | - * @return ClipboardService|object |
|
| 63 | - */ |
|
| 64 | - protected function getClipboardService() |
|
| 65 | - { |
|
| 66 | - return GeneralUtility::makeInstance(ClipboardService::class); |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * Get the Vidi Module Loader. |
|
| 61 | + * |
|
| 62 | + * @return ClipboardService|object |
|
| 63 | + */ |
|
| 64 | + protected function getClipboardService() |
|
| 65 | + { |
|
| 66 | + return GeneralUtility::makeInstance(ClipboardService::class); |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -16,25 +16,25 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Rows |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Returns rows of content as array. |
|
| 21 | - * |
|
| 22 | - * @param array $objects |
|
| 23 | - * @param array $columns |
|
| 24 | - * @return array |
|
| 25 | - * @throws \Exception |
|
| 26 | - * @throws \InvalidArgumentException |
|
| 27 | - */ |
|
| 28 | - public function render(array $objects = [], array $columns = array()) |
|
| 29 | - { |
|
| 30 | - $rows = []; |
|
| 19 | + /** |
|
| 20 | + * Returns rows of content as array. |
|
| 21 | + * |
|
| 22 | + * @param array $objects |
|
| 23 | + * @param array $columns |
|
| 24 | + * @return array |
|
| 25 | + * @throws \Exception |
|
| 26 | + * @throws \InvalidArgumentException |
|
| 27 | + */ |
|
| 28 | + public function render(array $objects = [], array $columns = array()) |
|
| 29 | + { |
|
| 30 | + $rows = []; |
|
| 31 | 31 | |
| 32 | - /** @var Row $row */ |
|
| 33 | - $row = GeneralUtility::makeInstance(Row::class, $columns); |
|
| 34 | - foreach ($objects as $index => $object) { |
|
| 35 | - $rows[] = $row->render($object, $index); |
|
| 36 | - } |
|
| 32 | + /** @var Row $row */ |
|
| 33 | + $row = GeneralUtility::makeInstance(Row::class, $columns); |
|
| 34 | + foreach ($objects as $index => $object) { |
|
| 35 | + $rows[] = $row->render($object, $index); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return $rows; |
|
| 39 | - } |
|
| 38 | + return $rows; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -26,610 +26,610 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Row extends AbstractComponentView |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $columns = []; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Registry for storing variable values and speed up the processing. |
|
| 36 | - * |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - protected $variables = []; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param array $columns |
|
| 43 | - */ |
|
| 44 | - public function __construct(array $columns = []) |
|
| 45 | - { |
|
| 46 | - $this->columns = $columns; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Render a row to be displayed in the Grid given an Content Object. |
|
| 51 | - * |
|
| 52 | - * @param Content $object |
|
| 53 | - * @param int $rowIndex |
|
| 54 | - * @return array |
|
| 55 | - * @throws \Exception |
|
| 56 | - */ |
|
| 57 | - public function render(Content $object = null, $rowIndex = 0) |
|
| 58 | - { |
|
| 59 | - // Initialize returned array |
|
| 60 | - $output = []; |
|
| 61 | - |
|
| 62 | - foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) { |
|
| 63 | - $value = ''; // default is empty at first. |
|
| 64 | - |
|
| 65 | - $this->computeVariables($object, $fieldNameAndPath); |
|
| 66 | - |
|
| 67 | - // Only compute the value if it is going to be shown in the Grid. Lost of time otherwise! |
|
| 68 | - if (in_array($fieldNameAndPath, $this->columns)) { |
|
| 69 | - // Fetch value |
|
| 70 | - if (Tca::grid()->hasRenderers($fieldNameAndPath)) { |
|
| 71 | - $value = ''; |
|
| 72 | - $renderers = Tca::grid()->getRenderers($fieldNameAndPath); |
|
| 73 | - |
|
| 74 | - // if is relation has one |
|
| 75 | - foreach ($renderers as $rendererClassName => $rendererConfiguration) { |
|
| 76 | - /** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */ |
|
| 77 | - $rendererObject = GeneralUtility::makeInstance($rendererClassName); |
|
| 78 | - $value .= $rendererObject |
|
| 79 | - ->setObject($object) |
|
| 80 | - ->setFieldName($fieldNameAndPath) |
|
| 81 | - ->setRowIndex($rowIndex) |
|
| 82 | - ->setFieldConfiguration($configuration) |
|
| 83 | - ->setGridRendererConfiguration($rendererConfiguration) |
|
| 84 | - ->render(); |
|
| 85 | - } |
|
| 86 | - } else { |
|
| 87 | - $value = $this->resolveValue($object, $fieldNameAndPath); |
|
| 88 | - $value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing. |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Possible formatting given by configuration. @see TCA['grid'] |
|
| 92 | - $value = $this->formatValue($value, $configuration); |
|
| 93 | - |
|
| 94 | - // Here, there is the chance to further "decorate" the value for inline editing, localization, ... |
|
| 95 | - if ($this->willBeEnriched()) { |
|
| 96 | - $localizedStructure = $this->initializeLocalizedStructure($value); |
|
| 97 | - |
|
| 98 | - if ($this->isEditable()) { |
|
| 99 | - $localizedStructure = $this->addEditableMarkup($localizedStructure); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($this->isLocalized()) { |
|
| 103 | - $localizedStructure = $this->addLocalizationMarkup($localizedStructure); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($this->hasIcon()) { |
|
| 107 | - $localizedStructure = $this->addSpriteIconMarkup($localizedStructure); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $value = $this->flattenStructure($localizedStructure); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // Final wrap given by configuration. @see TCA['grid'] |
|
| 114 | - $value = $this->wrapValue($value, $configuration); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $output[$this->getFieldName()] = $value; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $output['DT_RowId'] = 'row-' . $object->getUid(); |
|
| 121 | - $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid()); |
|
| 122 | - |
|
| 123 | - return $output; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Flatten the localized structure to render the final value |
|
| 128 | - * |
|
| 129 | - * @param array $localizedStructure |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - protected function flattenStructure(array $localizedStructure) |
|
| 133 | - { |
|
| 134 | - // Flatten the structure. |
|
| 135 | - $value = ''; |
|
| 136 | - foreach ($localizedStructure as $structure) { |
|
| 137 | - $value .= sprintf( |
|
| 138 | - '<div class="%s">%s</div>', |
|
| 139 | - $structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '', |
|
| 140 | - $structure['value'] |
|
| 141 | - ); |
|
| 142 | - } |
|
| 143 | - return $value; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Store some often used variable values and speed up the processing. |
|
| 148 | - * |
|
| 149 | - * @param Content $object |
|
| 150 | - * @param string $fieldNameAndPath |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - protected function computeVariables(Content $object, $fieldNameAndPath) |
|
| 154 | - { |
|
| 155 | - $this->variables = []; |
|
| 156 | - $this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
| 157 | - $this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 158 | - $this->variables['fieldNameAndPath'] = $fieldNameAndPath; |
|
| 159 | - $this->variables['object'] = $object; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Tell whether the object will be decorated / wrapped such as |
|
| 164 | - * |
|
| 165 | - * @param string $value |
|
| 166 | - * @return array |
|
| 167 | - */ |
|
| 168 | - protected function initializeLocalizedStructure($value) |
|
| 169 | - { |
|
| 170 | - $localizedStructure[] = [ |
|
| 171 | - 'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value, |
|
| 172 | - 'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED, |
|
| 173 | - 'language' => 0, |
|
| 174 | - 'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(), |
|
| 175 | - ]; |
|
| 176 | - |
|
| 177 | - if ($this->isLocalized()) { |
|
| 178 | - foreach ($this->getLanguageService()->getLanguages() as $language) { |
|
| 179 | - // Make sure the language is allowed for the current Backend User. |
|
| 180 | - if ($this->isLanguageAllowedForBackendUser($language)) { |
|
| 181 | - $resolvedObject = $this->getResolvedObject(); |
|
| 182 | - $fieldName = $this->getFieldName(); |
|
| 183 | - |
|
| 184 | - if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) { |
|
| 185 | - $localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName); |
|
| 186 | - $status = LocalizationStatus::LOCALIZED; |
|
| 187 | - |
|
| 188 | - // Replace blank value by something more meaningful for the End User. |
|
| 189 | - if (empty($localizedValue)) { |
|
| 190 | - $status = LocalizationStatus::EMPTY_VALUE; |
|
| 191 | - $localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : ''; |
|
| 192 | - } |
|
| 193 | - } else { |
|
| 194 | - $localizedValue = sprintf( |
|
| 195 | - '<a href="%s" style="color: black">%s</a>', |
|
| 196 | - $this->getLocalizedUri($language['uid']), |
|
| 197 | - $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation') |
|
| 198 | - ); |
|
| 199 | - $status = LocalizationStatus::NOT_YET_LOCALIZED; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // Feed structure. |
|
| 203 | - $localizedStructure[] = [ |
|
| 204 | - 'value' => $localizedValue, |
|
| 205 | - 'status' => $status, |
|
| 206 | - 'language' => (int)$language['uid'], |
|
| 207 | - 'languageFlag' => $language['flag'], |
|
| 208 | - ]; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return $localizedStructure; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @param array $language |
|
| 218 | - * @return bool |
|
| 219 | - */ |
|
| 220 | - protected function isLanguageAllowedForBackendUser(array $language) |
|
| 221 | - { |
|
| 222 | - return $this->getBackendUser()->checkLanguageAccess($language['uid']); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Returns a placeholder when the value is empty. |
|
| 227 | - * |
|
| 228 | - * @return string |
|
| 229 | - */ |
|
| 230 | - protected function getEmptyValuePlaceholder() |
|
| 231 | - { |
|
| 232 | - return sprintf( |
|
| 233 | - '<i>%s</i>', |
|
| 234 | - $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing') |
|
| 235 | - ); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose. |
|
| 240 | - * |
|
| 241 | - * @return bool |
|
| 242 | - */ |
|
| 243 | - protected function willBeEnriched() |
|
| 244 | - { |
|
| 245 | - $willBeEnriched = false; |
|
| 246 | - |
|
| 247 | - if ($this->fieldExists()) { |
|
| 248 | - $willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return $willBeEnriched; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Tell whether the field in the context will be prepended by an icon. |
|
| 256 | - * |
|
| 257 | - * @return bool |
|
| 258 | - */ |
|
| 259 | - protected function hasIcon() |
|
| 260 | - { |
|
| 261 | - $dataType = $this->getDataType(); |
|
| 262 | - return Tca::table($dataType)->getLabelField() === $this->getFieldName(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Tell whether the field in the context will be prepended by an icon. |
|
| 267 | - * |
|
| 268 | - * @return bool |
|
| 269 | - */ |
|
| 270 | - protected function isLocalized() |
|
| 271 | - { |
|
| 272 | - $object = $this->getObject(); |
|
| 273 | - $fieldName = $this->getFieldName(); |
|
| 274 | - $dataType = $this->getDataType(); |
|
| 275 | - $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 276 | - |
|
| 277 | - return $this->getLanguageService()->hasLanguages() |
|
| 278 | - && Tca::grid($object)->isLocalized($fieldNameAndPath) |
|
| 279 | - && Tca::table($dataType)->field($fieldName)->isLocalized(); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Add some markup to have the content editable in the Grid. |
|
| 284 | - * |
|
| 285 | - * @param array $localizedStructure |
|
| 286 | - * @return array |
|
| 287 | - */ |
|
| 288 | - protected function addEditableMarkup(array $localizedStructure) |
|
| 289 | - { |
|
| 290 | - $dataType = $this->getDataType(); |
|
| 291 | - $fieldName = $this->getFieldName(); |
|
| 292 | - |
|
| 293 | - foreach ($localizedStructure as $index => $structure) { |
|
| 294 | - if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) { |
|
| 295 | - $localizedStructure[$index]['value'] = sprintf( |
|
| 296 | - '<span class="%s" data-language="%s">%s</span>', |
|
| 297 | - Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield', |
|
| 298 | - $structure['language'], |
|
| 299 | - $structure['value'] |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - return $localizedStructure; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Add some markup related to the localization. |
|
| 308 | - * |
|
| 309 | - * @param array $localizedStructure |
|
| 310 | - * @return array |
|
| 311 | - */ |
|
| 312 | - protected function addLocalizationMarkup(array $localizedStructure) |
|
| 313 | - { |
|
| 314 | - foreach ($localizedStructure as $index => $structure) { |
|
| 315 | - $localizedStructure[$index]['value'] = sprintf( |
|
| 316 | - '<span>%s %s</span>', |
|
| 317 | - empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 318 | - $structure['value'] |
|
| 319 | - ); |
|
| 320 | - } |
|
| 321 | - return $localizedStructure; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * Add some markup related to the prepended icon. |
|
| 326 | - * |
|
| 327 | - * @param array $localizedStructure |
|
| 328 | - * @return array |
|
| 329 | - */ |
|
| 330 | - protected function addSpriteIconMarkup(array $localizedStructure) |
|
| 331 | - { |
|
| 332 | - $object = $this->getObject(); |
|
| 333 | - |
|
| 334 | - foreach ($localizedStructure as $index => $structure) { |
|
| 335 | - $recordData = []; |
|
| 336 | - |
|
| 337 | - $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime'); |
|
| 338 | - foreach ($enablesMethods as $enableMethod) { |
|
| 339 | - $methodName = 'get' . $enableMethod . 'Field'; |
|
| 340 | - |
|
| 341 | - // Fetch possible hidden filed. |
|
| 342 | - $enableField = Tca::table($object)->$methodName(); |
|
| 343 | - if ($enableField) { |
|
| 344 | - $recordData[$enableField] = $object[$enableField]; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - // Get Enable Fields of the object to render the sprite with overlays. |
|
| 349 | - $localizedStructure[$index]['value'] = sprintf( |
|
| 350 | - '%s %s', |
|
| 351 | - $this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL), |
|
| 352 | - $structure['value'] |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - return $localizedStructure; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Return whether the field given by the context is editable. |
|
| 361 | - * |
|
| 362 | - * @return boolean |
|
| 363 | - */ |
|
| 364 | - protected function isEditable() |
|
| 365 | - { |
|
| 366 | - $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 367 | - $dataType = $this->getDataType(); |
|
| 368 | - $fieldName = $this->getFieldName(); |
|
| 369 | - |
|
| 370 | - return Tca::grid()->isEditable($fieldNameAndPath) |
|
| 371 | - && Tca::table($dataType)->hasField($fieldName) |
|
| 372 | - && Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only. |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Return the appropriate URI to create the translation. |
|
| 377 | - * |
|
| 378 | - * @param int $language |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - protected function getLocalizedUri($language) |
|
| 382 | - { |
|
| 383 | - // Transmit recursive selection parameter. |
|
| 384 | - $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
| 385 | - $parameters = GeneralUtility::_GP($parameterPrefix); |
|
| 386 | - |
|
| 387 | - $additionalParameters = array( |
|
| 388 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 389 | - 'controller' => 'Content', |
|
| 390 | - 'action' => 'localize', |
|
| 391 | - 'format' => 'json', |
|
| 392 | - 'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0, |
|
| 393 | - 'fieldNameAndPath' => $this->getFieldNameAndPath(), |
|
| 394 | - 'language' => $language, |
|
| 395 | - 'matches' => array( |
|
| 396 | - 'uid' => $this->getObject()->getUid(), |
|
| 397 | - ), |
|
| 398 | - ), |
|
| 399 | - ); |
|
| 400 | - |
|
| 401 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Compute the value for the Content object according to a field name. |
|
| 406 | - * |
|
| 407 | - * @param Content $object |
|
| 408 | - * @param string $fieldNameAndPath |
|
| 409 | - * @return string |
|
| 410 | - */ |
|
| 411 | - protected function resolveValue(Content $object, $fieldNameAndPath) |
|
| 412 | - { |
|
| 413 | - // Get the first part of the field name and |
|
| 414 | - $fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath); |
|
| 415 | - |
|
| 416 | - $value = $object[$fieldName]; |
|
| 417 | - |
|
| 418 | - // Relation but contains no data. |
|
| 419 | - if (is_array($value) && empty($value)) { |
|
| 420 | - $value = ''; |
|
| 421 | - } elseif ($value instanceof Content) { |
|
| 422 | - $fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 423 | - |
|
| 424 | - // true means the field name does not contains a path. "title" vs "metadata.title" |
|
| 425 | - // Fetch the default label |
|
| 426 | - if ($fieldNameOfForeignTable === $fieldName) { |
|
| 427 | - $foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable(); |
|
| 428 | - $fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField(); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - $value = $object[$fieldName][$fieldNameOfForeignTable]; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $value; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Check whether a string contains HTML tags. |
|
| 439 | - * |
|
| 440 | - * @param string $string the content to be analyzed |
|
| 441 | - * @return boolean |
|
| 442 | - */ |
|
| 443 | - protected function hasHtml($string) |
|
| 444 | - { |
|
| 445 | - $result = false; |
|
| 446 | - |
|
| 447 | - // We compare the length of the string with html tags and without html tags. |
|
| 448 | - if (strlen($string) !== strlen(strip_tags($string))) { |
|
| 449 | - $result = true; |
|
| 450 | - } |
|
| 451 | - return $result; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Check whether a string contains potential XSS. |
|
| 456 | - * |
|
| 457 | - * @param string $string the content to be analyzed |
|
| 458 | - * @return boolean |
|
| 459 | - */ |
|
| 460 | - protected function isClean($string) |
|
| 461 | - { |
|
| 462 | - // @todo implement me! |
|
| 463 | - $result = true; |
|
| 464 | - return $result; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Process the value |
|
| 469 | - * |
|
| 470 | - * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however! |
|
| 471 | - * e.g DefaultValueGridProcessor, TextAreaGridProcessor, ... |
|
| 472 | - * |
|
| 473 | - * @param string $value |
|
| 474 | - * @param Content $object |
|
| 475 | - * @param string $fieldNameAndPath |
|
| 476 | - * @return string |
|
| 477 | - * @throws InvalidKeyInArrayException |
|
| 478 | - */ |
|
| 479 | - protected function processValue($value, Content $object, $fieldNameAndPath) |
|
| 480 | - { |
|
| 481 | - // Set default value if $field name correspond to the label of the table |
|
| 482 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 483 | - if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) { |
|
| 484 | - $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title')); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - // Sanitize the value in case of "select" or "radio button". |
|
| 488 | - if (is_scalar($value)) { |
|
| 489 | - $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType(); |
|
| 490 | - if ($fieldType !== FieldType::TEXTAREA) { |
|
| 491 | - $value = htmlspecialchars($value); |
|
| 492 | - } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) { |
|
| 493 | - $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML. |
|
| 494 | - } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) { |
|
| 495 | - $value = nl2br($value); |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - return $value; |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Possible value formatting. |
|
| 504 | - * |
|
| 505 | - * @param string $value |
|
| 506 | - * @param array $configuration |
|
| 507 | - * @return string |
|
| 508 | - * @throws \InvalidArgumentException |
|
| 509 | - */ |
|
| 510 | - protected function formatValue($value, array $configuration) |
|
| 511 | - { |
|
| 512 | - if (empty($configuration['format'])) { |
|
| 513 | - return $value; |
|
| 514 | - } |
|
| 515 | - $className = $configuration['format']; |
|
| 516 | - |
|
| 517 | - /** @var FormatterInterface $formatter */ |
|
| 518 | - $formatter = GeneralUtility::makeInstance($className); |
|
| 519 | - $value = $formatter->format($value); |
|
| 520 | - |
|
| 521 | - return $value; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Possible value wrapping. |
|
| 526 | - * |
|
| 527 | - * @param string $value |
|
| 528 | - * @param array $configuration |
|
| 529 | - * @return string |
|
| 530 | - */ |
|
| 531 | - protected function wrapValue($value, array $configuration) |
|
| 532 | - { |
|
| 533 | - if (!empty($configuration['wrap'])) { |
|
| 534 | - $parts = explode('|', $configuration['wrap']); |
|
| 535 | - $value = implode($value, $parts); |
|
| 536 | - } |
|
| 537 | - return $value; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * Tell whether the field in the context really exists. |
|
| 542 | - * |
|
| 543 | - * @return bool |
|
| 544 | - */ |
|
| 545 | - protected function fieldExists() |
|
| 546 | - { |
|
| 547 | - if ($this->variables['hasField'] === null) { |
|
| 548 | - $dataType = $this->getDataType(); |
|
| 549 | - $fieldName = $this->getFieldName(); |
|
| 550 | - $this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName); |
|
| 551 | - } |
|
| 552 | - return $this->variables['hasField']; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * @return string |
|
| 557 | - */ |
|
| 558 | - protected function getDataType() |
|
| 559 | - { |
|
| 560 | - return $this->variables['dataType']; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * @return string |
|
| 565 | - */ |
|
| 566 | - protected function getFieldName() |
|
| 567 | - { |
|
| 568 | - return $this->variables['fieldName']; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @return string |
|
| 573 | - */ |
|
| 574 | - protected function getFieldNameAndPath() |
|
| 575 | - { |
|
| 576 | - return $this->variables['fieldNameAndPath']; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * @return Content |
|
| 581 | - */ |
|
| 582 | - protected function getObject() |
|
| 583 | - { |
|
| 584 | - return $this->variables['object']; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * @return Content |
|
| 589 | - * @throws \InvalidArgumentException |
|
| 590 | - */ |
|
| 591 | - protected function getResolvedObject() |
|
| 592 | - { |
|
| 593 | - if (empty($this->variables['resolvedObject'])) { |
|
| 594 | - $object = $this->getObject(); |
|
| 595 | - $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 596 | - $this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath); |
|
| 597 | - } |
|
| 598 | - return $this->variables['resolvedObject']; |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * @return FieldPathResolver|object |
|
| 603 | - * @throws \InvalidArgumentException |
|
| 604 | - */ |
|
| 605 | - protected function getFieldPathResolver() |
|
| 606 | - { |
|
| 607 | - return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * @return ContentObjectResolver|object |
|
| 612 | - * @throws \InvalidArgumentException |
|
| 613 | - */ |
|
| 614 | - protected function getContentObjectResolver() |
|
| 615 | - { |
|
| 616 | - return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * @return \TYPO3\CMS\Core\Localization\LanguageService |
|
| 621 | - */ |
|
| 622 | - protected function getLabelService() |
|
| 623 | - { |
|
| 624 | - return $GLOBALS['LANG']; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @return LanguageService|object |
|
| 629 | - * @throws \InvalidArgumentException |
|
| 630 | - */ |
|
| 631 | - protected function getLanguageService() |
|
| 632 | - { |
|
| 633 | - return GeneralUtility::makeInstance(LanguageService::class); |
|
| 634 | - } |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $columns = []; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Registry for storing variable values and speed up the processing. |
|
| 36 | + * |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + protected $variables = []; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param array $columns |
|
| 43 | + */ |
|
| 44 | + public function __construct(array $columns = []) |
|
| 45 | + { |
|
| 46 | + $this->columns = $columns; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Render a row to be displayed in the Grid given an Content Object. |
|
| 51 | + * |
|
| 52 | + * @param Content $object |
|
| 53 | + * @param int $rowIndex |
|
| 54 | + * @return array |
|
| 55 | + * @throws \Exception |
|
| 56 | + */ |
|
| 57 | + public function render(Content $object = null, $rowIndex = 0) |
|
| 58 | + { |
|
| 59 | + // Initialize returned array |
|
| 60 | + $output = []; |
|
| 61 | + |
|
| 62 | + foreach (Tca::grid()->getFields() as $fieldNameAndPath => $configuration) { |
|
| 63 | + $value = ''; // default is empty at first. |
|
| 64 | + |
|
| 65 | + $this->computeVariables($object, $fieldNameAndPath); |
|
| 66 | + |
|
| 67 | + // Only compute the value if it is going to be shown in the Grid. Lost of time otherwise! |
|
| 68 | + if (in_array($fieldNameAndPath, $this->columns)) { |
|
| 69 | + // Fetch value |
|
| 70 | + if (Tca::grid()->hasRenderers($fieldNameAndPath)) { |
|
| 71 | + $value = ''; |
|
| 72 | + $renderers = Tca::grid()->getRenderers($fieldNameAndPath); |
|
| 73 | + |
|
| 74 | + // if is relation has one |
|
| 75 | + foreach ($renderers as $rendererClassName => $rendererConfiguration) { |
|
| 76 | + /** @var $rendererObject \Fab\Vidi\Grid\ColumnRendererInterface */ |
|
| 77 | + $rendererObject = GeneralUtility::makeInstance($rendererClassName); |
|
| 78 | + $value .= $rendererObject |
|
| 79 | + ->setObject($object) |
|
| 80 | + ->setFieldName($fieldNameAndPath) |
|
| 81 | + ->setRowIndex($rowIndex) |
|
| 82 | + ->setFieldConfiguration($configuration) |
|
| 83 | + ->setGridRendererConfiguration($rendererConfiguration) |
|
| 84 | + ->render(); |
|
| 85 | + } |
|
| 86 | + } else { |
|
| 87 | + $value = $this->resolveValue($object, $fieldNameAndPath); |
|
| 88 | + $value = $this->processValue($value, $object, $fieldNameAndPath); // post resolve processing. |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Possible formatting given by configuration. @see TCA['grid'] |
|
| 92 | + $value = $this->formatValue($value, $configuration); |
|
| 93 | + |
|
| 94 | + // Here, there is the chance to further "decorate" the value for inline editing, localization, ... |
|
| 95 | + if ($this->willBeEnriched()) { |
|
| 96 | + $localizedStructure = $this->initializeLocalizedStructure($value); |
|
| 97 | + |
|
| 98 | + if ($this->isEditable()) { |
|
| 99 | + $localizedStructure = $this->addEditableMarkup($localizedStructure); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($this->isLocalized()) { |
|
| 103 | + $localizedStructure = $this->addLocalizationMarkup($localizedStructure); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($this->hasIcon()) { |
|
| 107 | + $localizedStructure = $this->addSpriteIconMarkup($localizedStructure); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $value = $this->flattenStructure($localizedStructure); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // Final wrap given by configuration. @see TCA['grid'] |
|
| 114 | + $value = $this->wrapValue($value, $configuration); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $output[$this->getFieldName()] = $value; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $output['DT_RowId'] = 'row-' . $object->getUid(); |
|
| 121 | + $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid()); |
|
| 122 | + |
|
| 123 | + return $output; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Flatten the localized structure to render the final value |
|
| 128 | + * |
|
| 129 | + * @param array $localizedStructure |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + protected function flattenStructure(array $localizedStructure) |
|
| 133 | + { |
|
| 134 | + // Flatten the structure. |
|
| 135 | + $value = ''; |
|
| 136 | + foreach ($localizedStructure as $structure) { |
|
| 137 | + $value .= sprintf( |
|
| 138 | + '<div class="%s">%s</div>', |
|
| 139 | + $structure['status'] !== LocalizationStatus::LOCALIZED ? 'invisible' : '', |
|
| 140 | + $structure['value'] |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | + return $value; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Store some often used variable values and speed up the processing. |
|
| 148 | + * |
|
| 149 | + * @param Content $object |
|
| 150 | + * @param string $fieldNameAndPath |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + protected function computeVariables(Content $object, $fieldNameAndPath) |
|
| 154 | + { |
|
| 155 | + $this->variables = []; |
|
| 156 | + $this->variables['dataType'] = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
| 157 | + $this->variables['fieldName'] = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 158 | + $this->variables['fieldNameAndPath'] = $fieldNameAndPath; |
|
| 159 | + $this->variables['object'] = $object; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Tell whether the object will be decorated / wrapped such as |
|
| 164 | + * |
|
| 165 | + * @param string $value |
|
| 166 | + * @return array |
|
| 167 | + */ |
|
| 168 | + protected function initializeLocalizedStructure($value) |
|
| 169 | + { |
|
| 170 | + $localizedStructure[] = [ |
|
| 171 | + 'value' => empty($value) && $this->isEditable() ? $this->getEmptyValuePlaceholder() : $value, |
|
| 172 | + 'status' => empty($value) ? LocalizationStatus::EMPTY_VALUE : LocalizationStatus::LOCALIZED, |
|
| 173 | + 'language' => 0, |
|
| 174 | + 'languageFlag' => $defaultLanguage = $this->getLanguageService()->getDefaultFlag(), |
|
| 175 | + ]; |
|
| 176 | + |
|
| 177 | + if ($this->isLocalized()) { |
|
| 178 | + foreach ($this->getLanguageService()->getLanguages() as $language) { |
|
| 179 | + // Make sure the language is allowed for the current Backend User. |
|
| 180 | + if ($this->isLanguageAllowedForBackendUser($language)) { |
|
| 181 | + $resolvedObject = $this->getResolvedObject(); |
|
| 182 | + $fieldName = $this->getFieldName(); |
|
| 183 | + |
|
| 184 | + if ($this->getLanguageService()->hasLocalization($resolvedObject, $language['uid'])) { |
|
| 185 | + $localizedValue = $this->getLanguageService()->getLocalizedFieldName($resolvedObject, $language['uid'], $fieldName); |
|
| 186 | + $status = LocalizationStatus::LOCALIZED; |
|
| 187 | + |
|
| 188 | + // Replace blank value by something more meaningful for the End User. |
|
| 189 | + if (empty($localizedValue)) { |
|
| 190 | + $status = LocalizationStatus::EMPTY_VALUE; |
|
| 191 | + $localizedValue = $this->isEditable() ? $this->getEmptyValuePlaceholder() : ''; |
|
| 192 | + } |
|
| 193 | + } else { |
|
| 194 | + $localizedValue = sprintf( |
|
| 195 | + '<a href="%s" style="color: black">%s</a>', |
|
| 196 | + $this->getLocalizedUri($language['uid']), |
|
| 197 | + $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:create_translation') |
|
| 198 | + ); |
|
| 199 | + $status = LocalizationStatus::NOT_YET_LOCALIZED; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // Feed structure. |
|
| 203 | + $localizedStructure[] = [ |
|
| 204 | + 'value' => $localizedValue, |
|
| 205 | + 'status' => $status, |
|
| 206 | + 'language' => (int)$language['uid'], |
|
| 207 | + 'languageFlag' => $language['flag'], |
|
| 208 | + ]; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return $localizedStructure; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @param array $language |
|
| 218 | + * @return bool |
|
| 219 | + */ |
|
| 220 | + protected function isLanguageAllowedForBackendUser(array $language) |
|
| 221 | + { |
|
| 222 | + return $this->getBackendUser()->checkLanguageAccess($language['uid']); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Returns a placeholder when the value is empty. |
|
| 227 | + * |
|
| 228 | + * @return string |
|
| 229 | + */ |
|
| 230 | + protected function getEmptyValuePlaceholder() |
|
| 231 | + { |
|
| 232 | + return sprintf( |
|
| 233 | + '<i>%s</i>', |
|
| 234 | + $this->getLabelService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:start_editing') |
|
| 235 | + ); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Tell whether the object will be decorated (or wrapped) for inline editing, localization purpose. |
|
| 240 | + * |
|
| 241 | + * @return bool |
|
| 242 | + */ |
|
| 243 | + protected function willBeEnriched() |
|
| 244 | + { |
|
| 245 | + $willBeEnriched = false; |
|
| 246 | + |
|
| 247 | + if ($this->fieldExists()) { |
|
| 248 | + $willBeEnriched = $this->isEditable() || $this->hasIcon() || $this->isLocalized(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + return $willBeEnriched; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Tell whether the field in the context will be prepended by an icon. |
|
| 256 | + * |
|
| 257 | + * @return bool |
|
| 258 | + */ |
|
| 259 | + protected function hasIcon() |
|
| 260 | + { |
|
| 261 | + $dataType = $this->getDataType(); |
|
| 262 | + return Tca::table($dataType)->getLabelField() === $this->getFieldName(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Tell whether the field in the context will be prepended by an icon. |
|
| 267 | + * |
|
| 268 | + * @return bool |
|
| 269 | + */ |
|
| 270 | + protected function isLocalized() |
|
| 271 | + { |
|
| 272 | + $object = $this->getObject(); |
|
| 273 | + $fieldName = $this->getFieldName(); |
|
| 274 | + $dataType = $this->getDataType(); |
|
| 275 | + $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 276 | + |
|
| 277 | + return $this->getLanguageService()->hasLanguages() |
|
| 278 | + && Tca::grid($object)->isLocalized($fieldNameAndPath) |
|
| 279 | + && Tca::table($dataType)->field($fieldName)->isLocalized(); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Add some markup to have the content editable in the Grid. |
|
| 284 | + * |
|
| 285 | + * @param array $localizedStructure |
|
| 286 | + * @return array |
|
| 287 | + */ |
|
| 288 | + protected function addEditableMarkup(array $localizedStructure) |
|
| 289 | + { |
|
| 290 | + $dataType = $this->getDataType(); |
|
| 291 | + $fieldName = $this->getFieldName(); |
|
| 292 | + |
|
| 293 | + foreach ($localizedStructure as $index => $structure) { |
|
| 294 | + if ($structure['status'] !== LocalizationStatus::NOT_YET_LOCALIZED) { |
|
| 295 | + $localizedStructure[$index]['value'] = sprintf( |
|
| 296 | + '<span class="%s" data-language="%s">%s</span>', |
|
| 297 | + Tca::table($dataType)->field($fieldName)->isTextArea() ? 'editable-textarea' : 'editable-textfield', |
|
| 298 | + $structure['language'], |
|
| 299 | + $structure['value'] |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + return $localizedStructure; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Add some markup related to the localization. |
|
| 308 | + * |
|
| 309 | + * @param array $localizedStructure |
|
| 310 | + * @return array |
|
| 311 | + */ |
|
| 312 | + protected function addLocalizationMarkup(array $localizedStructure) |
|
| 313 | + { |
|
| 314 | + foreach ($localizedStructure as $index => $structure) { |
|
| 315 | + $localizedStructure[$index]['value'] = sprintf( |
|
| 316 | + '<span>%s %s</span>', |
|
| 317 | + empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 318 | + $structure['value'] |
|
| 319 | + ); |
|
| 320 | + } |
|
| 321 | + return $localizedStructure; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * Add some markup related to the prepended icon. |
|
| 326 | + * |
|
| 327 | + * @param array $localizedStructure |
|
| 328 | + * @return array |
|
| 329 | + */ |
|
| 330 | + protected function addSpriteIconMarkup(array $localizedStructure) |
|
| 331 | + { |
|
| 332 | + $object = $this->getObject(); |
|
| 333 | + |
|
| 334 | + foreach ($localizedStructure as $index => $structure) { |
|
| 335 | + $recordData = []; |
|
| 336 | + |
|
| 337 | + $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime'); |
|
| 338 | + foreach ($enablesMethods as $enableMethod) { |
|
| 339 | + $methodName = 'get' . $enableMethod . 'Field'; |
|
| 340 | + |
|
| 341 | + // Fetch possible hidden filed. |
|
| 342 | + $enableField = Tca::table($object)->$methodName(); |
|
| 343 | + if ($enableField) { |
|
| 344 | + $recordData[$enableField] = $object[$enableField]; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + // Get Enable Fields of the object to render the sprite with overlays. |
|
| 349 | + $localizedStructure[$index]['value'] = sprintf( |
|
| 350 | + '%s %s', |
|
| 351 | + $this->getIconFactory()->getIconForRecord($object->getDataType(), $recordData, Icon::SIZE_SMALL), |
|
| 352 | + $structure['value'] |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + return $localizedStructure; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Return whether the field given by the context is editable. |
|
| 361 | + * |
|
| 362 | + * @return boolean |
|
| 363 | + */ |
|
| 364 | + protected function isEditable() |
|
| 365 | + { |
|
| 366 | + $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 367 | + $dataType = $this->getDataType(); |
|
| 368 | + $fieldName = $this->getFieldName(); |
|
| 369 | + |
|
| 370 | + return Tca::grid()->isEditable($fieldNameAndPath) |
|
| 371 | + && Tca::table($dataType)->hasField($fieldName) |
|
| 372 | + && Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only. |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Return the appropriate URI to create the translation. |
|
| 377 | + * |
|
| 378 | + * @param int $language |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + protected function getLocalizedUri($language) |
|
| 382 | + { |
|
| 383 | + // Transmit recursive selection parameter. |
|
| 384 | + $parameterPrefix = $this->getModuleLoader()->getParameterPrefix(); |
|
| 385 | + $parameters = GeneralUtility::_GP($parameterPrefix); |
|
| 386 | + |
|
| 387 | + $additionalParameters = array( |
|
| 388 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 389 | + 'controller' => 'Content', |
|
| 390 | + 'action' => 'localize', |
|
| 391 | + 'format' => 'json', |
|
| 392 | + 'hasRecursiveSelection' => isset($parameters['hasRecursiveSelection']) ? (int)$parameters['hasRecursiveSelection'] : 0, |
|
| 393 | + 'fieldNameAndPath' => $this->getFieldNameAndPath(), |
|
| 394 | + 'language' => $language, |
|
| 395 | + 'matches' => array( |
|
| 396 | + 'uid' => $this->getObject()->getUid(), |
|
| 397 | + ), |
|
| 398 | + ), |
|
| 399 | + ); |
|
| 400 | + |
|
| 401 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Compute the value for the Content object according to a field name. |
|
| 406 | + * |
|
| 407 | + * @param Content $object |
|
| 408 | + * @param string $fieldNameAndPath |
|
| 409 | + * @return string |
|
| 410 | + */ |
|
| 411 | + protected function resolveValue(Content $object, $fieldNameAndPath) |
|
| 412 | + { |
|
| 413 | + // Get the first part of the field name and |
|
| 414 | + $fieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath); |
|
| 415 | + |
|
| 416 | + $value = $object[$fieldName]; |
|
| 417 | + |
|
| 418 | + // Relation but contains no data. |
|
| 419 | + if (is_array($value) && empty($value)) { |
|
| 420 | + $value = ''; |
|
| 421 | + } elseif ($value instanceof Content) { |
|
| 422 | + $fieldNameOfForeignTable = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 423 | + |
|
| 424 | + // true means the field name does not contains a path. "title" vs "metadata.title" |
|
| 425 | + // Fetch the default label |
|
| 426 | + if ($fieldNameOfForeignTable === $fieldName) { |
|
| 427 | + $foreignTable = Tca::table($object->getDataType())->field($fieldName)->getForeignTable(); |
|
| 428 | + $fieldNameOfForeignTable = Tca::table($foreignTable)->getLabelField(); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + $value = $object[$fieldName][$fieldNameOfForeignTable]; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $value; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Check whether a string contains HTML tags. |
|
| 439 | + * |
|
| 440 | + * @param string $string the content to be analyzed |
|
| 441 | + * @return boolean |
|
| 442 | + */ |
|
| 443 | + protected function hasHtml($string) |
|
| 444 | + { |
|
| 445 | + $result = false; |
|
| 446 | + |
|
| 447 | + // We compare the length of the string with html tags and without html tags. |
|
| 448 | + if (strlen($string) !== strlen(strip_tags($string))) { |
|
| 449 | + $result = true; |
|
| 450 | + } |
|
| 451 | + return $result; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Check whether a string contains potential XSS. |
|
| 456 | + * |
|
| 457 | + * @param string $string the content to be analyzed |
|
| 458 | + * @return boolean |
|
| 459 | + */ |
|
| 460 | + protected function isClean($string) |
|
| 461 | + { |
|
| 462 | + // @todo implement me! |
|
| 463 | + $result = true; |
|
| 464 | + return $result; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Process the value |
|
| 469 | + * |
|
| 470 | + * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however! |
|
| 471 | + * e.g DefaultValueGridProcessor, TextAreaGridProcessor, ... |
|
| 472 | + * |
|
| 473 | + * @param string $value |
|
| 474 | + * @param Content $object |
|
| 475 | + * @param string $fieldNameAndPath |
|
| 476 | + * @return string |
|
| 477 | + * @throws InvalidKeyInArrayException |
|
| 478 | + */ |
|
| 479 | + protected function processValue($value, Content $object, $fieldNameAndPath) |
|
| 480 | + { |
|
| 481 | + // Set default value if $field name correspond to the label of the table |
|
| 482 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 483 | + if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) { |
|
| 484 | + $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title')); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + // Sanitize the value in case of "select" or "radio button". |
|
| 488 | + if (is_scalar($value)) { |
|
| 489 | + $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType(); |
|
| 490 | + if ($fieldType !== FieldType::TEXTAREA) { |
|
| 491 | + $value = htmlspecialchars($value); |
|
| 492 | + } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) { |
|
| 493 | + $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML. |
|
| 494 | + } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) { |
|
| 495 | + $value = nl2br($value); |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + return $value; |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Possible value formatting. |
|
| 504 | + * |
|
| 505 | + * @param string $value |
|
| 506 | + * @param array $configuration |
|
| 507 | + * @return string |
|
| 508 | + * @throws \InvalidArgumentException |
|
| 509 | + */ |
|
| 510 | + protected function formatValue($value, array $configuration) |
|
| 511 | + { |
|
| 512 | + if (empty($configuration['format'])) { |
|
| 513 | + return $value; |
|
| 514 | + } |
|
| 515 | + $className = $configuration['format']; |
|
| 516 | + |
|
| 517 | + /** @var FormatterInterface $formatter */ |
|
| 518 | + $formatter = GeneralUtility::makeInstance($className); |
|
| 519 | + $value = $formatter->format($value); |
|
| 520 | + |
|
| 521 | + return $value; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Possible value wrapping. |
|
| 526 | + * |
|
| 527 | + * @param string $value |
|
| 528 | + * @param array $configuration |
|
| 529 | + * @return string |
|
| 530 | + */ |
|
| 531 | + protected function wrapValue($value, array $configuration) |
|
| 532 | + { |
|
| 533 | + if (!empty($configuration['wrap'])) { |
|
| 534 | + $parts = explode('|', $configuration['wrap']); |
|
| 535 | + $value = implode($value, $parts); |
|
| 536 | + } |
|
| 537 | + return $value; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * Tell whether the field in the context really exists. |
|
| 542 | + * |
|
| 543 | + * @return bool |
|
| 544 | + */ |
|
| 545 | + protected function fieldExists() |
|
| 546 | + { |
|
| 547 | + if ($this->variables['hasField'] === null) { |
|
| 548 | + $dataType = $this->getDataType(); |
|
| 549 | + $fieldName = $this->getFieldName(); |
|
| 550 | + $this->variables['hasField'] = Tca::table($dataType)->hasField($fieldName); |
|
| 551 | + } |
|
| 552 | + return $this->variables['hasField']; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * @return string |
|
| 557 | + */ |
|
| 558 | + protected function getDataType() |
|
| 559 | + { |
|
| 560 | + return $this->variables['dataType']; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * @return string |
|
| 565 | + */ |
|
| 566 | + protected function getFieldName() |
|
| 567 | + { |
|
| 568 | + return $this->variables['fieldName']; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @return string |
|
| 573 | + */ |
|
| 574 | + protected function getFieldNameAndPath() |
|
| 575 | + { |
|
| 576 | + return $this->variables['fieldNameAndPath']; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * @return Content |
|
| 581 | + */ |
|
| 582 | + protected function getObject() |
|
| 583 | + { |
|
| 584 | + return $this->variables['object']; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * @return Content |
|
| 589 | + * @throws \InvalidArgumentException |
|
| 590 | + */ |
|
| 591 | + protected function getResolvedObject() |
|
| 592 | + { |
|
| 593 | + if (empty($this->variables['resolvedObject'])) { |
|
| 594 | + $object = $this->getObject(); |
|
| 595 | + $fieldNameAndPath = $this->getFieldNameAndPath(); |
|
| 596 | + $this->variables['resolvedObject'] = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath); |
|
| 597 | + } |
|
| 598 | + return $this->variables['resolvedObject']; |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * @return FieldPathResolver|object |
|
| 603 | + * @throws \InvalidArgumentException |
|
| 604 | + */ |
|
| 605 | + protected function getFieldPathResolver() |
|
| 606 | + { |
|
| 607 | + return GeneralUtility::makeInstance(FieldPathResolver::class); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * @return ContentObjectResolver|object |
|
| 612 | + * @throws \InvalidArgumentException |
|
| 613 | + */ |
|
| 614 | + protected function getContentObjectResolver() |
|
| 615 | + { |
|
| 616 | + return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * @return \TYPO3\CMS\Core\Localization\LanguageService |
|
| 621 | + */ |
|
| 622 | + protected function getLabelService() |
|
| 623 | + { |
|
| 624 | + return $GLOBALS['LANG']; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @return LanguageService|object |
|
| 629 | + * @throws \InvalidArgumentException |
|
| 630 | + */ |
|
| 631 | + protected function getLanguageService() |
|
| 632 | + { |
|
| 633 | + return GeneralUtility::makeInstance(LanguageService::class); |
|
| 634 | + } |
|
| 635 | 635 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $output[$this->getFieldName()] = $value; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $output['DT_RowId'] = 'row-' . $object->getUid(); |
|
| 120 | + $output['DT_RowId'] = 'row-'.$object->getUid(); |
|
| 121 | 121 | $output['DT_RowClass'] = sprintf('%s_%s', $object->getDataType(), $object->getUid()); |
| 122 | 122 | |
| 123 | 123 | return $output; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | foreach ($localizedStructure as $index => $structure) { |
| 315 | 315 | $localizedStructure[$index]['value'] = sprintf( |
| 316 | 316 | '<span>%s %s</span>', |
| 317 | - empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-' . $structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 317 | + empty($structure['languageFlag']) ? '' : $this->getIconFactory()->getIcon('flags-'.$structure['languageFlag'], Icon::SIZE_SMALL), |
|
| 318 | 318 | $structure['value'] |
| 319 | 319 | ); |
| 320 | 320 | } |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | $enablesMethods = array('Hidden', 'Deleted', 'StartTime', 'EndTime'); |
| 338 | 338 | foreach ($enablesMethods as $enableMethod) { |
| 339 | - $methodName = 'get' . $enableMethod . 'Field'; |
|
| 339 | + $methodName = 'get'.$enableMethod.'Field'; |
|
| 340 | 340 | |
| 341 | 341 | // Fetch possible hidden filed. |
| 342 | 342 | $enableField = Tca::table($object)->$methodName(); |
@@ -17,35 +17,35 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class MassDeleteMenuItem extends AbstractComponentView |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Renders a "mass delete" menu item to be placed in the grid menu. |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - * @throws \InvalidArgumentException |
|
| 25 | - */ |
|
| 26 | - public function render() |
|
| 27 | - { |
|
| 28 | - return sprintf( |
|
| 29 | - '<li><a href="%s" class="dropdown-item mass-delete" >%s %s</a>', |
|
| 30 | - $this->getMassDeleteUri(), |
|
| 31 | - $this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL), |
|
| 32 | - $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:delete') |
|
| 33 | - ); |
|
| 34 | - } |
|
| 20 | + /** |
|
| 21 | + * Renders a "mass delete" menu item to be placed in the grid menu. |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + * @throws \InvalidArgumentException |
|
| 25 | + */ |
|
| 26 | + public function render() |
|
| 27 | + { |
|
| 28 | + return sprintf( |
|
| 29 | + '<li><a href="%s" class="dropdown-item mass-delete" >%s %s</a>', |
|
| 30 | + $this->getMassDeleteUri(), |
|
| 31 | + $this->getIconFactory()->getIcon('actions-edit-delete', Icon::SIZE_SMALL), |
|
| 32 | + $this->getLanguageService()->sL('LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:delete') |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return string |
|
| 38 | - * @throws \InvalidArgumentException |
|
| 39 | - */ |
|
| 40 | - protected function getMassDeleteUri() |
|
| 41 | - { |
|
| 42 | - $additionalParameters = array( |
|
| 43 | - $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 44 | - 'controller' => 'Content', |
|
| 45 | - 'action' => 'delete', |
|
| 46 | - 'format' => 'json', |
|
| 47 | - ), |
|
| 48 | - ); |
|
| 49 | - return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 50 | - } |
|
| 36 | + /** |
|
| 37 | + * @return string |
|
| 38 | + * @throws \InvalidArgumentException |
|
| 39 | + */ |
|
| 40 | + protected function getMassDeleteUri() |
|
| 41 | + { |
|
| 42 | + $additionalParameters = array( |
|
| 43 | + $this->getModuleLoader()->getParameterPrefix() => array( |
|
| 44 | + 'controller' => 'Content', |
|
| 45 | + 'action' => 'delete', |
|
| 46 | + 'format' => 'json', |
|
| 47 | + ), |
|
| 48 | + ); |
|
| 49 | + return $this->getModuleLoader()->getModuleUrl($additionalParameters); |
|
| 50 | + } |
|
| 51 | 51 | } |