public function FieldPluginBase::advancedRender in Drupal 9
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/field/FieldPluginBase.php \Drupal\views\Plugin\views\field\FieldPluginBase::advancedRender()
Renders a field using advanced settings.
This renders a field normally, then decides if render-as-link and text-replacement rendering is necessary.
Parameters
\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.
Return value
string|\Drupal\Component\Render\MarkupInterface The advanced rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.
Overrides FieldHandlerInterface::advancedRender
File
- core/
modules/ views/ src/ Plugin/ views/ field/ FieldPluginBase.php, line 1143
Class
- FieldPluginBase
- Base class for views fields.
Namespace
Drupal\views\Plugin\views\fieldCode
public function advancedRender(ResultRow $values) {
// Clean up values from previous render calls.
if ($this->lastRenderIndex != $values->index) {
$this->last_render_text = '';
}
if ($this
->allowAdvancedRender() && $this instanceof MultiItemsFieldHandlerInterface) {
$raw_items = $this
->getItems($values);
// If there are no items, set the original value to NULL.
if (empty($raw_items)) {
$this->original_value = NULL;
}
}
else {
$value = $this
->render($values);
if (is_array($value)) {
$value = $this
->getRenderer()
->render($value);
}
$this->last_render = $value;
$this->original_value = $value;
}
if ($this
->allowAdvancedRender()) {
if ($this instanceof MultiItemsFieldHandlerInterface) {
$items = [];
foreach ($raw_items as $count => $item) {
$value = $this
->render_item($count, $item);
if (is_array($value)) {
$value = (string) $this
->getRenderer()
->render($value);
}
$this->last_render = $value;
$this->original_value = $this->last_render;
$alter = $item + $this->options['alter'];
$alter['phase'] = static::RENDER_TEXT_PHASE_SINGLE_ITEM;
$items[] = $this
->renderText($alter);
}
$value = $this
->renderItems($items);
}
else {
$alter = [
'phase' => static::RENDER_TEXT_PHASE_COMPLETELY,
] + $this->options['alter'];
$value = $this
->renderText($alter);
}
if (is_array($value)) {
$value = $this
->getRenderer()
->render($value);
}
// This happens here so that renderAsLink can get the unaltered value of
// this field as a token rather than the altered value.
$this->last_render = $value;
}
// String cast is necessary to test emptiness of MarkupInterface
// objects.
if (empty((string) $this->last_render)) {
if ($this
->isValueEmpty($this->last_render, $this->options['empty_zero'], FALSE)) {
$alter = $this->options['alter'];
$alter['alter_text'] = 1;
$alter['text'] = $this->options['empty'];
$alter['phase'] = static::RENDER_TEXT_PHASE_EMPTY;
$this->last_render = $this
->renderText($alter);
}
}
// If we rendered something, update the last render index.
if ((string) $this->last_render !== '') {
$this->lastRenderIndex = $values->index;
}
return $this->last_render;
}