EntityReferenceTaxonomyTermRssFormatter.php in Zircon Profile 8
File
core/modules/taxonomy/src/Plugin/Field/FieldFormatter/EntityReferenceTaxonomyTermRssFormatter.php
View source
<?php
namespace Drupal\taxonomy\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase;
class EntityReferenceTaxonomyTermRssFormatter extends EntityReferenceFormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$parent_entity = $items
->getEntity();
$elements = array();
foreach ($this
->getEntitiesToView($items, $langcode) as $delta => $entity) {
$parent_entity->rss_elements[] = array(
'key' => 'category',
'value' => $entity
->label(),
'attributes' => array(
'domain' => $entity
->id() ? \Drupal::url('entity.taxonomy_term.canonical', [
'taxonomy_term' => $entity
->id(),
], array(
'absolute' => TRUE,
)) : '',
),
);
}
return $elements;
}
public static function isApplicable(FieldDefinitionInterface $field_definition) {
return $field_definition
->getFieldStorageDefinition()
->getSetting('target_type') == 'taxonomy_term';
}
}