TYPO3 CMS  TYPO3_8-7
BitmapIconProvider.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
27  const MARKUP_IDENTIFIER_INLINE = 'inline';
28 
33  public function prepareIconMarkup(Icon $icon, array $options = [])
34  {
35  $icon->setMarkup($this->generateMarkup($icon, $options));
36  $icon->setAlternativeMarkup(self::MARKUP_IDENTIFIER_INLINE, $this->generateInlineMarkup($icon, $options));
37  }
38 
45  protected function generateMarkup(Icon $icon, array $options)
46  {
47  if (empty($options['source'])) {
48  throw new \InvalidArgumentException('[' . $icon->getIdentifier() . '] The option "source" is required and must not be empty', 1440754980);
49  }
50 
51  $source = $options['source'];
52 
53  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
54  $source = GeneralUtility::getFileAbsFileName($source);
55  }
56  $source = PathUtility::getAbsoluteWebPath($source);
57 
58  return '<img src="' . htmlspecialchars($source) . '" width="' . $icon->getDimension()->getWidth() . '" height="' . $icon->getDimension()->getHeight() . '" />';
59  }
60 
67  protected function generateInlineMarkup(Icon $icon, array $options)
68  {
69  if (empty($options['source'])) {
70  throw new \InvalidArgumentException('The option "source" is required and must not be empty', 1471460676);
71  }
72 
73  $source = $options['source'];
74 
75  if (strpos($source, 'EXT:') === 0 || strpos($source, '/') !== 0) {
76  $source = GeneralUtility::getFileAbsFileName($source);
77  }
78 
79  if (!file_exists($source)) {
80  return '';
81  }
82 
83  return '<image width="' . $icon->getDimension()->getWidth() . '" height="'
84  . $icon->getDimension()->getHeight() . '" xlink:href="' . PathUtility::getAbsoluteWebPath($source) . '"/>';
85  }
86 }
setAlternativeMarkup($markupIdentifier, $markup)
Definition: Icon.php:134
static getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:40
static getFileAbsFileName($filename, $_=null, $_2=null)