trait UncacheableFieldHandlerTrait

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/field/UncacheableFieldHandlerTrait.php \Drupal\views\Plugin\views\field\UncacheableFieldHandlerTrait
  2. 10 core/modules/views/src/Plugin/views/field/UncacheableFieldHandlerTrait.php \Drupal\views\Plugin\views\field\UncacheableFieldHandlerTrait
  3. 11.x core/modules/views/src/Plugin/views/field/UncacheableFieldHandlerTrait.php \Drupal\views\Plugin\views\field\UncacheableFieldHandlerTrait

Trait encapsulating the logic for uncacheable field handlers.

Hierarchy

1 file declares its use of UncacheableFieldHandlerTrait
FieldFormButtonTest.php in core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php

File

core/modules/views/src/Plugin/views/field/UncacheableFieldHandlerTrait.php, line 10

Namespace

Drupal\views\Plugin\views\field
View source
trait UncacheableFieldHandlerTrait {
    
    /**
     * {@inheritdoc}
     *
     * @see \Drupal\views\Plugin\views\Field\FieldHandlerInterface::render()
     */
    public function render(ResultRow $row) {
        return $this->getFieldTokenPlaceholder();
    }
    
    /**
     * {@inheritdoc}
     *
     * @see \Drupal\views\Plugin\views\Field\FieldHandlerInterface::postRender()
     */
    public function postRender(ResultRow $row, $output) {
        $placeholder = $this->getFieldTokenPlaceholder();
        $value = $this->doRender($row);
        $this->last_render = str_replace($placeholder, $value, $output);
        return [
            $placeholder => $value,
        ];
    }
    
    /**
     * {@inheritdoc}
     *
     * @see \Drupal\views\Plugin\views\Field\FieldPluginBase::getFieldTokenPlaceholder()
     */
    protected abstract function getFieldTokenPlaceholder();
    
    /**
     * Actually renders the field markup.
     *
     * @param \Drupal\views\ResultRow $row
     *   A result row.
     *
     * @return string
     *   The field markup.
     */
    protected function doRender(ResultRow $row) {
        return $this->getValue($row);
    }
    
    /**
     * {@inheritdoc}
     *
     * @see \Drupal\views\Plugin\views\Field\FieldHandlerInterface::getValue()
     */
    protected abstract function getValue(ResultRow $row, $field = NULL);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
UncacheableFieldHandlerTrait::doRender protected function Actually renders the field markup.
UncacheableFieldHandlerTrait::getFieldTokenPlaceholder abstract protected function
UncacheableFieldHandlerTrait::getValue abstract protected function 3
UncacheableFieldHandlerTrait::postRender public function
UncacheableFieldHandlerTrait::render public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.