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 17, 2023
1 parent 707c09e commit ba2e7a0
Showing 1 changed file with 73 additions and 61 deletions.
134 changes: 73 additions & 61 deletions Classes/Backend/Form/ToolBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,51 +156,6 @@ public function createEditButton($editTable, $editUid, $options = [])
return $btn;
}

/**
* Erstellt einen Link zur Bearbeitung eines Datensatzes.
*
* @param string $editTable DB-Tabelle des Datensatzes
* @param int $editUid UID des Datensatzes
* @param string $label Bezeichnung des Links
* @param array $options
*
* @return string
*/
public function createEditLink($editTable, $editUid, $label = 'Edit', $options = [])
{
$params = '&edit['.$editTable.']['.$editUid.']=edit';
$class = array_key_exists('class', $options) ? htmlspecialchars($options['class']) : self::CSS_CLASS_BTN;
$class = ' class="'.$class.'"';
$label = isset($options['label']) ? $options['label'] : $label;
$onClick = htmlspecialchars(BackendUtility::editOnClick($params));

return '<a href="#" '.$class.' onclick="'.$onClick.'" title="Edit UID: '.$editUid.'">'
.Icons::getSpriteIcon('actions-page-open')
.$label
.'</a>';
}

/**
* Erstellt einen History-Link
* Achtung: Benötigt die JS-Funktion jumpExt() in der Seite.
*
* @param string $table
* @param int $recordUid
*
* @return string
*/
public function createHistoryLink($table, $recordUid, $label = '')
{
$this->addBaseInlineJSCode();
$image = Icons::getSpriteIcon('actions-document-history-open');
$moduleUrl = BackendUtility::getModuleUrl('record_history', ['element' => $table.':'.$recordUid]);
$onClick = 'return jumpExt('.Strings::quoteJSvalue($moduleUrl).',\'#latest\');';

return '<a class="btn btn-default" href="#" onclick="'.htmlspecialchars($onClick).'" title="'
.htmlspecialchars($GLOBALS['LANG']->getLL('history')).'">'
.$image.'</a>';
}

/**
* Creates a new-record-button.
*
Expand Down Expand Up @@ -280,22 +235,11 @@ public function createShowLink($pid, $label, $urlParams = '', $options = [])
*/
public function createNewLink($table, $pid, $label = 'New', $options = [])
{
$returnUrl = T3General::getIndpEnv('REQUEST_URI');
$uri = (string) $this->uriBuilder->buildUriFromRoute(
'record_edit',
[
'id' => $pid,
'returnUrl' => $returnUrl,
sprintf('edit[%s][%s]', $table, $pid) => 'new',
]
);
if (isset($options[self::OPTION_PARAMS])) {
$uri .= $options[self::OPTION_PARAMS];
}
$uri = $this->buildEditUri($table, $pid, 'new', $options);
$uri .= $this->buildDefVals($options);

$image = Icons::getSpriteIcon('actions-document-new', ['asIcon' => true]);
$newRecordButton = $this->buttonBar->makeLinkButton()
$recordButton = $this->buttonBar->makeLinkButton()
->setHref($uri)
->setTitle($label)
->setShowLabelText(true)
Expand All @@ -305,11 +249,79 @@ public function createNewLink($table, $pid, $label = 'New', $options = [])

if (isset($options[self::OPTION_CONFIRM]) && strlen($options[self::OPTION_CONFIRM]) > 0) {
$class .= ' t3js-modal-trigger';
$newRecordButton->setDataAttributes(['content' => $options[self::OPTION_CONFIRM]]);
$recordButton->setDataAttributes(['content' => $options[self::OPTION_CONFIRM]]);
}
$recordButton->setClasses($class);

return $recordButton->render();
}

/**
* Erstellt einen Link zur Bearbeitung eines Datensatzes.
*
* @param string $editTable DB-Tabelle des Datensatzes
* @param int $editUid UID des Datensatzes
* @param string $label Bezeichnung des Links
* @param array $options
*
* @return string
*/
public function createEditLink($editTable, $editUid, $label = 'Edit', $options = [])
{
$uri = $this->buildEditUri($editTable, $editUid, 'edit', $options);

$image = Icons::getSpriteIcon('actions-document-open', ['asIcon' => true]);
$recordButton = $this->buttonBar->makeLinkButton()
->setHref($uri)
->setTitle($label)
->setShowLabelText(true)
->setIcon($image);

$class = array_key_exists('class', $options) ? htmlspecialchars($options['class']) : '';
$recordButton->setClasses($class);

return $recordButton->render();
}

/**
* @param string $operation new or edit
*/
private function buildEditUri($table, $pid, $operation, array $options)
{
$returnUrl = T3General::getIndpEnv('REQUEST_URI');
$uri = (string) $this->uriBuilder->buildUriFromRoute(
'record_edit',
[
'id' => $pid,
'returnUrl' => $returnUrl,
sprintf('edit[%s][%s]', $table, $pid) => $operation,
]
);
if (isset($options[self::OPTION_PARAMS])) {
$uri .= $options[self::OPTION_PARAMS];
}
$newRecordButton->setClasses($class);
return $uri;
}

return $newRecordButton->render();
/**
* Erstellt einen History-Link
* Achtung: Benötigt die JS-Funktion jumpExt() in der Seite.
*
* @param string $table
* @param int $recordUid
*
* @return string
*/
public function createHistoryLink($table, $recordUid, $label = '')
{
$this->addBaseInlineJSCode();
$image = Icons::getSpriteIcon('actions-document-history-open');
$moduleUrl = BackendUtility::getModuleUrl('record_history', ['element' => $table.':'.$recordUid]);
$onClick = 'return jumpExt('.Strings::quoteJSvalue($moduleUrl).',\'#latest\');';

return '<a class="btn btn-default" href="#" onclick="'.htmlspecialchars($onClick).'" title="'
.htmlspecialchars($GLOBALS['LANG']->getLL('history')).'">'
.$image.'</a>';
}

/**
Expand Down

0 comments on commit ba2e7a0

Please sign in to comment.