You are here

public function TypeStyle::postRender in Type Style 8

Runs after every field has been rendered.

This is meant to be used mainly to deal with field handlers whose output cannot be cached at row level but can be cached at display level. The typical example is the row counter. For completely uncacheable field output placeholders should be used.

Parameters

\Drupal\views\ResultRow $row: An array of all ResultRow objects returned from the query.

$output: The field rendered output.

Return value

string[] An associative array of post-render token values keyed by placeholder.

Overrides FieldPluginBase::postRender

See also

\Drupal\views\Plugin\views\field\UncacheableFieldHandlerTrait

File

src/Plugin/views/field/TypeStyle.php, line 83

Class

TypeStyle
A handler to output and arbitrary type style.

Namespace

Drupal\type_style\Plugin\views\field

Code

public function postRender(ResultRow $row, $output) {
  parent::postRender($row, $output);
  $style_name = $this
    ->getStyleName();
  $render = $this
    ->render($row);
  $replacements = [
    'data-type-style-color-' . $style_name => 'style="color: ' . $render . '"',
    'data-type-style-background-color-' . $style_name => 'style="background-color: ' . $render . '"',
  ];
  if ($style_name === 'color') {
    $replacements['data-type-style-color'] = 'style="color: ' . $render . '"';
    $replacements['data-type-style-background-color'] = 'style="background-color: ' . $render . '"';
  }
  return $replacements;
}