EntityLink.php in Zircon Profile 8.0
File
core/modules/comment/src/Plugin/views/field/EntityLink.php
View source
<?php
namespace Drupal\comment\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
class EntityLink extends FieldPluginBase {
protected $build;
protected function defineOptions() {
$options = parent::defineOptions();
$options['teaser'] = array(
'default' => FALSE,
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['teaser'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Show teaser-style link'),
'#default_value' => $this->options['teaser'],
'#description' => $this
->t('Show the comment link in the form used on standard entity teasers, rather than the full entity form.'),
);
parent::buildOptionsForm($form, $form_state);
}
public function query() {
}
public function preRender(&$values) {
$entities = array();
foreach ($values as $row) {
$entity = $row->_entity;
$entities[$entity
->id()] = $entity;
}
if ($entities) {
$this->build = entity_view_multiple($entities, $this->options['teaser'] ? 'teaser' : 'full');
}
}
public function render(ResultRow $values) {
$entity = $this
->getEntity($values);
return !empty($this->build[$entity
->id()]['links']['comment__comment']) ? drupal_render($this->build[$entity
->id()]['links']['comment__comment']) : '';
}
}
Classes
Name |
Description |
EntityLink |
Handler for showing comment module's entity links. |