Esempio n. 1
0
 /**
  * @test
  */
 public function registerIconAddNewIconToRegistry()
 {
     $unregisterdIcon = 'foo-bar-unregistered';
     $this->assertFalse($this->subject->isRegistered($unregisterdIcon));
     $this->subject->registerIcon($unregisterdIcon, FontawesomeIconProvider::class, array('name' => 'pencil', 'additionalClasses' => 'fa-fw'));
     $this->assertTrue($this->subject->isRegistered($unregisterdIcon));
 }
Esempio n. 2
0
 /**
  * @test
  * @dataProvider differentSizesDataProvider
  */
 public function getIconByIdentifierAndSizeReturnsNotFoundIconWithCorrectMarkupIfUnregisteredIdentifierIsUsed($size)
 {
     $this->iconRegistryMock->isRegistered(Argument::any())->willReturn(false);
     $this->iconRegistryMock->getDefaultIconIdentifier(Argument::any())->willReturn('default-not-found');
     $this->iconRegistryMock->getIconConfigurationByIdentifier('default-not-found')->willReturn(['provider' => FontawesomeIconProvider::class, 'options' => array('name' => 'times-circle', 'additionalClasses' => 'fa-fw')]);
     $this->assertContains('<span class="t3js-icon icon icon-size-' . $size['expected'] . ' icon-state-default icon-default-not-found" data-identifier="default-not-found">', $this->subject->getIcon($this->notRegisteredIconIdentifier, $size['input'])->render());
 }
Esempio n. 3
0
 /**
  * @param string $identifier
  * @param string $size "large", "small" or "default", see the constants of the Icon class
  * @param string $overlayIdentifier
  * @param IconState $state
  * @return Icon
  */
 public function getIcon($identifier, $size = Icon::SIZE_DEFAULT, $overlayIdentifier = null, IconState $state = null)
 {
     if ($this->iconRegistry->isDeprecated($identifier)) {
         $deprecationSettings = $this->iconRegistry->getDeprecationSettings($identifier);
         GeneralUtility::deprecationLog(sprintf($deprecationSettings['message'], $identifier));
         if (!empty($deprecationSettings['replacement'])) {
             $identifier = $deprecationSettings['replacement'];
         }
     }
     if (!$this->iconRegistry->isRegistered($identifier)) {
         $identifier = $this->iconRegistry->getDefaultIconIdentifier();
     }
     $iconConfiguration = $this->iconRegistry->getIconConfigurationByIdentifier($identifier);
     $iconConfiguration['state'] = $state;
     $icon = $this->createIcon($identifier, $size, $overlayIdentifier, $iconConfiguration);
     /** @var IconProviderInterface $iconProvider */
     $iconProvider = GeneralUtility::makeInstance($iconConfiguration['provider']);
     $iconProvider->prepareIconMarkup($icon, $iconConfiguration['options']);
     return $icon;
 }
 /**
  * Registers new icons
  *
  * @param $identifier
  * @param $iconFile
  */
 private function registerIcon($identifier, $iconFile)
 {
     $fileInfo = pathinfo($iconFile);
     if ($fileInfo['extension'] == 'svg') {
         if (!$this->iconRegistry->isRegistered($identifier)) {
             $this->iconRegistry->registerIcon($identifier, \TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class, array('source' => $iconFile));
         }
     } else {
         if (!$this->iconRegistry->isRegistered($identifier)) {
             $this->iconRegistry->registerIcon($identifier, \TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class, array('source' => $iconFile));
         }
     }
 }
Esempio n. 5
0
 /**
  * This helper functions looks up the column that is used for the type of the chosen TCA table and then fetches the
  * corresponding iconName based on the chosen icon class in this TCA.
  * The TCA looks up
  * - [ctrl][typeicon_column]
  * -
  * This method solely takes care of the type of this record, not any statuses used for overlays.
  *
  * see EXT:core/Configuration/TCA/pages.php for an example with the TCA table "pages"
  *
  * @param string $table The TCA table
  * @param array $row The selected record
  * @internal
  * @TODO: make this method protected, after FormEngine doesn't need it anymore.
  * @return string The icon identifier string for the icon of that DB record
  */
 public function mapRecordTypeToIconIdentifier($table, array $row)
 {
     $recordType = array();
     $ref = null;
     if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_column'])) {
         $column = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
         if (isset($row[$column])) {
             // even if not properly documented the value of the typeicon_column in a record could be an array (multiselect)
             // in typeicon_classes a key could consist of a commaseparated string "foo,bar"
             // but mostly it should be only one entry in that array
             if (is_array($row[$column])) {
                 $recordType[1] = implode(',', $row[$column]);
             } else {
                 $recordType[1] = $row[$column];
             }
         } else {
             $recordType[1] = 'default';
         }
         // Workaround to give nav_hide pages a complete different icon
         // Although it's not a separate doctype
         // and to give root-pages an own icon
         if ($table === 'pages') {
             if ((int) $row['nav_hide'] > 0) {
                 $recordType[2] = $recordType[1] . '-hideinmenu';
             }
             if ((int) $row['is_siteroot'] > 0) {
                 $recordType[3] = $recordType[1] . '-root';
             }
             if (!empty($row['module'])) {
                 $recordType[4] = 'contains-' . $row['module'];
             }
             if ((int) $row['content_from_pid'] > 0) {
                 if ($row['is_siteroot']) {
                     $recordType[4] = 'page-contentFromPid-root';
                 } else {
                     $recordType[4] = (int) $row['nav_hide'] === 0 ? 'page-contentFromPid' : 'page-contentFromPid-hideinmenu';
                 }
             }
         }
         if (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
             foreach ($recordType as $key => $type) {
                 if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type])) {
                     $recordType[$key] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'][$type];
                 } else {
                     unset($recordType[$key]);
                 }
             }
             $recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
             if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask'])) {
                 $recordType[5] = str_replace('###TYPE###', $row[$column], $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['mask']);
             }
             if (isset($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'])) {
                 $parameters = array('row' => $row);
                 $recordType[6] = GeneralUtility::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['userFunc'], $parameters, $ref);
             }
         } else {
             foreach ($recordType as &$type) {
                 $type = 'tcarecords-' . $table . '-' . $type;
             }
             unset($type);
             $recordType[0] = 'tcarecords-' . $table . '-default';
         }
     } elseif (is_array($GLOBALS['TCA'][$table]['ctrl']['typeicon_classes'])) {
         $recordType[0] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_classes']['default'];
     } else {
         $recordType[0] = 'tcarecords-' . $table . '-default';
     }
     krsort($recordType);
     foreach ($recordType as $iconName) {
         if ($this->iconRegistry->isRegistered($iconName)) {
             return $iconName;
         }
     }
     return $this->iconRegistry->getDefaultIconIdentifier();
 }