function OEmbedFormatter::isApplicable

Same name in other branches
  1. 9 core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php \Drupal\media\Plugin\Field\FieldFormatter\OEmbedFormatter::isApplicable()
  2. 8.9.x core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php \Drupal\media\Plugin\Field\FieldFormatter\OEmbedFormatter::isApplicable()
  3. 11.x core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php \Drupal\media\Plugin\Field\FieldFormatter\OEmbedFormatter::isApplicable()

Overrides FormatterBase::isApplicable

File

core/modules/media/src/Plugin/Field/FieldFormatter/OEmbedFormatter.php, line 337

Class

OEmbedFormatter
Plugin implementation of the 'oembed' formatter.

Namespace

Drupal\media\Plugin\Field\FieldFormatter

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) {
    if ($field_definition->getTargetEntityTypeId() !== 'media') {
        return FALSE;
    }
    if (parent::isApplicable($field_definition)) {
        $media_type = $field_definition->getTargetBundle();
        if ($media_type) {
            $media_type = MediaType::load($media_type);
            return $media_type && $media_type->getSource() instanceof OEmbedInterface;
        }
    }
    return FALSE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.