DirectEditor.php 1.27 KB
Newer Older
1
2
3
4
<?php

/**
 * @file
5
 * Contains \Drupal\edit\Plugin\InPlaceEditor\DirectEditor.
6
7
 */

8
namespace Drupal\edit\Plugin\InPlaceEditor;
9
10

use Drupal\edit\EditorBase;
11
use Drupal\edit\Annotation\InPlaceEditor;
12
use Drupal\field\Plugin\Core\Entity\FieldInstance;
13
14

/**
15
 * Defines the direct editor.
16
 *
17
 * @InPlaceEditor(
18
19
20
21
22
23
24
 *   id = "direct",
 *   module = "edit"
 * )
 */
class DirectEditor extends EditorBase {

  /**
25
   * Implements \Drupal\edit\EditPluginInterface::isCompatible().
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
   *
   * @todo The processed text logic is too coupled to text fields. Figure out
   *   how to generalize to other textual field types.
   */
  function isCompatible(FieldInstance $instance, array $items) {
    $field = field_info_field($instance['field_name']);

    // This editor is incompatible with multivalued fields.
    if ($field['cardinality'] != 1) {
      return FALSE;
    }
    // This editor is incompatible with processed ("rich") text fields.
    elseif (!empty($instance['settings']['text_processing'])) {
      return FALSE;
    }
    else {
      return TRUE;
    }
  }

  /**
47
   * Implements \Drupal\edit\EditPluginInterface::getAttachments().
48
49
50
51
   */
  public function getAttachments() {
    return array(
      'library' => array(
52
        array('edit', 'edit.editorWidget.direct'),
53
54
55
56
      ),
    );
  }
}