AttachmentTestFormatter.php
Same filename in other branches
- 9 core/modules/views/tests/modules/views_test_formatter/src/Plugin/Field/FieldFormatter/AttachmentTestFormatter.php
- 8.9.x core/modules/views/tests/modules/views_test_formatter/src/Plugin/Field/FieldFormatter/AttachmentTestFormatter.php
- 11.x core/modules/views/tests/modules/views_test_formatter/src/Plugin/Field/FieldFormatter/AttachmentTestFormatter.php
Namespace
Drupal\views_test_formatter\Plugin\Field\FieldFormatterFile
-
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\Attribute\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\NumericUnformattedFormatter;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Plugin implementation of the 'number_unformatted_with_attachment' formatter.
*/
class AttachmentTestFormatter extends NumericUnformattedFormatter {
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
// Add dummy attachments.
$entity_id = $items->getEntity()
->id();
$elements['#attached']['library'][] = 'foo/fake_library';
$elements['#attached']['drupalSettings']['AttachmentIntegerFormatter'][$entity_id] = $entity_id;
return $elements;
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
AttachmentTestFormatter | Plugin implementation of the 'number_unformatted_with_attachment' formatter. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.