niobi-8.x-2.0-alpha4/modules/niobi_form/modules/niobi_app/src/Plugin/Field/FieldType/NiobiAppDecisionType.php
modules/niobi_form/modules/niobi_app/src/Plugin/Field/FieldType/NiobiAppDecisionType.php
<?php
namespace Drupal\niobi_app\Plugin\Field\FieldType;
use Drupal\Component\Utility\Random;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\TypedData\DataDefinition;
/**
* Plugin implementation of the 'niobi_app_decision_type' field type.
*
* @FieldType(
* id = "niobi_app_decision_type",
* label = @Translation("Niobi Application Decision type"),
* category = @Translation("Niobi Research Center"),
* description = @Translation("Application decisions which may be selected."),
* default_widget = "niobi_app_decision_widget",
* default_formatter = "niobi_app_decision_formatter"
* )
*/
class NiobiAppDecisionType extends FieldItemBase {
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Text value'))
->addConstraint('Length', ['max' => 255])
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => 255,
],
],
'indexes' => [
'value' => ['value'],
],
];
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
return $value === NULL || $value === '';
}
/**
* {@inheritdoc}
*/
protected static function castAllowedValue($value) {
return (string) $value;
}
}
