You are here

public static function InlineEntityFormSimple::isApplicable in Inline Entity Form 8

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

src/Plugin/Field/FieldWidget/InlineEntityFormSimple.php, line 185

Class

InlineEntityFormSimple
Simple inline widget.

Namespace

Drupal\inline_entity_form\Plugin\Field\FieldWidget

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) {
  $handler_settings = $field_definition
    ->getSettings()['handler_settings'];
  $target_entity_type_id = $field_definition
    ->getFieldStorageDefinition()
    ->getSetting('target_type');
  $target_entity_type = \Drupal::entityTypeManager()
    ->getDefinition($target_entity_type_id);

  // The target entity type doesn't use bundles, no need to validate them.
  if (!$target_entity_type
    ->getKey('bundle')) {
    return TRUE;
  }
  if (empty($handler_settings['target_bundles'])) {
    return FALSE;
  }
  if (count($handler_settings['target_bundles']) != 1) {
    return FALSE;
  }
  return TRUE;
}