YamlFormEntityReferenceItem.php in YAML Form 8
File
src/Plugin/Field/FieldType/YamlFormEntityReferenceItem.php
View source
<?php
namespace Drupal\yamlform\Plugin\Field\FieldType;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TypedData\DataDefinition;
class YamlFormEntityReferenceItem extends EntityReferenceItem {
public static function defaultStorageSettings() {
return [
'target_type' => 'yamlform',
] + parent::defaultStorageSettings();
}
public static function defaultFieldSettings() {
return [
'default_data' => '',
'status' => TRUE,
] + parent::defaultFieldSettings();
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'target_id' => [
'description' => 'The ID of the form entity.',
'type' => 'varchar_ascii',
'length' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
],
'default_data' => [
'description' => 'Default submission data.',
'type' => 'text',
],
'status' => [
'description' => 'Flag to control whether this form should be open or closed to new submissions.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'default' => 1,
],
],
'indexes' => [
'target_id' => [
'target_id',
],
],
];
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$properties['default_data'] = DataDefinition::create('string')
->setLabel(t('Default submission data'));
$properties['status'] = DataDefinition::create('boolean')
->setLabel(t('Status'))
->setDescription(t('Flag to control whether this form should be open or closed to new submissions.'));
return $properties;
}
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
return [];
}
public static function getPreconfiguredOptions() {
return [];
}
}