/**
* Compile global buttons from the table configuration array and return them as HTML
*
* @return string
*/
protected function generateGlobalButtons()
{
if (!is_array($GLOBALS['TL_DCA'][$this->strTable]['list']['global_operations'])) {
return '';
}
$return = '';
foreach ($GLOBALS['TL_DCA'][$this->strTable]['list']['global_operations'] as $k => $v) {
if (\Input::get('act') == 'select' && !$v['showOnSelect']) {
continue;
}
$v = is_array($v) ? $v : array($v);
$label = is_array($v['label']) ? $v['label'][0] : $v['label'];
$title = is_array($v['label']) ? $v['label'][1] : $v['label'];
$attributes = $v['attributes'] != '' ? ' ' . ltrim($v['attributes']) : '';
// Custom icon (see #5541)
if ($v['icon']) {
$v['class'] = trim($v['class'] . ' header_icon');
// Add the theme path if only the file name is given
if (strpos($v['icon'], '/') === false) {
$v['icon'] = \Image::getPath($v['icon']);
}
$attributes = sprintf('style="background-image:url(\'%s%s\')"', TL_ASSETS_URL, $v['icon']) . $attributes;
}
if ($label == '') {
$label = $k;
}
if ($title == '') {
$title = $label;
}
// Call a custom function instead of using the default button
if (is_array($v['button_callback'])) {
$this->import($v['button_callback'][0]);
$return .= $this->{$v['button_callback'][0]}->{$v['button_callback'][1]}($v['href'], $label, $title, $v['class'], $attributes, $this->strTable, $this->root);
continue;
} elseif (is_callable($v['button_callback'])) {
$return .= $v['button_callback']($v['href'], $label, $title, $v['class'], $attributes, $this->strTable, $this->root);
continue;
}
$return .= '<a href="' . $this->addToUrl($v['href']) . '" class="' . $v['class'] . '" title="' . \StringUtil::specialchars($title) . '"' . $attributes . '>' . $label . '</a> ';
}
return $return;
}