Backend\Core\Engine\DataGrid::setColumnConfirm PHP Method

setColumnConfirm() public method

Set a custom column confirm message.
public setColumnConfirm ( string $column, string $message, string $custom = null, string $title = null, string $uniqueId = '[id]' )
$column string The name of the column to set the confirm for.
$message string The message to use as a confirm message.
$custom string Unused parameter.
$title string The title for the column.
$uniqueId string A unique ID that will be uses.
    public function setColumnConfirm($column, $message, $custom = null, $title = null, $uniqueId = '[id]')
    {
        $column = (string) $column;
        $message = (string) $message;
        $title = $title !== null ? (string) $title : null;
        $uniqueId = (string) $uniqueId;
        // has results
        if ($this->source->getNumResults() > 0) {
            // column doesn't exist
            if (!isset($this->columns[$column])) {
                throw new \SpoonDatagridException('The column "' . $column . '" doesn\'t exist, therefore no confirm message/script can be added.');
            } else {
                // get URL
                $url = $this->columns[$column]->getURL();
                // URL provided?
                if ($url != '') {
                    // grab current value
                    $currentValue = $this->columns[$column]->getValue();
                    // reset URL
                    $this->columns[$column]->setURL(null);
                    // set the value
                    $this->columns[$column]->setValue('<a href="' . $url . '" class="">' . $currentValue . '</a>');
                }
                // generate id
                $id = 'confirm-' . (string) $uniqueId;
                // set title if there wasn't one provided
                if ($title === null) {
                    $title = \SpoonFilter::ucfirst(BackendLanguage::lbl('Delete') . '?');
                }
                // grab current value
                $value = $this->columns[$column]->getValue();
                // add class for confirmation
                if (mb_substr_count($value, '<a') > 0) {
                    if (mb_substr_count($value, 'class="') > 0) {
                        $value = str_replace('class="', 'data-message-id="' . $id . '" class="jsConfirmationTrigger ', $value);
                    } else {
                        $value = str_replace('<a ', '<a data-message-id="' . $id . '" class="jsConfirmationTrigger" ', $value);
                    }
                } else {
                    // is it a link?
                    throw new Exception('The column doesn\'t contain a link.');
                }
                // append message
                $value .= '<div id="' . $id . '" title="' . $title . '" style="display: none;"><p>' . $message . '</p></div>';
                // reset value
                $this->columns[$column]->setValue($value);
            }
        }
    }