You are here

public static function OEmbedWidget::isApplicable in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/src/Plugin/Field/FieldWidget/OEmbedWidget.php \Drupal\media\Plugin\Field\FieldWidget\OEmbedWidget::isApplicable()
  2. 10 core/modules/media/src/Plugin/Field/FieldWidget/OEmbedWidget.php \Drupal\media\Plugin\Field\FieldWidget\OEmbedWidget::isApplicable()

Returns if the widget 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 widget can be used, FALSE otherwise.

Overrides WidgetBase::isApplicable

File

core/modules/media/src/Plugin/Field/FieldWidget/OEmbedWidget.php, line 55

Class

OEmbedWidget
Plugin implementation of the 'oembed_textfield' widget.

Namespace

Drupal\media\Plugin\Field\FieldWidget

Code

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