Skip to content

Commit

Permalink
#340 add support for security policy header
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed Nov 18, 2023
1 parent b9908f7 commit 98da3ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions Classes/Backend/Form/ToolBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ToolBox
public const OPTION_TITLE = 'title';

public const OPTION_CONFIRM = 'confirm';
public const OPTION_ICON_NAME = 'icon-name';
public const OPTION_ICON_NAME = 'icon';
public const OPTION_HOVER_TEXT = 'hover';

public const OPTION_PARAMS = 'params';
Expand Down Expand Up @@ -635,7 +635,6 @@ public function createLink($paramStr, $pid, $label, array $options = [])
*/
public function createModuleLink(array $params, $pid, $label, array $options = [])
{
$label = $this->buildIconTag($options, $label);
if (!isset($_GET['id']) && !isset($params['id'])) {
// ensure pid is set even on POST requests.
$params['id'] = $pid;
Expand All @@ -648,8 +647,7 @@ public function createModuleLink(array $params, $pid, $label, array $options = [
$recordButton->setHoverText($options[self::OPTION_HOVER_TEXT]);
}

if (isset($options[self::OPTION_ICON_NAME])) {
$icon = Icons::getSpriteIcon($options[self::OPTION_ICON_NAME], ['asIcon' => true]);
if ($icon = $this->buildIcon($options)) {
$recordButton->setIcon($icon);
}

Expand All @@ -665,14 +663,17 @@ public function createModuleLink(array $params, $pid, $label, array $options = [
return $recordButton->render();
}

protected function buildIconTag(array $options, $label = '')
/**
* @return \TYPO3\CMS\Core\Imaging\Icon|null
*/
protected function buildIcon(array $options)
{
$tag = $label;
$tag = null;
// $options['sprite'] für abwärtskompatibilität
if (isset($options['icon']) || isset($options['sprite'])) {
$icon = isset($options['icon']) ? $options['icon'] : $options['sprite'];
// FIXME: label get lost here??
$tag = Icons::getSpriteIcon($icon, $options);
$tag = Icons::getSpriteIcon($icon, array_merge(['asIcon' => true], $options));
}

return $tag;
Expand All @@ -690,7 +691,9 @@ protected function buildIconTag(array $options, $label = '')
*/
public function createSubmit($name, $value, $confirmMsg = '', $options = [])
{
$icon = $this->buildIconTag($options, '');
// FIXME: das muss überarbeitet werden.
$icon = $this->buildIcon($options);
$icon = $icon ? $icon->render() : '';
$onClick = '';
if (strlen($confirmMsg)) {
$onClick = 'onclick="return confirm('.Strings::quoteJSvalue($confirmMsg).')"';
Expand Down
4 changes: 2 additions & 2 deletions tests/Classes/Backend/Form/ToolBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function testCreateLinkWithIconForTypo387()
->will(self::returnValue('jumpUrl'));

self::assertRegExp(
'/<a href="#" class="myClass" onclick="window.location.href=\'jumpUrl\'; return false;" >.*<img.*actions\-add\.svg" width="16" height="16".*<\/a>/s',
'/<a href="jumpUrl" class="myClass" title="mylabel">.*<img.*actions-add\.svg" width="16" height="16".*<\/a>/s',
$formTool->createLink($urlParameters, 0, 'mylabel', $options)
);
}
Expand All @@ -386,7 +386,7 @@ public function testCreateLinkWithIconAndSizeForTypo387()
->will(self::returnValue('jumpUrl'));

self::assertRegExp(
'/<a href="#" class="myClass" onclick="window.location.href=\'jumpUrl\'; return false;" >.*<img.*actions\-add\.svg" width="32" height="32".*<\/a>/s',
'/<a href="jumpUrl" class="myClass" title="mylabel">.*<img.*actions\-add\.svg" width="32" height="32".*<\/a>/s',
$formTool->createLink($urlParameters, 0, 'mylabel', $options)
);
}
Expand Down

0 comments on commit 98da3ac

Please sign in to comment.