Form Controller

This method is used to cancel an edit.

  • string $key - The name of the primary key of the URL variable.
  • return boolean - True if access level checks pass, false otherwise.
public function cancel($key = null)
{
$this->checkToken();

$model = $this->getModel();
$table = $model->getTable();
$context = "$this->option.edit.$this->context";

if (empty($key))
{
$key = $table->getKeyName();
}

$recordId = $this->input->getInt($key);

// Attempt to check-in the current record.
if ($recordId && property_exists($table, 'checked_out') && $model->checkin($recordId) === false)
{
// Check-in failed, go back to the record and display a notice.
$this->setError(\JText::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');

$this->setRedirect(
\JRoute::_(
'index.php?option=' . $this->option . '&view=' . $this->view_item
. $this->getRedirectToItemAppend($recordId, $key), false
)
);

return false;
}

// Clean the session data and redirect.
$this->releaseEditId($context, $recordId);
\JFactory::getApplication()->setUserState($context . '.data', null);

$url = 'index.php?option=' . $this->option . '&view=' . $this->view_list
. $this->getRedirectToListAppend();

// Check if there is a return value
$return = $this->input->get('return', null, 'base64');

if (!is_null($return) && \JUri::isInternal(base64_decode($return)))
{
$url = base64_decode($return);
}

// Redirect to the list screen.
$this->setRedirect(\JRoute::_($url, false));

return true;
}