/**
* Returns if CRUD is in editing mode or not. It's preferable over
* checking if($grid->form).
*
* @param string $mode Specify which editing mode you expect
*
* @return bool true if editing.
*/
public function isEditing($mode = null)
{
$page_mode = $this->virtual_page->isActive();
// Requested edit, but not allowed
if ($page_mode == 'edit' && !$this->allow_edit) {
throw $this->exception('Editing is not allowed');
}
// Requested add but not allowed
if ($page_mode == 'add' && !$this->allow_add) {
throw $this->exception('Adding is not allowed');
}
// Request matched argument exactly
if (!is_null($mode)) {
return $mode === $page_mode;
}
// Argument was blank, then edit/add is OK
return (bool) $page_mode;
}