diff --git a/Classes/View/Button/HideButton.php b/Classes/View/Button/HideButton.php new file mode 100644 index 00000000..8a028153 --- /dev/null +++ b/Classes/View/Button/HideButton.php @@ -0,0 +1,105 @@ +metadata) && isset($object->metadata->visible) && (bool)$object->metadata->visible === false) { + $buttonIcon = 'actions-edit-unhide'; + $label = 'unHide'; + } else { + $buttonIcon = 'actions-edit-hide'; + $label = 'hide'; + } + $file = $this->getFileConverter()->convert($object); + + // Only display the hide icon if the file has no reference? + if ($this->getFileReferenceService()->countTotalReferences($object->getUid()) === 0 && $file->checkActionPermission('write')) { + + $button = $this->makeLinkButton() + ->setHref($this->getHideUri($object)) + ->setDataAttributes([ + 'uid' => $object->getUid(), + 'toggle' => 'tooltip', + 'label' => $file->getProperty('title'), + ]) + ->setClasses('btn-visibility-toggle') + ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_mod_web_list.xlf:' . $label)) + ->setIcon($this->getIconFactory()->getIcon($buttonIcon, Icon::SIZE_SMALL)) + ->render(); + } + + return $button; + } + + /** + * @param Content $object + * @return string + * @throws \InvalidArgumentException + */ + protected function getHideUri(Content $object) + { + $newVisibility = (isset($object->metadata) && isset($object->metadata->visible)) ? (int)!$object->metadata->visible : 0; + $additionalParameters = [ + $this->getModuleLoader()->getParameterPrefix() => [ + 'controller' => 'Content', + 'action' => 'update', + 'format' => 'json', + 'fieldNameAndPath' => 'metadata.visible', + 'content' => [ + 'visible' => $newVisibility + ], + 'matches' => [ + 'uid' => $object->getUid(), + ], + ], + ]; + return $this->getModuleLoader()->getModuleUrl($additionalParameters); + } + + /** + * @return \Fab\Media\Resource\FileReferenceService + * @throws \InvalidArgumentException + */ + protected function getFileReferenceService() + { + return GeneralUtility::makeInstance('Fab\Media\Resource\FileReferenceService'); + } + + /** + * @return \Fab\Media\TypeConverter\ContentToFileConverter + * @throws \InvalidArgumentException + */ + protected function getFileConverter() + { + return GeneralUtility::makeInstance('Fab\Media\TypeConverter\ContentToFileConverter'); + } + +} diff --git a/ext_conf_template.txt b/ext_conf_template.txt index d22a1190..22c04080 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -13,6 +13,9 @@ has_media_file_picker = 0 # cat=basic//; type=boolean; label= Hide default file list : If checked, the default file list is hidden from the Backend as everything is handled by the Media module. Reload the Backend after enabling this option. hide_file_list = 0 +# cat=basic//; type=boolean; label= Display hide button : If checked, the a hide button is added to media module, that shows/hides sys_metadata entry of current item (only if filemetadata is loaded +show_hide_button_in_media = 0 + ###################### Image preset ###################### # cat=image preset//2; type=string; label= Maximum size of thumbnail image: Define the max width and height of a thumbnail. This setting is currently used for thumbnails in the Grid in the BE. diff --git a/ext_tables.php b/ext_tables.php index 33138f87..68429357 100644 --- a/ext_tables.php +++ b/ext_tables.php @@ -72,6 +72,26 @@ $defaultMainModule = (bool)$configuration['has_folder_tree']['value'] ? 'file' : 'content'; + $configuration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['media']); + + $buttonArray = [ + \Fab\Media\View\Button\LinkCreatorButton::class, + \Fab\Media\View\Button\ImageEditorButton::class, + \Fab\Media\View\Button\FilePickerButton::class, + \Fab\Media\View\Button\EditButton::class, + \Fab\Media\View\Button\DownloadButton::class, + \Fab\Media\View\Button\DeleteButton::class + ]; + + if ($configuration['show_hide_button_in_media'] == 1 + && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('filemetadata') + ) { + $buttonArray[] = \Fab\Media\View\Button\HideButton::class; + + // update width of button column to fit new hide button + $GLOBALS['TCA']['sys_file']['grid']['columns']['__buttons']['width'] = '120px'; + } + /** @var \Fab\Vidi\Module\ModuleLoader $moduleLoader */ $moduleLoader = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( \Fab\Vidi\Module\ModuleLoader::class, @@ -106,14 +126,7 @@ \Fab\Media\View\Plugin\ImageEditorPlugin::class, \Fab\Media\View\Plugin\FilePickerPlugin::class, ]) - ->setGridButtonsComponents([ - \Fab\Media\View\Button\LinkCreatorButton::class, - \Fab\Media\View\Button\ImageEditorButton::class, - \Fab\Media\View\Button\FilePickerButton::class, - \Fab\Media\View\Button\EditButton::class, - \Fab\Media\View\Button\DownloadButton::class, - \Fab\Media\View\Button\DeleteButton::class, - ]) + ->setGridButtonsComponents($buttonArray) ->setMenuMassActionComponents([ \Fab\Vidi\View\MenuItem\ExportXlsMenuItem::class, \Fab\Vidi\View\MenuItem\ExportXmlMenuItem::class,