예제 #1
0
 /**
  * Tests _contextual_links_to_id().
  */
 function testContextualLinksToId()
 {
     $tests = $this->_contextual_links_id_testcases();
     foreach ($tests as $test) {
         $this->assertIdentical(_contextual_links_to_id($test['links']), $test['id']);
     }
 }
예제 #2
0
 /**
  * Add quickedit attribute for bundle
  *
  * @param $crawler
  *   crawler instance of class Crawler - Symfony
  *
  * @return
  *   crawler instance with update html
  */
 public function addQuickeditAttributeForBundle($crawler, $component)
 {
     $bundle = $component->bundle();
     $quickedit = 'component/' . $component->id();
     $bundle_layer = $crawler->filter('[data-component="' . $bundle . '"]');
     $bundle_layer->setAttribute(QE_ENTITY_ID, $quickedit)->addClass('contextual-region');
     $build_contextual_links['#contextual_links']['component'] = array('route_parameters' => array('component' => $component->id()), 'metadata' => array('changed' => $component->getChangedTime()));
     $contextual_links['contextual_links'] = array('#type' => 'contextual_links_placeholder', '#id' => _contextual_links_to_id($build_contextual_links['#contextual_links']));
     $render_contextual_links = render($contextual_links)->__toString();
     $bundle_layer->prepend($render_contextual_links);
     return $crawler;
 }
예제 #3
0
 /**
  * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render().
  *
  * Renders the contextual fields.
  *
  * @param \Drupal\views\ResultRow $values
  *   The values retrieved from a single row of a view's query result.
  *
  * @see contextual_preprocess()
  * @see contextual_contextual_links_view_alter()
  */
 public function render(ResultRow $values)
 {
     $links = array();
     foreach ($this->options['fields'] as $field) {
         $rendered_field = $this->view->style_plugin->getField($values->index, $field);
         if (empty($rendered_field)) {
             continue;
         }
         $title = $this->view->field[$field]->last_render_text;
         $path = '';
         if (!empty($this->view->field[$field]->options['alter']['path'])) {
             $path = $this->view->field[$field]->options['alter']['path'];
         } elseif (!empty($this->view->field[$field]->options['alter']['url']) && $this->view->field[$field]->options['alter']['url'] instanceof Url) {
             $path = $this->view->field[$field]->options['alter']['url']->toString();
         }
         if (!empty($title) && !empty($path)) {
             // Make sure that tokens are replaced for this paths as well.
             $tokens = $this->getRenderTokens(array());
             $path = strip_tags(Html::decodeEntities(strtr($path, $tokens)));
             $links[$field] = array('href' => $path, 'title' => $title);
             if (!empty($this->options['destination'])) {
                 $links[$field]['query'] = $this->getDestinationArray();
             }
         }
     }
     // Renders a contextual links placeholder.
     if (!empty($links)) {
         $contextual_links = array('contextual' => array('', array(), array('contextual-views-field-links' => UrlHelper::encodePath(Json::encode($links)))));
         $element = array('#type' => 'contextual_links_placeholder', '#id' => _contextual_links_to_id($contextual_links));
         return drupal_render($element);
     } else {
         return '';
     }
 }