You are here

abstract class FlexiformDisplayPageBase in Flexiform 7

Base class for page displays.

Hierarchy

Expanded class hierarchy of FlexiformDisplayPageBase

File

includes/display/page.display.inc, line 10
Base definition for pages.

View source
abstract class FlexiformDisplayPageBase extends FlexiformDisplayBase {

  /**
   * Define the menu links
   */
  public function hook_menu() {
    $items = array();
    $items[$this->configuration['path']] = array(
      'title callback' => 'flexiform_page_title',
      'title arguments' => $this
        ->getMenuArguments(),
      'page callback' => 'flexiform_page_wrapper',
      'page arguments' => $this
        ->getMenuArguments(),
      'access callback' => 'flexiform_page_access',
      'access arguments' => $this
        ->getMenuArguments(),
      'file' => 'flexiform.pages.inc',
      'weight' => isset($this->configuration['weight']) ? $this->configuration['weight'] : 0,
    );

    // Add the menu name if we have one.
    if (isset($this->configuration['menu_name'])) {
      $items[$this->configuration['path']]['menu_name'] = $this->configuration['menu_name'];
    }

    // Add the type if we have one.
    if (isset($this->configuration['type'])) {
      $items[$this->configuration['path']]['type'] = $this->configuration['type'];

      // @TODO: Deal properly with default local tasks.
    }

    // Add the access settings.
    if (!empty($this->configuration['access']['permission'])) {
      $items[$this->configuration['path']]['access callback'] = 'user_access';
      $items[$this->configuration['path']]['access arguments'] = array(
        $this->configuration['access']['permission'],
      );
    }
    return $items;
  }

  /**
   * Get the page/title arguments for hook_menu.
   *
   * @see FlexiformDisplayPageBase::hook_menu()
   */
  protected function getMenuArguments() {
    return array(
      $this
        ->getFlexiform()->form,
      get_class($this),
      NULL,
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getPath($base_entity_id = NULL) {

    // Get hold of all the info.
    $items = $this
      ->hook_menu();
    $path = explode('/', reset(array_keys($items)));
    $item = reset($items);
    $args = func_get_args();

    // Deal with placeholders.
    foreach ($item['page arguments'] as $pos => $arg) {
      if (is_int($arg)) {
        $path[$arg] = array_shift($args);
      }
    }

    // Append the rest of the arguments.
    $path = array_merge($path, $args);

    // Re-combine and return.
    return implode('/', $path);
  }

  /**
   * Get the configuration form.
   */
  public function configForm($form, &$form_state) {
    $form = parent::configForm($form, $form_state);
    $form['path'] = array(
      '#title' => t('Path'),
      '#type' => 'textfield',
      '#default_value' => isset($this->configuration['path']) ? $this->configuration['path'] : NULL,
    );
    $form['type'] = array(
      '#title' => t('Menu type'),
      '#type' => 'select',
      '#description' => t('Select the type of menu item to use.'),
      '#options' => array(
        MENU_CALLBACK => t('No menu item'),
        MENU_NORMAL_ITEM => t('Normal menu item'),
        MENU_LOCAL_ACTION => t('Local action'),
        MENU_LOCAL_TASK => t('Tab'),
        MENU_DEFAULT_LOCAL_TASK => t('Default tab'),
      ),
      '#default_value' => isset($this->configuration['type']) ? $this->configuration['type'] : MENU_CALLBACK,
    );
    $form['menu_name'] = array(
      '#title' => t('Menu'),
      '#type' => 'select',
      '#description' => t('Select the menu the item should be put in.'),
      '#options' => module_exists('menu') ? menu_get_menus() : menu_list_system_menus(),
      '#default_value' => isset($this->configuration['menu_name']) ? $this->configuration['menu_name'] : NULL,
      '#states' => array(
        'visible' => array(
          ':input[name="displays[flexiform_create_entity_page][type]"]' => array(
            '!value' => MENU_CALLBACK,
          ),
        ),
      ),
    );
    $form['weight'] = array(
      '#title' => t('Weight'),
      '#type' => 'weight',
      '#description' => t('Heavier items will sink and lighter items will be positioned near the top.'),
      '#default_value' => isset($this->configuration['weight']) ? $this->configuration['weight'] : 0,
      '#delta' => 30,
    );
    $form['access'] = array(
      '#type' => 'fieldset',
      '#title' => t('Access'),
      '#tree' => TRUE,
      '#description' => t('Alter settings for who can access this page. These settings will override the main flexiform access settings.'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['access']['permission'] = array(
      '#type' => 'select',
      '#title' => t('Required Permission'),
      '#description' => t('Only users with the following permission will be able to access this form. <strong>N.B. It is recommended that you use the access controls below. This option should only be used if different permissions are required for different displays.</strong>'),
      '#options' => $this
        ->getPermissionOptions(),
      '#empty_option' => t(' - None - '),
      '#default_value' => isset($this->configuration['access']['permission']) ? $this->configuration['access']['permission'] : '',
    );
    return $form;
  }

  /**
   * Get Permission Options.
   */
  protected function getPermissionOptions() {
    $options =& drupal_static('FlexiformDisplayPagePermissionOptions', array());
    if (!empty($options)) {
      return $options;
    }
    $module_info = system_get_info('module');
    $modules = array();
    foreach (module_implements('permission') as $module) {
      $modules[$module] = $module_info[$module]['name'];
      $permissions[$module] = module_invoke($module, 'permission');
    }
    foreach ($permissions as $module => $perms) {
      foreach ($perms as $perm => $info) {
        $options[$modules[$module]][$perm] = strip_tags($info['title']);
      }
    }
    return $options;
  }

  /**
   * Get the title.
   */
  public function title($context = array()) {
    return $this->configuration['title'];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlexiformDisplayBase::$flexiform protected property The Flexiform the display is for.
FlexiformDisplayBase::access public function Check the access for this form display. Overrides FlexiformDisplayInterface::access 1
FlexiformDisplayBase::build public function Build the form ready for rendering. Overrides FlexiformDisplayInterface::build 2
FlexiformDisplayBase::getBaseEntity public function Get the base entity for a flexiform. Overrides FlexiformDisplayInterface::getBaseEntity 4
FlexiformDisplayBase::getFlexiform public function Retrieve the flexiform for this display. Overrides FlexiformDisplayInterface::getFlexiform
FlexiformDisplayBase::isEnabled public function Is this display enabled. 1
FlexiformDisplayBase::__construct public function
FlexiformDisplayPageBase::configForm public function Get the configuration form. Overrides FlexiformDisplayBase::configForm 3
FlexiformDisplayPageBase::getMenuArguments protected function Get the page/title arguments for hook_menu. 2
FlexiformDisplayPageBase::getPath public function Get the path, if applicable, for the display. Overrides FlexiformDisplayBase::getPath
FlexiformDisplayPageBase::getPermissionOptions protected function Get Permission Options.
FlexiformDisplayPageBase::hook_menu public function Define the menu links 2
FlexiformDisplayPageBase::title public function Get the title. Overrides FlexiformDisplayBase::title 1