public function TokenBase::build in Display Suite 8.4
Same name and namespace in other branches
- 8.2 src/Plugin/DsField/TokenBase.php \Drupal\ds\Plugin\DsField\TokenBase::build()
- 8.3 src/Plugin/DsField/TokenBase.php \Drupal\ds\Plugin\DsField\TokenBase::build()
Renders a field.
Return value
array A renderable array representing the content of the field.
Overrides DsFieldBase::build
1 method overrides TokenBase::build()
- DynamicTwigField::build in src/
Plugin/ DsField/ DynamicTwigField.php - Renders a field.
File
- src/
Plugin/ DsField/ TokenBase.php, line 55
Class
- TokenBase
- The base plugin to create DS code fields.
Namespace
Drupal\ds\Plugin\DsFieldCode
public function build() {
$content = $this
->content();
$format = $this
->format();
// Get the current code for current language.
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
$value = $this->token
->replace($content, [
$this
->getEntityTypeId() => $this
->entity(),
], [
'langcode' => $langcode,
'clear' => TRUE,
]);
// Empty string in token fields treated as empty field.
if ($value === '') {
return [];
}
return [
'#type' => 'processed_text',
'#text' => $value,
'#format' => $format,
'#filter_types_to_skip' => [],
'#langcode' => $langcode,
];
}