/** * Utility static to avoid repetition. * * @param Controller $controller * @param string $identifier e.g. 'ParentID' or 'ID' * @retun number */ public static function get_numeric_identifier($controller, $identifier = 'ID') { // Deal-to all types of incoming data if (!$controller->hasMethod('currentPageID')) { return 0; } // Use native SS logic to deal with an identifier of 'ID' if ($identifier == 'ID') { $useId = $controller->currentPageID(); // Otherwise it's custom } else { $params = $controller->getRequest()->requestVars(); $idFromFunc = function () use($controller, $params, $identifier) { if (!isset($params[$identifier])) { if (!isset($controller->urlParams[$identifier])) { return 0; } return $controller->urlParams[$identifier]; } return $params[$identifier]; }; $useId = $idFromFunc(); } // We may have a padded string e.g. "1217 ". Without first truncating, we'd return 0 and pass tests... $id = (int) trim($useId); return !empty($id) && is_numeric($id) ? $id : 0; }
/** * Edited version of the GridFieldEditForm function * adds the 'Bulk Upload' at the end of the crums * * CMS-specific functionality: Passes through navigation breadcrumbs * to the template, and includes the currently edited record (if any). * see {@link LeftAndMain->Breadcrumbs()} for details. * * @author SilverStripe original Breadcrumbs() method * @see GridFieldDetailForm_ItemRequest * @param boolean $unlinked * @return ArrayData */ public function Breadcrumbs($unlinked = false) { if (!$this->controller->hasMethod('Breadcrumbs')) { return; } $items = $this->controller->Breadcrumbs($unlinked); $items->push(new ArrayData(array('Title' => 'Bulk Editing', 'Link' => false))); return $items; }
/** * Return the form's action attribute. * This is build by adding an executeForm get variable to the parent controller's Link() value * * @return string */ public function FormAction() { if ($this->formActionPath) { return $this->formActionPath; } elseif ($this->controller->hasMethod("FormObjectLink")) { return $this->controller->FormObjectLink($this->name); } else { return Controller::join_links($this->controller->Link(), $this->name); } }
/** * CMS-specific functionality: Passes through navigation breadcrumbs * to the template, and includes the currently edited record (if any). * see {@link LeftAndMain->Breadcrumbs()} for details. * * @param boolean $unlinked * @return ArrayData */ function Breadcrumbs($unlinked = false) { if (!$this->popupController->hasMethod('Breadcrumbs')) { return; } $items = $this->popupController->Breadcrumbs($unlinked); if ($this->record && $this->record->ID) { $items->push(new ArrayData(array('Title' => $this->record->Title, 'Link' => $this->Link()))); } else { $items->push(new ArrayData(array('Title' => sprintf(_t('GridField.NewRecord', 'New %s'), $this->record->i18n_singular_name()), 'Link' => false))); } return $items; }