class AdminMenuItem

Assumes page callback for the menu item will be drupal_get_form($form_id).

Assumes an admin form (accessed via the page arguments) will be created at or via the .module file form builder function 'MYMODULE_form_admin', where MYMODULE is the machine name of the module passed on construction.

Assumes the access is set to 'access administration pages'.

This implementation does not use a FormController, and so it only serves to demonstrate old-style Drupal form builders.

UML: AdminMenuItem

@todo OOE style object-oriented admin version of a IFormControllerMenuItem

@author darrenkelly

Hierarchy

Expanded class hierarchy of AdminMenuItem

1 file declares its use of AdminMenuItem
AbstractFactory.php in lib/Drupal/ooe/Factory/AbstractFactory.php
AbstractFactory

File

lib/Drupal/ooe/Admin/AdminMenuItem.php, line 33
AdminMenuItem

Namespace

Drupal\ooe\Admin
View source
class AdminMenuItem extends FormMenuItem {

  private static $ACCESS = array('access administration pages');

  // NB: can't use const:
  // http://stackoverflow.com/questions/11184469/php-use-array-as-class-constant

  /**
   * Constructor.
   *
   * @param string $module
   *   The module machine name.
   * @param string $title
   *   The title of the admin menu item.
   * @param string $path
   *   The menu path
   */
  public function __construct($module, $title, $path) {
    parent::__construct($module, $title, $path);

    $this->pageArguments = $this->pageArguments();

    // $this->setAccessArguments(self::$ACCESS);
    $this->accessArguments = self::$ACCESS;

    // 'hook_menu() also provides an important part of Drupal's security,
    // as it performs user access checks.
    // We would like only administrators to be able to access this form,
    // and we'll check that permission here in hook_menu().
    // To minimize the number of permissions an administrator has to deal with,
    // we'll use the core administration permission
    // instead of creating a new custom permission.'
  }

  /**
   * Forces the page arguments to meet a convention MYMODULE_form_admin.
   *
   * @return array
   *   An array containing the page arguments as MYMODULE_form_admin.
   */
  private function pageArguments() {
    return array($this->getModule() . "_form_admin");
  }

  /**
   * Overridden to prevent resetting of locally fixed admin value.
   *
   * @param string[] $pageArguments
   *   Page arguments.
   *
   * @throws \Exception
   *  Always thrown to prevent reset.
   * @return IMenuItem
   *   Never returned.
   */
  public function setPageArguments(array $pageArguments) {
    throw new \Exception("IGNORED: page arguments are forced to '"
      . $this->pageArguments() . "' !");
  }

  /**
   * Overridden to prevent resetting of locally fixed admin value.
   *
   * @param string[] $accessArguments
   *   The access arguments string array.
   *
   * @throws \Exception
   *   Always thrown to prevent reset.
   *
   * @return IMenuItem
   *   Never returned.
   */
  public function setAccessArguments(array $accessArguments) {
    throw new \Exception("IGNORED: access arguments are forced to '"
      . self::$ACCESS . "' !");
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
AdminMenuItem::$ACCESS private static property
AdminMenuItem::pageArguments private function Forces the page arguments to meet a convention MYMODULE_form_admin.
AdminMenuItem::setAccessArguments public function Overridden to prevent resetting of locally fixed admin value. Overrides DefaultMenuItem::setAccessArguments
AdminMenuItem::setPageArguments public function Overridden to prevent resetting of locally fixed admin value. Overrides DefaultMenuItem::setPageArguments
AdminMenuItem::__construct public function Constructor. Overrides FormMenuItem::__construct
DefaultMenuItem::$accessArguments protected property An array of arguments to pass to the access callback function.
DefaultMenuItem::$accessCallback protected property The access callback.
DefaultMenuItem::$description private property From hook_menu(): 'The untranslated description of the menu item.'
DefaultMenuItem::$isExpanded private property Whether the menu item is expanded.
DefaultMenuItem::$menuName private property The name of a custom menu this should appear in.
DefaultMenuItem::$pageArguments protected property An array of arguments to pass to the page callback.
DefaultMenuItem::$pageCallback protected property From hook_menu(): '"page callback": The function to call to display a web page when the user visits the path. If omitted, the parent menu item's callback will be used instead.'
DefaultMenuItem::$path private property The path portion of the menu item's URL.
DefaultMenuItem::$title private property The title of the menu item.
DefaultMenuItem::$type private property The bitmask of flags describing properties of the menu item.
DefaultMenuItem::$weight private property An integer that determines the relative position of items in the menu.
DefaultMenuItem::forceAccessCallbackFALSE final public function Forces the access callback to be FALSE. Overrides IMenuItem::forceAccessCallbackFALSE
DefaultMenuItem::forceAccessCallbackTRUE final public function Forces the access callback to be TRUE. Overrides IMenuItem::forceAccessCallbackTRUE
DefaultMenuItem::get public function Builds and returns a valid Drupal menu item array for hook_menu(). Overrides IMenuItem::get
DefaultMenuItem::getPageArgumentsDecorated protected function By default just the pageArguments as set, if any.
DefaultMenuItem::getPath final public function The path portion of the menu item's URL. Overrides IMenuItem::getPath
DefaultMenuItem::setAccessCallback public function Sets the access callback to a string representing a callback function. Overrides IMenuItem::setAccessCallback
DefaultMenuItem::setDescription final public function Sets 'The untranslated description of the menu item'. Overrides IMenuItem::setDescription
DefaultMenuItem::setExpanded final public function Sets whether the menu item is expanded. Overrides IMenuItem::setExpanded
DefaultMenuItem::setMenuName final public function The machine name of the menu for this. Overrides IMenuItem::setMenuName
DefaultMenuItem::setPath final public function Sets the menu path portion of the menu item's URL. Overrides IMenuItem::setPath
DefaultMenuItem::setTitle final public function Sets (or resets) the title of the menu item. Overrides IMenuItem::setTitle
DefaultMenuItem::setType final public function Sets the bitmask of flags describing properties of the menu item. Overrides IMenuItem::setType
DefaultMenuItem::setTypeCallback final public function Sets the menu type to be a MENU_CALLBACK menu item (if TRUE). Overrides IMenuItem::setTypeCallback
DefaultMenuItem::setTypeDefaultLocalTask final public function Sets the menu type to be a MENU_DEFAULT_LOCAL_TASK (if TRUE). Overrides IMenuItem::setTypeDefaultLocalTask
DefaultMenuItem::setTypeLocalAction final public function Sets the menu type to be a MENU_LOCAL_ACTION (if TRUE). Overrides IMenuItem::setTypeLocalAction
DefaultMenuItem::setTypeLocalTask final public function Sets the menu type to be a MENU_LOCAL_TASK (if TRUE). Overrides IMenuItem::setTypeLocalTask
DefaultMenuItem::setTypeNormal final public function Sets the menu type to be a MENU_NORMAL_ITEM menu item (if TRUE). Overrides IMenuItem::setTypeNormal
DefaultMenuItem::setTypeSuggestedItem final public function Sets the menu type to be a MENU_SUGGESTED_ITEM (if TRUE). Overrides IMenuItem::setTypeSuggestedItem
DefaultMenuItem::setWeight final public function Sets the menu item weight. Overrides IMenuItem::setWeight
DefaultModuleHelper::$displayName private property A human readable and displayable name of the module.
DefaultModuleHelper::$factory private property The current factory of this.
DefaultModuleHelper::$module private property The module machine name.
DefaultModuleHelper::f protected function The current factory, or a lazily created DefaultFactory.
DefaultModuleHelper::factory protected function The current factory or a lazily created DefaultFactory.
DefaultModuleHelper::getFactory public function The current factory. Overrides IModuleHelper::getFactory
DefaultModuleHelper::getModule public function Gets the module machine name. Overrides IModuleHelper::getModule
DefaultModuleHelper::getModuleDisplayName public function A human readable and displayable name of the module. Overrides IModuleHelper::getModuleDisplayName
DefaultModuleHelper::setFactory protected function Sets the factory of this.
DefaultModuleHelper::setModule private function Sets the module machine name.
DefaultModuleHelper::setModuleDisplayName public function Sets a human readable and displayable name of the module. Overrides IModuleHelper::setModuleDisplayName
FormMenuItem::PAGE_CALLBACK constant Fixed at drupal_get_form().
FormMenuItem::setPageCallback final public function Overridden to always throw an exception. Overrides DefaultMenuItem::setPageCallback