Skip to content

Commit

Permalink
Feature/support for content security policy header (#341)
Browse files Browse the repository at this point in the history
* #340 add support for security policy header
* #340 change reload events for form input elements
* #340 fix unit tests
* #340 add flash message to DocumentTemplate
* #340 createNewButton is alias of createNewLink
* #340 improve button hover text
* #340 fix tce links for older t3 versions
  • Loading branch information
digedag authored Dec 9, 2023
1 parent f8045dd commit 5232a12
Show file tree
Hide file tree
Showing 20 changed files with 1,080 additions and 364 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ v1.18.0 (??.11.2023)
* BC: Parameter type of exceptions changed in ExceptionHandlerInterface to \Throwable
* Share ViewContext instance of current configuration with current request
* Fixed some PHP 8 issues
* Support for activated content security policy header in backend modules
* Improved icon support in backend modules
* BC: impossible to use HTML-Code in title parameter of ToolBox::createModuleLink(). Most likely this was done for icon code. As fix provide icon as option ToolBox::OPTION_ICON_NAME.
* BC: removed public attributes `JScode` and `JScodeArray` in `Sys25\RnBase\Backend\Template\Override\DocumentTemplate`
* Support for FlashMessage via `DocumentTemplate::showFlashMessage()`
* Method `rmFromList` added to `T3General`
* Possible BC: `ToolBox::createNewButton()` is now alias of `ToolBox::createNewLink()`

v1.17.4 (22.09.2023)

Expand Down
5 changes: 2 additions & 3 deletions Classes/Backend/Decorator/BaseDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Sys25\RnBase\Domain\Model\DataInterface;
use Sys25\RnBase\Domain\Model\DataModel;
use Sys25\RnBase\Domain\Model\DomainModelInterface as DomainInterface;
use Sys25\RnBase\Domain\Model\RecordInterface;
use Sys25\RnBase\Utility\Strings;
use Sys25\RnBase\Utility\TYPO3;

Expand Down Expand Up @@ -427,11 +426,11 @@ protected function formatActionMovedown(
/**
* Returns the uid map and sets the pointer to the current element.
*
* @param RecordInterface $item
* @param DomainInterface $item
*
* @return array
*/
protected function getUidMap(RecordInterface $item)
protected function getUidMap(DomainInterface $item)
{
if (!$this->getOptions()->hasUidMap()) {
return [];
Expand Down
127 changes: 127 additions & 0 deletions Classes/Backend/Form/Element/EnhancedLinkButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace Sys25\RnBase\Backend\Form\Element;

use Sys25\RnBase\Utility\T3General;
use TYPO3\CMS\Backend\Template\Components\Buttons\LinkButton;

/***************************************************************
* Copyright notice
*
* (c) 2023 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
* Erweitert den LinkButton von TYPO3 um zusätzliche Funktionen.
* - man kann links ohne Icon setzen
* - der Hover-Tooltip kann abweichend vom Label sein
* - die default btn-CSS-Klassen können komplett ersetzt werden.
*/
class EnhancedLinkButton extends LinkButton
{
private $overrideCss = true;

public function addDataAttributes(array $dataAttributes)
{
$this->dataAttributes = array_merge($this->dataAttributes, $dataAttributes);
}

/**
* If set given css classes will override default button classes.
*
* @param bool $value
*
* @return LinkButton
*/
public function setOverrideCss($value)
{
$this->overrideCss = (bool) $value;

return $this;
}

/**
* hover tooltip attribute of the link.
*
* @var string
*/
private $hoverText = '';

/**
* Get hoverText.
*
* @return string
*/
public function getHoverText()
{
return ''.$this->hoverText;
}

/**
* Set tooltip text.
*
* @param string $value hover text
*
* @return LinkButton
*/
public function setHoverText($value)
{
$this->hoverText = $value;

return $this;
}

/**
* Renders the markup for the button.
*
* @return string
*/
public function render()
{
$cssClasses = 'btn btn-default btn-sm ';
if ($this->overrideCss && !empty($this->getClasses())) {
$cssClasses = '';
}

$attributes = [
'href' => $this->getHref(),
'class' => trim($cssClasses.$this->getClasses()),
'title' => $this->getHoverText() ?: $this->getTitle(),
];
$labelText = '';
if ($this->showLabelText) {
$labelText = ' '.$this->title;
}
foreach ($this->dataAttributes as $attributeName => $attributeValue) {
$attributes['data-'.$attributeName] = $attributeValue;
}
if (method_exists($this, 'isDisabled') && $this->isDisabled()) {
$attributes['disabled'] = 'disabled';
$attributes['class'] .= ' disabled';
}
$attributesString = T3General::implodeAttributes($attributes, true);

$icon = $this->getIcon() ? $this->getIcon()->render() : '';

return '<a '.$attributesString.'>'
.trim($icon.htmlspecialchars($labelText))
.'</a>';
}
}
2 changes: 1 addition & 1 deletion Classes/Backend/Form/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function isNEWRecord($uid)
* @param string $uid
* @param array $record should contain pid and other default values for record
*
* @return multitype:
* @return array
*/
protected function compileFormData($table, $uid, $record)
{
Expand Down
Loading

0 comments on commit 5232a12

Please sign in to comment.