3 namespace Drupal\taxonomy\Plugin\Field\FieldFormatter;
5 use Drupal\Core\Field\FieldDefinitionInterface;
6 use Drupal\Core\Field\FieldItemListInterface;
7 use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
10 * Plugin implementation of the 'entity reference taxonomy term RSS' formatter.
13 * id = "entity_reference_rss_category",
14 * label = @Translation("RSS category"),
15 * description = @Translation("Display reference to taxonomy term in RSS."),
21 class EntityReferenceTaxonomyTermRssFormatter extends EntityReferenceFormatterBase {
26 public function viewElements(FieldItemListInterface $items, $langcode) {
27 $parent_entity = $items->getEntity();
30 foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
31 $parent_entity->rss_elements[] = [
33 'value' => $entity->label(),
35 'domain' => $entity->id() ? \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $entity->id()], ['absolute' => TRUE]) : '',
46 public static function isApplicable(FieldDefinitionInterface $field_definition) {
47 // This formatter is only available for taxonomy terms.
48 return $field_definition->getFieldStorageDefinition()->getSetting('target_type') == 'taxonomy_term';