You are here

public function Editor::isCompatible in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/editor/src/Plugin/InPlaceEditor/Editor.php \Drupal\editor\Plugin\InPlaceEditor\Editor::isCompatible()

Checks whether this in-place editor is compatible with a given field.

Parameters

\Drupal\Core\Field\FieldItemListInterface $items: The field values to be in-place edited.

Return value

bool TRUE if it is compatible, FALSE otherwise.

Overrides InPlaceEditorInterface::isCompatible

File

core/modules/editor/src/Plugin/InPlaceEditor/Editor.php, line 28
Contains \Drupal\editor\Plugin\InPlaceEditor\Editor.

Class

Editor
Defines the formatted text in-place editor.

Namespace

Drupal\editor\Plugin\InPlaceEditor

Code

public function isCompatible(FieldItemListInterface $items) {
  $field_definition = $items
    ->getFieldDefinition();

  // This editor is incompatible with multivalued fields.
  if ($field_definition
    ->getFieldStorageDefinition()
    ->getCardinality() != 1) {
    return FALSE;
  }
  elseif (in_array($field_definition
    ->getType(), array(
    'text',
    'text_long',
    'text_with_summary',
  ), TRUE)) {
    if ($editor = editor_load($items[0]->format)) {
      $definition = \Drupal::service('plugin.manager.editor')
        ->getDefinition($editor
        ->getEditor());
      if ($definition['supports_inline_editing'] === TRUE) {
        return TRUE;
      }
    }
    return FALSE;
  }
}