You are here

function views_attach_plugin_display_node_content::options_form in Views attach 7.2

Same name and namespace in other branches
  1. 6.2 views_attach_plugin_display_node_content.inc \views_attach_plugin_display_node_content::options_form()
  2. 6 views_attach_plugin_display_node_content.inc \views_attach_plugin_display_node_content::options_form()

Provide the default form for setting options.

Overrides views_plugin_display::options_form

File

./views_attach_plugin_display_node_content.inc, line 77

Class

views_attach_plugin_display_node_content
The plugin that handles node-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);
  switch ($form_state['section']) {
    case 'types':
      $form['#title'] .= t('Node types');
      $form['types'] = array(
        '#type' => 'checkboxes',
        '#multiple' => TRUE,
        '#required' => TRUE,
        '#title' => t("Embed this display in the following node types"),
        '#options' => node_get_types('names'),
        '#default_value' => $this
          ->get_option('types'),
      );
      break;
    case 'modes':
      $form['#title'] .= t('Build modes');
      $form['modes'] = array(
        '#type' => 'checkboxes',
        '#title' => t("Embed this display in the following build modes"),
        '#options' => views_attach_build_modes(),
        '#default_value' => $this
          ->get_option('modes'),
      );
      break;
    case 'arguments':
      $form['#title'] .= t('Arguments');
      $default = $this
        ->get_option('argument_mode');
      $options = array(
        'none' => t("No special handling"),
        'nid' => t("Use the ID of the node 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,
      );

      // Add the extra option for Tokens if the module is enabled.
      // If it isn't, ensure that we dont' default to 'token'.
      if (module_exists('token')) {
        $form['argument_mode']['#options']['token'] = t("Use tokens from the node the view is attached to");
        $form['token_prefix'] = array(
          '#id' => 'views-attached-token-arguments',
          '#type' => 'hidden',
          '#prefix' => '<div><div id="views-attached-token-arguments">',
          '#process' => array(
            'views_process_dependency',
          ),
          '#dependency' => array(
            'radio:argument_mode' => array(
              'token',
            ),
          ),
        );
        $form['default_argument'] = array(
          '#type' => 'textfield',
          '#default_value' => $this
            ->get_option('default_argument'),
          '#description' => t('You may use token replacement to provide arguments based on the current node. Separate arguments with "/".'),
        );
        $form['token_help'] = array(
          '#type' => 'fieldset',
          '#title' => t('Replacement tokens'),
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#description' => theme('token_help', 'node'),
        );
        $form['token_suffix'] = array(
          '#value' => '</div></div>',
        );
      }
      elseif ($default == 'token') {
        $form['argument_mode']['#default_value'] = 'none';
      }
      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;
  }
}