JSONFormatter.php in JSON Field 8
File
src/Plugin/Field/FieldFormatter/JSONFormatter.php
View source
<?php
namespace Drupal\json_field\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
class JSONFormatter extends FormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = !empty($items) ? [
'#attached' => [
'library' => [
'json_field/json_field.formatter',
],
],
] : [];
foreach ($items as $delta => $item) {
$elements[$delta] = [
'#type' => 'json_text',
'#text' => $item->value,
'#langcode' => $langcode,
];
}
return $elements;
}
}