ViewsSystemRequires.php in Views System 8
File
src/Plugin/views/field/ViewsSystemRequires.php
View source
<?php
namespace Drupal\views_system\Plugin\views\field;
use Drupal\views\Plugin\views\field\PrerenderList;
class ViewsSystemRequires extends PrerenderList {
public function preRender(&$values) {
$this->items = array();
foreach ($values as $result) {
$field = $this
->getValue($result);
if (!empty($field) && !isset($this->items[$field])) {
foreach (unserialize($field) as $item) {
$name = $item['name'];
$label = db_query('SELECT label FROM {views_system} WHERE name = :name', array(
':name' => $name,
))
->fetchField();
$this->items[$field][$name]['label'] = $label;
$this->items[$field][$name]['name'] = $name;
}
}
}
}
function render_item($count, $item) {
return $item['label'];
}
protected function documentSelfTokens(&$tokens) {
$tokens['{{ ' . $this->options['id'] . '__label' . ' }}'] = $this
->t('The human readable name of the item.');
$tokens['{{ ' . $this->options['id'] . '__name' . ' }}'] = $this
->t('The machine-name of the item.');
}
protected function addSelfTokens(&$tokens, $item) {
if (!empty($item['name'])) {
$tokens['{{ ' . $this->options['id'] . '__label' . ' }}'] = $item['label'];
$tokens['{{ ' . $this->options['id'] . '__name' . ' }}'] = $item['name'];
}
}
}