editor_note-8.x-1.x-dev/src/Plugin/Field/FieldType/EditorNoteItem.php
src/Plugin/Field/FieldType/EditorNoteItem.php
<?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')->setLabel(t('Editor Note'));
return $properties;
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
return $value === NULL || $value === '';
}
}
