public static function EntityReferenceDisplayFormatterTrait::isApplicable in Entity Reference Display 8
File
- src/
Plugin/ Field/ FieldFormatter/ EntityReferenceDisplayFormatterTrait.php, line 88
Class
- EntityReferenceDisplayFormatterTrait
- Plugin trait for the 'entity_reference_display' formatters.
Namespace
Drupal\entity_reference_display\Plugin\Field\FieldFormatterCode
public static function isApplicable(FieldDefinitionInterface $field_definition) {
// Get all fields associated with current entity.
$entity_type = $field_definition
->getTargetEntityTypeId();
$entity_bundle = $field_definition
->getTargetBundle();
if (!empty($entity_bundle)) {
$entity_fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions($entity_type, $entity_bundle);
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field */
foreach ($entity_fields as $field) {
// Formatter is only available for entity types with display mode field.
if ($field
->getType() == 'entity_reference_display') {
return TRUE;
}
}
}
return FALSE;
}