class PrerenderList
Same name and namespace in other branches
- 11.x core/modules/views/src/Plugin/views/field/PrerenderList.php \Drupal\views\Plugin\views\field\PrerenderList
- 10 core/modules/views/src/Plugin/views/field/PrerenderList.php \Drupal\views\Plugin\views\field\PrerenderList
- 8.9.x core/modules/views/src/Plugin/views/field/PrerenderList.php \Drupal\views\Plugin\views\field\PrerenderList
Field handler to provide a list of items.
The items are expected to be loaded by a child object during preRender, and 'my field' is expected to be the pointer to the items in the list.
Items to render should be in a list in $this->items
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase extends \Drupal\views\Plugin\views\field\FieldHandlerInterface implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\field\PrerenderList extends \Drupal\views\Plugin\views\field\MultiItemsFieldHandlerInterface implements \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase extends \Drupal\views\Plugin\views\field\FieldHandlerInterface implements \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase extends \Drupal\views\Plugin\views\ViewsHandlerInterface implements \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of PrerenderList
Related topics
3 files declare their use of PrerenderList
- Permissions.php in core/
modules/ user/ src/ Plugin/ views/ field/ Permissions.php - Roles.php in core/
modules/ user/ src/ Plugin/ views/ field/ Roles.php - TaxonomyIndexTid.php in core/
modules/ taxonomy/ src/ Plugin/ views/ field/ TaxonomyIndexTid.php
File
-
core/
modules/ views/ src/ Plugin/ views/ field/ PrerenderList.php, line 18
Namespace
Drupal\views\Plugin\views\fieldView source
abstract class PrerenderList extends FieldPluginBase implements MultiItemsFieldHandlerInterface {
/**
* Stores all items which are used to render the items.
*
* It should be keyed first by the id of the base table, for example nid.
* The second key is the id of the thing which is displayed multiple times
* per row, for example the tid.
*
* @var array
*/
public $items = [];
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['type'] = [
'default' => 'separator',
];
$options['separator'] = [
'default' => ', ',
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['type'] = [
'#type' => 'radios',
'#title' => $this->t('Display type'),
'#options' => [
'ul' => $this->t('Unordered list'),
'ol' => $this->t('Ordered list'),
'separator' => $this->t('Simple separator'),
],
'#default_value' => $this->options['type'],
];
$form['separator'] = [
'#type' => 'textfield',
'#title' => $this->t('Separator'),
'#default_value' => $this->options['separator'],
'#states' => [
'visible' => [
':input[name="options[type]"]' => [
'value' => 'separator',
],
],
],
];
parent::buildOptionsForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function renderItems($items) {
if (!empty($items)) {
if ($this->options['type'] == 'separator') {
$render = [
'#type' => 'inline_template',
'#template' => '{{ items|safe_join(separator) }}',
'#context' => [
'items' => $items,
'separator' => $this->sanitizeValue($this->options['separator'], 'xss_admin'),
],
];
}
else {
$render = [
'#theme' => 'item_list',
'#items' => $items,
'#title' => NULL,
'#list_type' => $this->options['type'],
];
}
return \Drupal::service('renderer')->render($render);
}
}
/**
* {@inheritdoc}
*
* Items should be stored in the result array, if possible, as an array
* with 'value' as the actual displayable value of the item, plus
* any items that might be found in the 'alter' options array for
* creating links, such as 'path', 'fragment', 'query' etc, such a thing
* is to be made. Additionally, items that might be turned into tokens
* should also be in this array.
*/
public function getItems(ResultRow $values) {
$field = $this->getValue($values);
if (!empty($this->items[$field])) {
return $this->items[$field];
}
return [];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.