/**
* Template function plugin which generate delete and toggle buttons for objects to be used in
* combination with `WoltLabSuite/Core/Ui/Object/Action`.
- *
+ *
* TODO: More information and examples
*
* @author Matthias Schmidt
'delete',
'toggle',
];
-
+
/**
* @inheritDoc
*/
throw new \InvalidArgumentException("Missing 'action' argument.");
}
$action = $tagArgs['action'];
- if (!in_array($action, static::SUPPORTED_ACTIONS)) {
+ if (!\in_array($action, static::SUPPORTED_ACTIONS)) {
throw new \InvalidArgumentException("Unsupported action '{$action}'.");
}
}
foreach ($tagArgs as $key => $value) {
if (\preg_match('~^parameter.+$~', $key)) {
- $additionalAttributes .= sprintf(
+ $additionalAttributes .= \sprintf(
' data-object-action-%s="%s"',
\strtolower(\preg_replace(
'~([A-Z])~',
'objectTitle' => $tagArgs['objectTitle'],
]
));
- }
- else if (isset($tagArgs['confirmMessage'])) {
- $confirmMessage = StringUtil::encodeHTML($tplObj->fetchString(
- $tplObj->getCompiler()->compileString(
- $tagArgs['confirmMessage'],
- $language->get($tagArgs['confirmMessage'])
- )['template']));
- }
- else {
+ } elseif (isset($tagArgs['confirmMessage'])) {
+ $confirmMessage = StringUtil::encodeHTML(
+ $tplObj->fetchString(
+ $tplObj->getCompiler()->compileString(
+ $tagArgs['confirmMessage'],
+ $language->get($tagArgs['confirmMessage'])
+ )['template']
+ )
+ );
+ } else {
throw new \InvalidArgumentException("Missing 'objectTitle' or 'confirmMessage' argument for 'delete' action.");
}
return <<<HTML
<span class="icon icon16 fa-times jsObjectAction jsTooltip pointer" title="{$title}" data-object-action="delete" data-confirm-message="{$confirmMessage}"{$additionalAttributes}></span>
HTML;
-
+
break;
-
+
case 'toggle':
if (!isset($tagArgs['isDisabled'])) {
throw new \InvalidArgumentException("Missing 'isDisabled' argument for 'toggle' action.");
}
-
+
$icon = 'fa-check-square-o';
$title = $language->getDynamicVariable('wcf.global.button.disable');
if ($tagArgs['isDisabled']) {
$title = $language->getDynamicVariable('wcf.global.button.enable');
}
$title = StringUtil::encodeHTML($title);
-
+
return <<<HTML
<span class="icon icon16 {$icon} jsObjectAction jsTooltip pointer" title="{$title}" data-object-action="toggle"{$additionalAttributes}></span>
HTML;
-
+
default:
throw new \LogicException("Unreachable.");
}