You are here

public static function LinkAllyFormatter::isApplicable in Element Class Formatter 8

Returns if the formatter can be used for the provided field.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition that should be checked.

Return value

bool TRUE if the formatter can be used, FALSE otherwise.

Overrides FormatterBase::isApplicable

File

src/Plugin/Field/FieldFormatter/LinkAllyFormatter.php, line 184

Class

LinkAllyFormatter
Defines a formatter that allows links with screenreader only text.

Namespace

Drupal\element_class_formatter\Plugin\Field\FieldFormatter

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) {
  $manager = \Drupal::entityTypeManager();
  $type_id = $field_definition
    ->getTargetEntityTypeId();

  // Either this is a link field, or this is an entity-type that has a
  // canonical route.
  return parent::isApplicable($field_definition) && ($field_definition
    ->getType() === 'link' || $manager
    ->hasDefinition($type_id) && ($type = $manager
    ->getDefinition($type_id)) && $type
    ->hasLinkTemplate('canonical'));
}