You are here

function eva_plugin_display_entity::options_form in EVA: Entity Views Attachment 7

Provide the default form for setting options.

Overrides views_plugin_display::options_form

File

./eva_plugin_display_entity.inc, line 99

Class

eva_plugin_display_entity
The plugin that handles entity-attached views.

Code

function options_form(&$form, &$form_state) {

  // It is very important to call the parent function here:
  parent::options_form($form, $form_state);
  $entity_info = entity_get_info();
  $entity_type = $this
    ->get_option('entity_type');
  switch ($form_state['section']) {
    case 'entity_type':
      $entity_names = array();
      foreach ($entity_info as $type => $info) {
        if (!empty($info['view modes'])) {
          $entity_names[$type] = $info['label'];
        }
      }
      $form['#title'] .= t('Entity type');
      $form['entity_type'] = array(
        '#type' => 'radios',
        '#required' => TRUE,
        '#title' => t("Attach this display to the following entity type"),
        '#options' => $entity_names,
        '#default_value' => $this
          ->get_option('entity_type'),
      );
      break;
    case 'bundles':
      $options = array();
      foreach ($entity_info[$entity_type]['bundles'] as $bundle => $info) {
        $options[$bundle] = $info['label'];
      }
      $form['#title'] .= t('Bundles');
      $form['bundles'] = array(
        '#type' => 'checkboxes',
        '#title' => t("Attach this display to the following bundles.  If no bundles are selected, the display will be attached to all."),
        '#options' => $options,
        '#default_value' => $this
          ->get_option('bundles'),
      );
      break;
    case 'show_on':
      $form['#title'] .= t('Show on');
      $form['show_on'] = array(
        '#type' => 'select',
        '#title' => t('Where to show this view'),
        '#description' => t('This view can be used on either the entity display or on the entity form. When shown on a form, the exposed filters will be hidden.'),
        '#options' => array(
          'display' => t('Display'),
          'form' => t('Form'),
        ),
        '#required' => TRUE,
        '#default_value' => $this
          ->get_option('show_on'),
      );
      break;
    case 'arguments':
      $form['#title'] .= t('Arguments');
      $default = $this
        ->get_option('argument_mode');
      $options = array(
        'none' => t("No special handling"),
        'id' => t("Use the ID of the entity the view is attached to"),
        'token' => t("Use tokens from the entity the view is attached to"),
      );
      $form['argument_mode'] = array(
        '#type' => 'radios',
        '#title' => t("How should this display populate the view's arguments?"),
        '#options' => $options,
        '#default_value' => $default,
      );
      $form['token'] = array(
        '#type' => 'fieldset',
        '#title' => t('Token replacement'),
        '#collapsible' => TRUE,
        '#states' => array(
          'visible' => array(
            ':input[name=argument_mode]' => array(
              'value' => 'token',
            ),
          ),
        ),
      );
      $form['token']['default_argument'] = array(
        '#title' => t('Arguments'),
        '#type' => 'textfield',
        '#default_value' => $this
          ->get_option('default_argument'),
        '#description' => t('You may use token replacement to provide arguments based on the current entity. Separate arguments with "/".'),
      );
      if (module_exists('token')) {
        $form['token']['tokens'] = array(
          '#theme' => 'token_tree',
          '#token_types' => array(
            token_get_entity_mapping('entity', $entity_type),
          ),
        );
      }
      break;
    case 'show_title':
      $form['#title'] .= t('Show title');
      $form['show_title'] = array(
        '#type' => 'checkbox',
        '#title' => t('Show the title of the view above the attached view.'),
        '#default_value' => $this
          ->get_option('show_title'),
      );
      break;
    case 'exposed_form_as_field':
      $form['#title'] .= t('Exposed Form as Field');
      $form['exposed_form_as_field'] = array(
        '#type' => 'checkbox',
        '#title' => t('Split off Exposed Form as Separate Field'),
        '#default_value' => $this
          ->get_option('exposed_form_as_field'),
        '#description' => t('Check this box to have a separate field for this view\'s exposed form on the "Manage Display" tab. This is not available to EVAs attached to the form.'),
      );
  }
}