Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 22 |
| Path | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 22 |
| init | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| defineOptions | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| buildOptionsForm | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 9 |
|||
| query | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| render | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
|||
| <?php | |
| /** | |
| * @file | |
| * Contains \Drupal\node\Plugin\views\field\Path. | |
| */ | |
| namespace Drupal\node\Plugin\views\field; | |
| use Drupal\Core\Form\FormStateInterface; | |
| use Drupal\views\Plugin\views\field\FieldPluginBase; | |
| use Drupal\views\Plugin\views\display\DisplayPluginBase; | |
| use Drupal\views\ResultRow; | |
| use Drupal\views\ViewExecutable; | |
| /** | |
| * Field handler to present the path to the node. | |
| * | |
| * @ingroup views_field_handlers | |
| * | |
| * @ViewsField("node_path") | |
| */ | |
| class Path extends FieldPluginBase { | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { | |
| parent::init($view, $display, $options); | |
| $this->additional_fields['nid'] = 'nid'; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| protected function defineOptions() { | |
| $options = parent::defineOptions(); | |
| $options['absolute'] = array('default' => FALSE); | |
| return $options; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function buildOptionsForm(&$form, FormStateInterface $form_state) { | |
| parent::buildOptionsForm($form, $form_state); | |
| $form['absolute'] = array( | |
| '#type' => 'checkbox', | |
| '#title' => $this->t('Use absolute link (begins with "http://")'), | |
| '#default_value' => $this->options['absolute'], | |
| '#description' => $this->t('Enable this option to output an absolute link. Required if you want to use the path as a link destination (as in "output this field as a link" above).'), | |
| '#fieldset' => 'alter', | |
| ); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function query() { | |
| $this->ensureMyTable(); | |
| $this->addAdditionalFields(); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function render(ResultRow $values) { | |
| $nid = $this->getValue($values, 'nid'); | |
| return \Drupal::url('entity.node.canonical', ['node' => $nid], ['absolute' => $this->options['absolute']]); | |
| } | |
| } |