TextDefaultFormatter.php in Drupal 8
Same filename and directory in other branches
Namespace
Drupal\text\Plugin\Field\FieldFormatterFile
core/modules/text/src/Plugin/Field/FieldFormatter/TextDefaultFormatter.phpView source
<?php
namespace Drupal\text\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
/**
* Plugin implementation of the 'text_default' formatter.
*
* @FieldFormatter(
* id = "text_default",
* label = @Translation("Default"),
* field_types = {
* "text",
* "text_long",
* "text_with_summary",
* }
* )
*/
class TextDefaultFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
// The ProcessedText element already handles cache context & tag bubbling.
// @see \Drupal\filter\Element\ProcessedText::preRenderText()
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#type' => 'processed_text',
'#text' => $item->value,
'#format' => $item->format,
'#langcode' => $item
->getLangcode(),
];
}
return $elements;
}
}
Classes
Name | Description |
---|---|
TextDefaultFormatter | Plugin implementation of the 'text_default' formatter. |