AttachmentTestFormatter.php in Drupal 10
File
core/modules/views/tests/modules/views_test_formatter/src/Plugin/Field/FieldFormatter/AttachmentTestFormatter.php
View source
<?php
namespace Drupal\views_test_formatter\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericUnformattedFormatter;
class AttachmentTestFormatter extends NumericUnformattedFormatter {
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
$entity_id = $items
->getEntity()
->id();
$elements['#attached']['library'][] = 'foo/fake_library';
$elements['#attached']['drupalSettings']['AttachmentIntegerFormatter'][$entity_id] = $entity_id;
return $elements;
}
}