You are here

EntityReferenceFacetLink.php in Entity Reference Facet Link 8

File

src/Plugin/Field/FieldFormatter/EntityReferenceFacetLink.php
View source
<?php

namespace Drupal\entity_reference_facet_link\Plugin\Field\FieldFormatter;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;

/**
 * Plugin implementation of the 'entity reference facet link' formatter.
 *
 * @FieldFormatter(
 *   id = "entity_reference_facet_link",
 *   label = @Translation("Facet link"),
 *   description = @Translation("Display the label of the referenced entities linked to a faceted search."),
 *   field_types = {
 *     "entity_reference"
 *   }
 * )
 */
class EntityReferenceFacetLink extends EntityReferenceFacetFormatterBase {

  /**
   * {@inheritdoc}
   */
  protected function buildElement(Url $url, EntityInterface $entity) {
    return [
      '#type' => 'link',
      '#title' => $entity
        ->label(),
      '#url' => $url,
    ];
  }

}

Classes

Namesort descending Description
EntityReferenceFacetLink Plugin implementation of the 'entity reference facet link' formatter.