Contao\DataContainer::generateButtons PHP Method

generateButtons() protected method

Compile buttons from the table configuration array and return them as HTML
protected generateButtons ( array $arrRow, string $strTable, array $arrRootIds = [], boolean $blnCircularReference = false, array $arrChildRecordIds = null, string $strPrevious = null, string $strNext = null ) : string
$arrRow array
$strTable string
$arrRootIds array
$blnCircularReference boolean
$arrChildRecordIds array
$strPrevious string
$strNext string
return string
    protected function generateButtons($arrRow, $strTable, $arrRootIds = array(), $blnCircularReference = false, $arrChildRecordIds = null, $strPrevious = null, $strNext = null)
    {
        if (empty($GLOBALS['TL_DCA'][$strTable]['list']['operations'])) {
            return '';
        }
        $return = '';
        foreach ($GLOBALS['TL_DCA'][$strTable]['list']['operations'] as $k => $v) {
            $v = is_array($v) ? $v : array($v);
            $id = \StringUtil::specialchars(rawurldecode($arrRow['id']));
            $label = $v['label'][0] ?: $k;
            $title = sprintf($v['label'][1] ?: $k, $id);
            $attributes = $v['attributes'] != '' ? ' ' . ltrim(sprintf($v['attributes'], $id, $id)) : '';
            // Add the key as CSS class
            if (strpos($attributes, 'class="') !== false) {
                $attributes = str_replace('class="', 'class="' . $k . ' ', $attributes);
            } else {
                $attributes = ' class="' . $k . '"' . $attributes;
            }
            // 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]}($arrRow, $v['href'], $label, $title, $v['icon'], $attributes, $strTable, $arrRootIds, $arrChildRecordIds, $blnCircularReference, $strPrevious, $strNext, $this);
                continue;
            } elseif (is_callable($v['button_callback'])) {
                $return .= $v['button_callback']($arrRow, $v['href'], $label, $title, $v['icon'], $attributes, $strTable, $arrRootIds, $arrChildRecordIds, $blnCircularReference, $strPrevious, $strNext, $this);
                continue;
            }
            // Generate all buttons except "move up" and "move down" buttons
            if ($k != 'move' && $v != 'move') {
                if ($k == 'show') {
                    $return .= '<a href="' . $this->addToUrl($v['href'] . '&amp;id=' . $arrRow['id'] . '&amp;popup=1') . '" title="' . \StringUtil::specialchars($title) . '" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . \StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG'][$strTable]['show'][1], $arrRow['id']))) . '\',\'url\':this.href});return false"' . $attributes . '>' . \Image::getHtml($v['icon'], $label) . '</a> ';
                } else {
                    $return .= '<a href="' . $this->addToUrl($v['href'] . '&amp;id=' . $arrRow['id'] . (\Input::get('nb') ? '&amp;nc=1' : '')) . '" title="' . \StringUtil::specialchars($title) . '"' . $attributes . '>' . \Image::getHtml($v['icon'], $label) . '</a> ';
                }
                continue;
            }
            $arrDirections = array('up', 'down');
            $arrRootIds = is_array($arrRootIds) ? $arrRootIds : array($arrRootIds);
            foreach ($arrDirections as $dir) {
                $label = $GLOBALS['TL_LANG'][$strTable][$dir][0] ?: $dir;
                $title = $GLOBALS['TL_LANG'][$strTable][$dir][1] ?: $dir;
                $label = \Image::getHtml($dir . '.svg', $label);
                $href = $v['href'] ?: '&amp;act=move';
                if ($dir == 'up') {
                    $return .= (is_numeric($strPrevious) && (!in_array($arrRow['id'], $arrRootIds) || empty($GLOBALS['TL_DCA'][$strTable]['list']['sorting']['root'])) ? '<a href="' . $this->addToUrl($href . '&amp;id=' . $arrRow['id']) . '&amp;sid=' . intval($strPrevious) . '" title="' . \StringUtil::specialchars($title) . '"' . $attributes . '>' . $label . '</a> ' : \Image::getHtml('up_.svg')) . ' ';
                } else {
                    $return .= (is_numeric($strNext) && (!in_array($arrRow['id'], $arrRootIds) || empty($GLOBALS['TL_DCA'][$strTable]['list']['sorting']['root'])) ? '<a href="' . $this->addToUrl($href . '&amp;id=' . $arrRow['id']) . '&amp;sid=' . intval($strNext) . '" title="' . \StringUtil::specialchars($title) . '"' . $attributes . '>' . $label . '</a> ' : \Image::getHtml('down_.svg')) . ' ';
                }
            }
        }
        return trim($return);
    }