• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

handlers/views_handler_field_contextual_links.inc

00001 <?php
00002 
00003 class views_handler_field_contextual_links extends views_handler_field {
00004   function option_definition() {
00005     $options = parent::option_definition();
00006 
00007     $options['fields'] = array('default' => array());
00008     $options['destination'] = array('default' => 1);
00009 
00010     return $options;
00011   }
00012 
00013   function options_form(&$form, &$form_state) {
00014     $all_fields = $this->view->display_handler->get_field_labels();
00015     // Offer to include only those fields that follow this one.
00016     $field_options = array_slice($all_fields, 0, array_search($this->options['id'], array_keys($all_fields)));
00017     $form['fields'] = array(
00018       '#type' => 'checkboxes',
00019       '#title' => t('Fields'),
00020       '#description' => t('Fields to be included as contextual links.'),
00021       '#options' => $field_options,
00022       '#default_value' => $this->options['fields'],
00023     );
00024     $form['destination'] = array(
00025       '#type' => 'select',
00026       '#title' => t('Include destination'),
00027       '#description' => t('Include a "destination" parameter in the link to return the user to the original view upon completing the contextual action.'),
00028       '#options' => array(
00029         '0' => t('No'),
00030         '1' => t('Yes'),
00031       ),
00032       '#default_value' => $this->options['destination'],
00033     );
00034   }
00035 
00036   function pre_render(&$values) {
00037     // Add a row plugin css class for the contextual link.
00038     $class = 'contextual-links-region';
00039     if (!empty($this->view->style_plugin->options['row_class'])) {
00040       $this->view->style_plugin->options['row_class'] .= " $class";
00041     }
00042     else {
00043       $this->view->style_plugin->options['row_class'] = $class;
00044     }
00045   }
00046 
00050   function render($values) {
00051     $links = array();
00052     foreach ($this->options['fields'] as $field) {
00053       if (empty($this->view->field[$field]->last_render_text)) {
00054         continue;
00055       }
00056       $title = $this->view->field[$field]->last_render_text;
00057       $path = '';
00058       if (!empty($this->view->field[$field]->options['alter']['path'])) {
00059         $path = $this->view->field[$field]->options['alter']['path'];
00060       }
00061       if (!empty($title)) {
00062         $links[$field] = array(
00063           'href' => $path,
00064           'title' => $title,
00065         );
00066         if (!empty($this->options['destination'])) {
00067           $links[$field]['query'] = drupal_get_destination();
00068         }
00069       }
00070     }
00071     $build = array(
00072       '#prefix' => '<div class="contextual-links-wrapper">',
00073       '#suffix' => '</div>',
00074       '#theme' => 'links__contextual',
00075       '#links' => $links,
00076       '#attributes' => array('class' => array('contextual-links')),
00077       '#attached' => array(
00078         'library' => array(array('contextual', 'contextual-links')),
00079       ),
00080       '#access' => user_access('access contextual links'),
00081     );
00082 
00083     return drupal_render($build);
00084   }
00085 
00086   function query() { }
00087 }

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1