You are here

class views_view_field_handler_include_view in Views PDF 6

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
  2. 7.3 modules/views_view_field/views_view_field_handler_include_view.inc \views_view_field_handler_include_view
  3. 7 modules/views_view_field/views_view_field_handler_include_view.inc \views_view_field_handler_include_view
  4. 7.2 modules/views_view_field/views_view_field_handler_include_view.inc \views_view_field_handler_include_view

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

Hierarchy

Expanded class hierarchy of views_view_field_handler_include_view

1 string reference to 'views_view_field_handler_include_view'
views_view_field_views_data in modules/views_view_field/views_view_field.views.inc
Implemenation of hook_views_data()

File

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

View source
class views_view_field_handler_include_view extends views_handler_field {

  /**
   * Query the view. Deactivated because we do not want to query anything.
   */
  function query() {

    // Override parent::query() and don't alter query.
    $this->field_alias = 'view_include_' . $this->position;
  }

  /**
   * Definitions of the views field options.
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['view'] = array(
      'default' => '',
    );
    $options['number_of_args'] = array(
      'default' => 1,
    );
    $options['args'] = array(
      'default' => array(),
    );
    return $options;
  }

  /**
   * Settings form
   */
  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 determine.'),
    );
    $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('Arguement #%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 replacements 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', $items, $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>',
    );
  }

  /**
   * Renders the field. For rendering the new views is created an added. For
   * PDF displays the two PDF classes where merged.
   */
  function render($values) {
    if (!empty($this->options['exclude'])) {
      return '';
    }
    $displayType = $this->view->display_handler
      ->get_style_type();
    $currentDisplay = $this->view->current_display;
    $tokens = $this
      ->get_render_tokens('');
    $args = array();
    foreach ($this->options['args'] as $arg) {
      $args[] = str_replace(array_keys($tokens), $tokens, $arg);
    }
    $view_name = $this->options['view'];
    $view = views_get_view($view_name);
    $view
      ->set_arguments($args);

    // Try same display as the current
    if (!$view
      ->set_display($currentDisplay)) {

      // Try the display type
      if (!$view
        ->set_display($displayType . '_1')) {

        // Use the default:
        $view
          ->init_display();
      }
    }
    $view
      ->pre_execute();
    $view
      ->execute();
    $view
      ->init_style();

    // Important only for pdf views. With this action we assign the
    // PDF document to the new view
    if (isset($this->view->pdf) && is_object($this->view->pdf)) {
      $view->pdf =& $this->view->pdf;
    }
    if (is_object($view->style_plugin)) {
      return $view->style_plugin
        ->render();
    }
    else {
      return 'style plugin not found';
    }
  }
  function allow_advanced_render() {
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_view_field_handler_include_view::allow_advanced_render function
views_view_field_handler_include_view::options_form function Settings form
views_view_field_handler_include_view::option_definition function Definitions of the views field options.
views_view_field_handler_include_view::query function Query the view. Deactivated because we do not want to query anything.
views_view_field_handler_include_view::render function Renders the field. For rendering the new views is created an added. For PDF displays the two PDF classes where merged.