Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
[FEATURE] Display the selected default folder/image in the plugin ove…
Browse files Browse the repository at this point in the history
…rview
  • Loading branch information
vertexvaar committed Feb 13, 2019
1 parent 11c29e7 commit 6174eea
Showing 1 changed file with 92 additions and 4 deletions.
96 changes: 92 additions & 4 deletions Classes/Hooks/PluginInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException;
use TYPO3\CMS\Core\LinkHandling\Exception\UnknownUrnException;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Service\FlexFormService;

Expand All @@ -27,16 +32,25 @@
class PluginInformation
{
/**
* TODO: replace with TYPO3\CMS\Core\Service\FlexFormService when dropping TYPO3 v8
*
* This class has an alias in TYPO3 v9
* @var FlexFormService
*/
protected $flexFormService = null;

/**
* @var LinkService
*/
protected $linkService = null;

/**
* PluginInformation constructor.
*/
public function __construct()
{
$this->flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
$this->linkService = GeneralUtility::makeInstance(LinkService::class);
}

/**
Expand All @@ -50,10 +64,84 @@ public function build(array $contentElement, PageLayoutView $pageLayoutView)
$row = $contentElement['row'];
$label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
$config = $this->flexFormService->convertFlexFormContentToArray($row['pi_flexform']);
$pluginType = $this->getSelectedPluginType($config);

$defaultSource = '>none<';
$defaultStorage = '>none<';
switch ($pluginType) {
case 'show':
$this->resolveFileInformation($config, $defaultSource, $defaultStorage);
break;
case 'list':
$this->resolveFolderInformation($config, $defaultSource, $defaultStorage);
break;
case 'category':
$this->resolveFolderInformation($config, $defaultSource, $defaultStorage);
break;
default:
break;
}
$pluginType = ucfirst($pluginType);

$pluginDescription = <<<HTML
<strong>$label</strong> - $pluginType<br/>
Default source: $defaultSource<br/>
File storage: $defaultStorage
HTML;
return $pageLayoutView->linkEditContent($pluginDescription, $row);
}

/**
* @param array $config
* @return string
*/
protected function getSelectedPluginType(array $config)
{
preg_match('~Gallery\->(?P<type>\w+);~', $config['switchableControllerActions'], $matches);
return $pageLayoutView->linkEditContent(
'<strong>' . $label . '</strong>' . ' - ' . ucfirst($matches['type']),
$row
);
return $matches['type'];
}

/**
* @param $config
* @param string $defaultSource
* @param string $defaultStorage
*/
protected function resolveFolderInformation(array $config, &$defaultSource, &$defaultStorage)
{
if (isset($config['settings']['default']['folder'])) {
$folderIdentifier = $config['settings']['default']['folder'];
/** @var Folder $folder */
try {
$folder = $this->linkService->resolveByStringRepresentation($folderIdentifier)['folder'];
} catch (UnknownLinkHandlerException $e) {
return;
} catch (UnknownUrnException $e) {
return;
}
$defaultSource = $folder->getReadablePath();
$defaultStorage = $folder->getStorage()->getName();
}
}

/**
* @param $config
* @param string $defaultSource
* @param string $defaultStorage
*/
protected function resolveFileInformation(array $config, &$defaultSource, &$defaultStorage)
{
if (isset($config['settings']['default']['image'])) {
$imageIdentifier = $config['settings']['default']['image'];
/** @var File $image */
try {
$image = $this->linkService->resolveByStringRepresentation($imageIdentifier)['file'];
} catch (UnknownLinkHandlerException $e) {
return;
} catch (UnknownUrnException $e) {
return;
}
$defaultSource = $image->getIdentifier();
$defaultStorage = $image->getStorage()->getName();
}
}
}

0 comments on commit 6174eea

Please sign in to comment.