Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions Classes/View/Button/HideButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php
namespace Fab\Media\View\Button;

/*
* This file is part of the Fab/Media project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Fab\Vidi\View\AbstractComponentView;
use Fab\Vidi\Domain\Model\Content;

/**
* View which renders a "hide" button to be placed in the grid.
*/
class HideButton extends AbstractComponentView
{

/**
* Renders a "hide" button to be placed in the grid.
*
* @param Content $object
* @return string
* @throws \RuntimeException
* @throws \InvalidArgumentException
*/
public function render(Content $object = null)
{
$button = '';

if (isset($object->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');
}

}
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 21 additions & 8 deletions ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down