You are here

public function TextareaWidget::isApplicable in Typed Data API enhancements 8

Returns if the widget can be used for the provided data.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface $definition: The definition of the edited data.

Return value

bool Whether the data can be edited with the widget.

Overrides FormWidgetInterface::isApplicable

File

src/Plugin/TypedDataFormWidget/TextareaWidget.php, line 46

Class

TextareaWidget
Plugin implementation of the 'textarea' widget.

Namespace

Drupal\typed_data\Plugin\TypedDataFormWidget

Code

public function isApplicable(DataDefinitionInterface $definition) {
  if (is_subclass_of($definition
    ->getClass(), StringInterface::class)) {
    $result = TRUE;

    // Never use textarea for editing dates, durations, e-mail or URIs.
    $classes = [
      DateTimeInterface::class,
      DurationInterface::class,
      Email::class,
      UriInterface::class,
    ];
    foreach ($classes as $class) {
      $result = $result && !is_subclass_of($definition
        ->getClass(), $class) && $definition
        ->getClass() != $class;
    }
    return $result;
  }
  else {
    return FALSE;
  }
}