You are here

EditorNoteItem.php in Editor Notes 8

File

src/Plugin/Field/FieldType/EditorNoteItem.php
View source
<?php

namespace Drupal\editor_note\Plugin\Field\FieldType;

use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;

/**
 * Provides a field type of editor note.
 *
 * @FieldType(
 *   id = "editor_note_item",
 *   label = @Translation("Editor Note"),
 *   description = @Translation("A field containing an editor note."),
 *   default_widget = "editor_note_widget",
 *   default_formatter = "editor_note_table_formatter",
 *   module = "editor_note",
 *   cardinality = 1,
 * )
 */
class EditorNoteItem extends FieldItemBase implements FieldItemInterface {

  /**
   * {@inheritdoc}
   */
  public static function schema(FieldStorageDefinitionInterface $field_definition) {
    return [
      'columns' => [
        'value' => [
          'type' => 'varchar',
          'length' => 256,
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
    $properties['value'] = DataDefinition::create('string');
    return $properties;
  }

  /**
   * {@inheritdoc}
   */
  public function isEmpty() {
    $value = $this
      ->get('value')
      ->getValue();
    return $value === NULL || $value === '';
  }

}

Classes

Namesort descending Description
EditorNoteItem Provides a field type of editor note.