You are here

function views_view_field_handler_include_view::options_form in Views PDF 7

Same name and namespace in other branches
  1. 8 modules/views_view_field/views_view_field_handler_include_view.inc \views_view_field_handler_include_view::options_form()
  2. 6 modules/views_view_field/views_view_field_handler_include_view.inc \views_view_field_handler_include_view::options_form()
  3. 7.3 modules/views_view_field/views_view_field_handler_include_view.inc \views_view_field_handler_include_view::options_form()
  4. 7.2 modules/views_view_field/views_view_field_handler_include_view.inc \views_view_field_handler_include_view::options_form()

Settings form

Overrides views_handler_field::options_form

File

modules/views_view_field/views_view_field_handler_include_view.inc, line 38
Plugin for the views include field

Class

views_view_field_handler_include_view
This class contains the functionality to add a view as a new field in another view.

Code

function options_form(&$form, &$form_state) {
  parent::options_form($form, $form_state);
  $views = views_get_all_views();
  foreach ($views as $key => $view) {
    if ($this->view->name != $view->name) {
      $view_options[$key] = $view->name;
    }
  }
  $form['view'] = array(
    '#type' => 'select',
    '#title' => t('View to include'),
    '#options' => $view_options,
    '#default_value' => $this->options['view'],
    '#description' => t('Select the view to include. The display will be automatically determined.'),
  );
  $form['number_of_args'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter the number of arguments'),
    '#default_value' => $this->options['number_of_args'],
    '#description' => t('Enter the number of arguments you want to pass to the view.'),
  );
  for ($i = 0; $this->options['number_of_args'] > $i; $i++) {
    $form['args'][$i] = array(
      '#type' => 'textfield',
      '#title' => t('Argument #%number', array(
        '%number' => $i + 1,
      )),
      '#default_value' => $this->options['args'][$i],
      '#description' => t('Enter here the argument to pass to the view. If you want to use a value from a field, then use the replacement patterns in <strong>Rewrite results</strong> below.'),
    );
  }

  // Get a list of the available fields and arguments for token replacement.
  $options = array();
  foreach ($this->view->display_handler
    ->get_handlers('field') as $field => $handler) {

    // We only use fields up to (and excluding) this one.
    if ($field == $this->options['id']) {
      break;
    }
    $options[t('Fields')]["[{$field}]"] = $handler
      ->ui_name();
  }
  $count = 0;

  // This lets us prepare the key as we want it printed.
  foreach ($this->view->display_handler
    ->get_handlers('argument') as $arg => $handler) {
    $options[t('Arguments')]['%' . ++$count] = t('@argument title', array(
      '@argument' => $handler
        ->ui_name(),
    ));
    $options[t('Arguments')]['!' . $count] = t('@argument input', array(
      '@argument' => $handler
        ->ui_name(),
    ));
  }
  $this
    ->document_self_tokens($options[t('Fields')]);

  // Default text.
  $output = t('<p>You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');

  // We have some options, so make a list.
  if (!empty($options)) {
    $output = t('<p>The following substitution patterns are available for this display. Use the pattern shown on the left to display the value indicated on the right. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');
    foreach (array_keys($options) as $type) {
      if (!empty($options[$type])) {
        $items = array();
        foreach ($options[$type] as $key => $value) {
          $items[] = $key . ' == ' . $value;
        }
        $output .= theme('item_list', array(
          'items' => $items,
          'title' => $type,
        ));
      }
    }
  }

  // This construct uses 'hidden' and not markup because process doesn't
  // run. It also has an extra div because the dependency wants to hide
  // the parent in situations like this, so we need a second div to
  // make this work.
  $form['alter']['help'] = array(
    '#type' => 'hidden',
    '#id' => 'views-tokens-help',
    '#prefix' => '<div><fieldset id="views-tokens-help"><legend>' . t('Replacement patterns') . '</legend>' . $output . '</fieldset></div>',
  );
}