ContextItem.php in Core Context 8
File
src/Plugin/Field/FieldType/ContextItem.php
View source
<?php
namespace Drupal\core_context\Plugin\Field\FieldType;
use Drupal\Component\Plugin\Context\Context;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\DataDefinition;
final class ContextItem extends FieldItemBase {
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$definitions = [];
$definitions['id'] = DataDefinition::create('string')
->setRequired(TRUE)
->setLabel(new TranslatableMarkup('Context ID'));
$definitions['type'] = DataDefinition::create('string')
->setRequired(TRUE)
->setLabel(new TranslatableMarkup('Data type'));
$definitions['label'] = DataDefinition::create('string')
->setRequired(TRUE)
->setLabel(new TranslatableMarkup('Label'));
$definitions['description'] = DataDefinition::create('string')
->setLabel(new TranslatableMarkup('Description'));
$definitions['value'] = DataDefinition::create('any')
->setRequired(TRUE)
->setLabel(new TranslatableMarkup('Value'));
return $definitions;
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'id' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
'type' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
'label' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
'description' => [
'type' => 'text',
'size' => 'normal',
],
'value' => [
'type' => 'blob',
'size' => 'normal',
'serialize' => TRUE,
'not null' => TRUE,
],
],
];
}
}
Classes
Name |
Description |
ContextItem |
Plugin implementation of the 'context' field type. |