class LinkFormatter

Same name in this branch

Plugin implementation of the 'taxonomy_term_reference_link' formatter.

Plugin annotation


@FieldFormatter(
  id = "taxonomy_term_reference_link",
  module = "taxonomy",
  label = @Translation("Link"),
  field_types = {
    "taxonomy_term_reference"
  }
)

Hierarchy

Expanded class hierarchy of LinkFormatter

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php, line 28
Contains \Drupal\taxonomy\Plugin\field\formatter\LinkFormatter.

Namespace

Drupal\taxonomy\Plugin\field\formatter
View source
class LinkFormatter extends TaxonomyFormatterBase {

  /**
   * {@inheritdoc}
   */
  public function viewElements(EntityInterface $entity, $langcode, array $items) {
    $elements = array();

    // Terms without tid do not exist yet, theme such terms as just their name.
    foreach ($items as $delta => $item) {
      if (!$item['tid']) {
        $elements[$delta] = array(
          '#markup' => check_plain($item['entity']
            ->label()),
        );
      }
      else {
        $term = $item['entity'];
        $uri = $term
          ->uri();
        $elements[$delta] = array(
          '#type' => 'link',
          '#title' => $term
            ->label(),
          '#href' => $uri['path'],
          '#options' => $uri['options'],
        );
      }
    }
    return $elements;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormatterBase::$field protected property The field definition.
FormatterBase::$instance protected property The field instance definition.
FormatterBase::$label protected property The label display setting.
FormatterBase::$settings protected property The formatter settings. Overrides PluginSettingsBase::$settings
FormatterBase::$viewMode protected property The view mode.
FormatterBase::settingsForm public function Returns a form to configure settings for the formatter. Overrides FormatterInterface::settingsForm 12
FormatterBase::settingsSummary public function Returns a short summary for the current formatter settings. Overrides FormatterInterface::settingsSummary 12
FormatterBase::view public function Builds a renderable array for one field on one entity instance. Overrides FormatterInterface::view
FormatterBase::__construct public function Constructs a FormatterBase object. Overrides PluginBase::__construct
LinkFormatter::viewElements public function Builds a renderable array for a field value. Overrides FormatterInterface::viewElements
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginSettingsBase::$defaultSettingsMerged protected property Whether default settings have been merged into the current $settings.
PluginSettingsBase::getDefaultSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::getDefaultSettings(). Overrides PluginSettingsInterface::getDefaultSettings
PluginSettingsBase::getSetting public function Implements Drupal\field\Plugin\PluginSettingsInterface::getSetting(). Overrides PluginSettingsInterface::getSetting
PluginSettingsBase::getSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::getSettings(). Overrides PluginSettingsInterface::getSettings
PluginSettingsBase::mergeDefaults protected function Merges default settings values into $settings.
PluginSettingsBase::setSetting public function Implements Drupal\field\Plugin\PluginSettingsInterface::setSetting(). Overrides PluginSettingsInterface::setSetting
PluginSettingsBase::setSettings public function Implements Drupal\field\Plugin\PluginSettingsInterface::setSettings(). Overrides PluginSettingsInterface::setSettings
TaxonomyFormatterBase::prepareView public function Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::prepareView(). Overrides FormatterBase::prepareView