/** * Return a CMSMenuItem to add the given controller to the CMSMenu * * @param string $controllerClass * @return CMSMenuItem */ protected static function menuitem_for_controller($controllerClass) { $urlBase = AdminRootController::admin_url(); $urlSegment = Config::inst()->get($controllerClass, 'url_segment', Config::FIRST_SET); $menuPriority = Config::inst()->get($controllerClass, 'menu_priority', Config::FIRST_SET); // Don't add menu items defined the old way if (!$urlSegment) { return null; } $link = Controller::join_links($urlBase, $urlSegment) . '/'; // doesn't work if called outside of a controller context (e.g. in _config.php) // as the locale won't be detected properly. Use {@link LeftAndMain->MainMenu()} to update // titles for existing menu entries $menuTitle = LeftAndMain::menu_title($controllerClass); return new CMSMenuItem($menuTitle, $link, $controllerClass, $menuPriority); }
/** * Returns the main menu of the CMS. This is also used by init() * to work out which sections the user has access to. * * @param bool $cached * @return SS_List */ public function MainMenu($cached = true) { if (!isset($this->_cache_MainMenu) || !$cached) { // Don't accidentally return a menu if you're not logged in - it's used to determine access. if (!Member::currentUser()) { return new ArrayList(); } // Encode into DO set $menu = new ArrayList(); $menuItems = CMSMenu::get_viewable_menu_items(); // extra styling for custom menu-icons $menuIconStyling = ''; if ($menuItems) { /** @var CMSMenuItem $menuItem */ foreach ($menuItems as $code => $menuItem) { // alternate permission checks (in addition to LeftAndMain->canView()) if (isset($menuItem->controller) && $this->hasMethod('alternateMenuDisplayCheck') && !$this->alternateMenuDisplayCheck($menuItem->controller)) { continue; } $linkingmode = "link"; if ($menuItem->controller && get_class($this) == $menuItem->controller) { $linkingmode = "current"; } else { if (strpos($this->Link(), $menuItem->url) !== false) { if ($this->Link() == $menuItem->url) { $linkingmode = "current"; // default menu is the one with a blank {@link url_segment} } else { if (singleton($menuItem->controller)->stat('url_segment') == '') { if ($this->Link() == AdminRootController::admin_url()) { $linkingmode = "current"; } } else { $linkingmode = "current"; } } } } // already set in CMSMenu::populate_menu(), but from a static pre-controller // context, so doesn't respect the current user locale in _t() calls - as a workaround, // we simply call LeftAndMain::menu_title() again // if we're dealing with a controller if ($menuItem->controller) { $title = LeftAndMain::menu_title($menuItem->controller); } else { $title = $menuItem->title; } // Provide styling for custom $menu-icon. Done here instead of in // CMSMenu::populate_menu(), because the icon is part of // the CMS right pane for the specified class as well... if ($menuItem->controller) { $menuIcon = LeftAndMain::menu_icon_for_class($menuItem->controller); if (!empty($menuIcon)) { $menuIconStyling .= $menuIcon; } } $menu->push(new ArrayData(array("MenuItem" => $menuItem, "AttributesHTML" => $menuItem->getAttributesHTML(), "Title" => Convert::raw2xml($title), "Code" => $code, "Icon" => strtolower($code), "Link" => $menuItem->url, "LinkingMode" => $linkingmode))); } } if ($menuIconStyling) { Requirements::customCSS($menuIconStyling); } $this->_cache_MainMenu = $menu; } return $this->_cache_MainMenu; }
public function schema($request) { // TODO Hardcoding schema until we can get GridField to generate a schema dynamically $treeClassJS = Convert::raw2js($this->config()->tree_class); $adminURL = Convert::raw2js(AdminRootController::admin_url()); $json = <<<JSON { \t"id": "{$adminURL}campaigns\\/schema\\/EditForm", \t"schema": { \t\t"name": "EditForm", \t\t"id": "Form_EditForm", \t\t"action": "schema", \t\t"method": "GET", \t\t"attributes": { \t\t\t"id": "Form_EditForm", \t\t\t"action": "{$adminURL}campaigns\\/EditForm", \t\t\t"method": "POST", \t\t\t"enctype": "multipart\\/form-data", \t\t\t"target": null \t\t}, \t\t"data": [], \t\t"fields": [{ \t\t\t"name": "ID", \t\t\t"id": "Form_EditForm_ID", \t\t\t"type": "Hidden", \t\t\t"component": null, \t\t\t"holderId": null, \t\t\t"title": false, \t\t\t"source": null, \t\t\t"extraClass": "hidden form-group--no-label", \t\t\t"description": null, \t\t\t"rightTitle": null, \t\t\t"leftTitle": null, \t\t\t"readOnly": false, \t\t\t"disabled": false, \t\t\t"customValidationMessage": "", \t\t\t"attributes": [], \t\t\t"data": [] \t\t}, { \t\t\t"name": "ChangeSets", \t\t\t"id": "Form_EditForm_ChangeSets", \t\t\t"type": "Custom", \t\t\t"component": "GridField", \t\t\t"holderId": null, \t\t\t"title": "Campaigns", \t\t\t"source": null, \t\t\t"extraClass": null, \t\t\t"description": null, \t\t\t"rightTitle": null, \t\t\t"leftTitle": null, \t\t\t"readOnly": false, \t\t\t"disabled": false, \t\t\t"customValidationMessage": "", \t\t\t"attributes": [], \t\t\t"data": { \t\t\t\t"recordType": "{$treeClassJS}", \t\t\t\t"collectionReadEndpoint": { \t\t\t\t\t"url": "{$adminURL}campaigns\\/sets", \t\t\t\t\t"method": "GET" \t\t\t\t}, \t\t\t\t"itemReadEndpoint": { \t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id", \t\t\t\t\t"method": "GET" \t\t\t\t}, \t\t\t\t"itemUpdateEndpoint": { \t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id", \t\t\t\t\t"method": "PUT" \t\t\t\t}, \t\t\t\t"itemCreateEndpoint": { \t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id", \t\t\t\t\t"method": "POST" \t\t\t\t}, \t\t\t\t"itemDeleteEndpoint": { \t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id", \t\t\t\t\t"method": "DELETE" \t\t\t\t}, \t\t\t\t"editFormSchemaEndpoint": "{$adminURL}campaigns\\/schema\\/DetailEditForm", \t\t\t\t"columns": [ \t\t\t\t\t{"name": "Title", "field": "Name"}, \t\t\t\t\t{"name": "Changes", "field": "ChangesCount"}, \t\t\t\t\t{"name": "Description", "field": "Description"} \t\t\t\t] \t\t\t} \t\t}, { \t\t\t"name": "SecurityID", \t\t\t"id": "Form_EditForm_SecurityID", \t\t\t"type": "Hidden", \t\t\t"component": null, \t\t\t"holderId": null, \t\t\t"title": "Security ID", \t\t\t"source": null, \t\t\t"extraClass": "hidden", \t\t\t"description": null, \t\t\t"rightTitle": null, \t\t\t"leftTitle": null, \t\t\t"readOnly": false, \t\t\t"disabled": false, \t\t\t"customValidationMessage": "", \t\t\t"attributes": [], \t\t\t"data": [] \t\t}], \t\t"actions": [] \t} } JSON; $formName = $request->param('ID'); if ($formName == 'EditForm') { $response = $this->getResponse(); $response->addHeader('Content-Type', 'application/json'); $response->setBody($json); return $response; } else { return parent::schema($request); } }