Skip to content

Commit

Permalink
[TASK] Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
josefglatz committed Mar 14, 2018
0 parents commit 343e84e
Show file tree
Hide file tree
Showing 14 changed files with 1,142 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.todos.json
/.idea
.DS_Store
104 changes: 104 additions & 0 deletions Classes/Controller/IconcheckController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php declare(strict_types = 1);

namespace JosefGlatz\Iconcheck\Controller;

use JosefGlatz\Iconcheck\Domain\Model\Dto\ExtensionConfiguration;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;


class IconcheckController extends ActionController
{

/**
* Backend Template Container.
* Takes care of outer "docheader" and other stuff this module is embedded in.
*
* @var string
*/
protected $defaultViewObjectName = BackendTemplateView::class;

/**
* BackendTemplateContainer
*
* @var BackendTemplateView
*/
protected $view;

/**
* @var string
*/
protected $languageFilePrefix = 'LLL:EXT:iconcheck/Resources/Private/Language/locallang.xlf:';

/**
* Method is called before each action and sets up the doc header.
*
* @param ViewInterface $view
*/
protected function initializeView(ViewInterface $view)
{
parent::initializeView($view);

// Early return for actions without valid view like tcaCreateAction or tcaDeleteAction
if (!($this->view instanceof BackendTemplateView)) {
return;
}

$this->view->assign('currentAction', $this->request->getControllerActionName());

// Shortcut button
$buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
$getVars = $this->request->getArguments();
$extensionName = $this->request->getControllerExtensionName();
$moduleName = $this->request->getPluginName();
if (\count($getVars) === 0) {
$modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
$getVars = array('id', 'M', $modulePrefix);
}
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName($moduleName)
->setGetVariables($getVars);
$buttonBar->addButton($shortcutButton);
}

/**
* Overview
*
* @throws \InvalidArgumentException
*/
public function indexAction()
{
// Instantiate TYPO3 icon registry
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
// Retrieve all registered icons from registry
$iconsAll = $iconRegistry->getAllRegisteredIconIdentifiers();

// Load extConf
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class);

// Show all icon identifiers alphabetically if enabled
if ($extConf->isListAllIconIdentifiers()) {
$listAll = $iconsAll;
natcasesort($listAll);
$this->view->assign('allIcons', $listAll);
}

// Render userdefined icons in module
if (!empty($extConf->getListIconsWithPrefix())) {
$iconsToShow = [];
foreach ($extConf->getListIconsWithPrefix() as $string) {
foreach ($iconsAll as $key) {
if (strpos($key, $string) === 0) {
$iconsToShow[$string][] = $key;
}
}
// Sort icons
natcasesort($iconsToShow[$string]);
}
$this->view->assign('iconsToShow', $iconsToShow);
}
}
}
64 changes: 64 additions & 0 deletions Classes/Domain/Model/Dto/ExtensionConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php declare(strict_types = 1);

namespace JosefGlatz\Iconcheck\Domain\Model\Dto;

use TYPO3\CMS\Core\Utility\GeneralUtility;

class ExtensionConfiguration
{

/** @var bool */
protected $listAllIconIdentifiers;

/** @var string */
protected $listIconsWithPrefix;

/** @var bool */
protected $enableModuleForEverybody;

/** @var bool */
protected $disableModule;

public function __construct()
{
/** @noinspection UnserializeExploitsInspection */
$settings = (array)unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['iconcheck']);
foreach ($settings as $key => $value) {
if (property_exists(__CLASS__, $key)) {
$this->$key = $value;
}
}
}

/**
* @return bool
*/
public function isListAllIconIdentifiers(): bool
{
return (bool)$this->listAllIconIdentifiers;
}

/**
* @return array
*/
public function getListIconsWithPrefix(): array
{
return GeneralUtility::trimExplode(',', $this->listIconsWithPrefix, true);
}

/**
* @return bool
*/
public function isEnableModuleForEverybody(): bool
{
return (bool)$this->enableModuleForEverybody;
}

/**
* @return bool
*/
public function isDisableModule(): bool
{
return (bool)$this->disableModule;
}
}
Loading

0 comments on commit 343e84e

Please sign in to comment.