Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
148
vendor/chi-teck/drupal-code-generator/templates/d8/_field/default-formatter.twig
vendored
Normal file
148
vendor/chi-teck/drupal-code-generator/templates/d8/_field/default-formatter.twig
vendored
Normal file
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldFormatter;
|
||||
|
||||
{% sort %}
|
||||
{% if datetime %}
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
{% endif %}
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FormatterBase;
|
||||
{% if formatter_settings %}
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
{% endif %}
|
||||
{% if link %}
|
||||
use Drupal\Core\Url;
|
||||
{% endif %}
|
||||
{% if list %}
|
||||
use Drupal\{{ machine_name }}\Plugin\Field\FieldType\{{ type_class }};
|
||||
{% endif %}
|
||||
{% endsort %}
|
||||
|
||||
/**
|
||||
* Plugin implementation of the '{{ field_id }}_default' formatter.
|
||||
*
|
||||
* @FieldFormatter(
|
||||
* id = "{{ field_id }}_default",
|
||||
* label = @Translation("Default"),
|
||||
* field_types = {"{{ field_id }}"}
|
||||
* )
|
||||
*/
|
||||
class {{ formatter_class }} extends FormatterBase {
|
||||
|
||||
{% if formatter_settings %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultSettings() {
|
||||
return ['foo' => 'bar'] + parent::defaultSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state) {
|
||||
$settings = $this->getSettings();
|
||||
$element['foo'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Foo'),
|
||||
'#default_value' => $settings['foo'],
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsSummary() {
|
||||
$settings = $this->getSettings();
|
||||
$summary[] = $this->t('Foo: @foo', ['@foo' => $settings['foo']]);
|
||||
return $summary;
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$element = [];
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
|
||||
{% for subfield in subfields %}
|
||||
{% if subfield.type == 'boolean' %}
|
||||
$element[$delta]['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('{{ subfield.name }}'),
|
||||
'#markup' => $item->{{ subfield.machine_name }} ? $this->t('Yes') : $this->t('No'),
|
||||
];
|
||||
|
||||
{% else %}
|
||||
if ($item->{{ subfield.machine_name }}) {
|
||||
{% if subfield.list %}
|
||||
$allowed_values = {{ type_class }}::{{ subfield.allowed_values_method }}();
|
||||
{% endif %}
|
||||
{% set item_value %}
|
||||
{% if subfield.list %}$allowed_values[$item->{{ subfield.machine_name }}]{% else %}$item->{{ subfield.machine_name }}{% endif %}
|
||||
{% endset %}
|
||||
{% if subfield.type == 'datetime' %}
|
||||
$date = DrupalDateTime::createFromFormat('{{ subfield.date_storage_format }}', $item->{{ subfield.machine_name }});
|
||||
// @DCG: Consider injecting the date formatter service.
|
||||
// @codingStandardsIgnoreStart
|
||||
$date_formatter = \Drupal::service('date.formatter');
|
||||
// @codingStandardsIgnoreStart
|
||||
$timestamp = $date->getTimestamp();
|
||||
{% if subfield.list %}
|
||||
$formatted_date = {{ item_value }};
|
||||
{% else %}
|
||||
$formatted_date = $date_formatter->format($timestamp, 'long');
|
||||
{% endif %}
|
||||
$iso_date = $date_formatter->format($timestamp, 'custom', 'Y-m-d\TH:i:s') . 'Z';
|
||||
$element[$delta]['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('{{ subfield.name }}'),
|
||||
'content' => [
|
||||
'#theme' => 'time',
|
||||
'#text' => $formatted_date,
|
||||
'#html' => FALSE,
|
||||
'#attributes' => [
|
||||
'datetime' => $iso_date,
|
||||
],
|
||||
'#cache' => [
|
||||
'contexts' => [
|
||||
'timezone',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
{% else %}
|
||||
$element[$delta]['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('{{ subfield.name }}'),
|
||||
{% if subfield.link %}
|
||||
'content' => [
|
||||
'#type' => 'link',
|
||||
'#title' => {{ item_value }},
|
||||
{% if subfield.type == 'email' %}
|
||||
'#url' => Url::fromUri('mailto:' . $item->{{ subfield.machine_name }}),
|
||||
{% elseif subfield.type == 'telephone' %}
|
||||
'#url' => Url::fromUri('tel:' . rawurlencode(preg_replace('/\s+/', '', $item->{{ subfield.machine_name }}))),
|
||||
{% elseif subfield.type == 'uri' %}
|
||||
'#url' => Url::fromUri($item->{{ subfield.machine_name }}),
|
||||
{% endif %}
|
||||
],
|
||||
{% else %}
|
||||
'#markup' => {{ item_value }},
|
||||
{% endif %}
|
||||
];
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
105
vendor/chi-teck/drupal-code-generator/templates/d8/_field/key-value-formatter.twig
vendored
Normal file
105
vendor/chi-teck/drupal-code-generator/templates/d8/_field/key-value-formatter.twig
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldFormatter;
|
||||
|
||||
{% sort %}
|
||||
{% if datetime %}
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
{% endif %}
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FormatterBase;
|
||||
{% if list %}
|
||||
use Drupal\{{ machine_name }}\Plugin\Field\FieldType\{{ type_class }};
|
||||
{% endif %}
|
||||
{% endsort %}
|
||||
|
||||
/**
|
||||
* Plugin implementation of the '{{ field_id }}_key_value' formatter.
|
||||
*
|
||||
* @FieldFormatter(
|
||||
* id = "{{ field_id }}_key_value",
|
||||
* label = @Translation("Key-value"),
|
||||
* field_types = {"{{ field_id }}"}
|
||||
* )
|
||||
*/
|
||||
class {{ key_value_formatter_class }} extends FormatterBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
|
||||
$element = [];
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
|
||||
$table = [
|
||||
'#type' => 'table',
|
||||
];
|
||||
|
||||
{% for subfield in subfields %}
|
||||
// {{ subfield.name }}.
|
||||
if ($item->{{ subfield.machine_name }}) {
|
||||
{% if subfield.type == 'datetime' %}
|
||||
$date = DrupalDateTime::createFromFormat('{{ subfield.date_storage_format }}', $item->{{ subfield.machine_name }});
|
||||
$date_formatter = \Drupal::service('date.formatter');
|
||||
$timestamp = $date->getTimestamp();
|
||||
{% if subfield.list %}
|
||||
$allowed_values = {{ type_class }}::{{ subfield.allowed_values_method }}();
|
||||
$formatted_date = $allowed_values[$item->{{ subfield.machine_name }}];
|
||||
{% else %}
|
||||
$formatted_date = $date_formatter->format($timestamp, 'long');
|
||||
{% endif %}
|
||||
$iso_date = $date_formatter->format($timestamp, 'custom', 'Y-m-d\TH:i:s') . 'Z';
|
||||
|
||||
{% elseif subfield.list %}
|
||||
$allowed_values = {{ type_class }}::{{ subfield.allowed_values_method }}();
|
||||
|
||||
{% endif %}
|
||||
$table['#rows'][] = [
|
||||
'data' => [
|
||||
[
|
||||
'header' => TRUE,
|
||||
'data' => [
|
||||
'#markup' => $this->t('{{ subfield.name }}'),
|
||||
],
|
||||
],
|
||||
[
|
||||
'data' => [
|
||||
{% if subfield.type == 'boolean' %}
|
||||
'#markup' => $item->{{ subfield.machine_name }} ? $this->t('Yes') : $this->t('No'),
|
||||
{% elseif subfield.type == 'datetime' %}
|
||||
'#theme' => 'time',
|
||||
'#text' => $formatted_date,
|
||||
'#html' => FALSE,
|
||||
'#attributes' => [
|
||||
'datetime' => $iso_date,
|
||||
],
|
||||
'#cache' => [
|
||||
'contexts' => [
|
||||
'timezone',
|
||||
],
|
||||
],
|
||||
{% else %}
|
||||
{% if subfield.list %}
|
||||
'#markup' => $allowed_values[$item->{{ subfield.machine_name }}],
|
||||
{% else %}
|
||||
'#markup' => $item->{{ subfield.machine_name }},
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
],
|
||||
],
|
||||
],
|
||||
'no_striping' => TRUE,
|
||||
];
|
||||
}
|
||||
|
||||
{% endfor %}
|
||||
$element[$delta] = $table;
|
||||
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
4
vendor/chi-teck/drupal-code-generator/templates/d8/_field/libraries.twig
vendored
Normal file
4
vendor/chi-teck/drupal-code-generator/templates/d8/_field/libraries.twig
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
{{ field_id }}:
|
||||
css:
|
||||
component:
|
||||
css/{{ field_id|u2h }}-widget.css: {}
|
50
vendor/chi-teck/drupal-code-generator/templates/d8/_field/schema.twig
vendored
Normal file
50
vendor/chi-teck/drupal-code-generator/templates/d8/_field/schema.twig
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
{% if storage_settings %}
|
||||
# Field storage.
|
||||
field.storage_settings.{{ field_id }}:
|
||||
type: mapping
|
||||
label: Example storage settings
|
||||
mapping:
|
||||
foo:
|
||||
type: string
|
||||
label: Foo
|
||||
{% endif %}
|
||||
{% if instance_settings %}
|
||||
# Field instance.
|
||||
field.field_settings.{{ field_id }}:
|
||||
type: mapping
|
||||
label: Example field settings
|
||||
mapping:
|
||||
bar:
|
||||
type: string
|
||||
label: Bar
|
||||
{% endif %}
|
||||
# Default value.
|
||||
field.value.{{ field_id }}:
|
||||
type: mapping
|
||||
label: Default value
|
||||
mapping:
|
||||
{% for subfield in subfields %}
|
||||
{{ subfield.machine_name }}:
|
||||
type: {{ subfield.type }}
|
||||
label: {{ subfield.name }}
|
||||
{% endfor %}
|
||||
{% if widget_settings %}
|
||||
# Field widget.
|
||||
field.widget.settings.{{ field_id }}:
|
||||
type: mapping
|
||||
label: Example widget settings
|
||||
mapping:
|
||||
foo:
|
||||
type: string
|
||||
label: Foo
|
||||
{% endif %}
|
||||
{% if formatter_settings %}
|
||||
# Field formatter.
|
||||
field.formatter.settings.{{ field_id }}_default:
|
||||
type: mapping
|
||||
label: Example formatter settings
|
||||
mapping:
|
||||
foo:
|
||||
type: string
|
||||
label: Foo
|
||||
{% endif %}
|
102
vendor/chi-teck/drupal-code-generator/templates/d8/_field/table-formatter.twig
vendored
Normal file
102
vendor/chi-teck/drupal-code-generator/templates/d8/_field/table-formatter.twig
vendored
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldFormatter;
|
||||
|
||||
{% sort %}
|
||||
{% if datetime %}
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
{% endif %}
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FormatterBase;
|
||||
{% if list %}
|
||||
use Drupal\{{ machine_name }}\Plugin\Field\FieldType\{{ type_class }};
|
||||
{% endif %}
|
||||
{% endsort %}
|
||||
|
||||
/**
|
||||
* Plugin implementation of the '{{ field_id }}_table' formatter.
|
||||
*
|
||||
* @FieldFormatter(
|
||||
* id = "{{ field_id }}_table",
|
||||
* label = @Translation("Table"),
|
||||
* field_types = {"{{ field_id }}"}
|
||||
* )
|
||||
*/
|
||||
class {{ table_formatter_class }} extends FormatterBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
|
||||
$header[] = '#';
|
||||
{% for subfield in subfields %}
|
||||
$header[] = $this->t('{{ subfield.name }}');
|
||||
{% endfor %}
|
||||
|
||||
$table = [
|
||||
'#type' => 'table',
|
||||
'#header' => $header,
|
||||
];
|
||||
|
||||
foreach ($items as $delta => $item) {
|
||||
$row = [];
|
||||
|
||||
$row[]['#markup'] = $delta + 1;
|
||||
|
||||
{% for subfield in subfields %}
|
||||
{% if subfield.type == 'boolean' %}
|
||||
$row[]['#markup'] = $item->{{ subfield.machine_name }} ? $this->t('Yes') : $this->t('No');
|
||||
|
||||
{% elseif subfield.type == 'datetime' %}
|
||||
if ($item->{{ subfield.machine_name }}) {
|
||||
$date = DrupalDateTime::createFromFormat('{{ subfield.date_storage_format }}', $item->{{ subfield.machine_name }});
|
||||
$date_formatter = \Drupal::service('date.formatter');
|
||||
$timestamp = $date->getTimestamp();
|
||||
{% if subfield.list %}
|
||||
$allowed_values = {{ type_class }}::{{ subfield.allowed_values_method }}();
|
||||
$formatted_date = $allowed_values[$item->{{ subfield.machine_name }}];
|
||||
{% else %}
|
||||
$formatted_date = $date_formatter->format($timestamp, 'long');
|
||||
{% endif %}
|
||||
$iso_date = $date_formatter->format($timestamp, 'custom', 'Y-m-d\TH:i:s') . 'Z';
|
||||
$row[] = [
|
||||
'#theme' => 'time',
|
||||
'#text' => $formatted_date,
|
||||
'#html' => FALSE,
|
||||
'#attributes' => [
|
||||
'datetime' => $iso_date,
|
||||
],
|
||||
'#cache' => [
|
||||
'contexts' => [
|
||||
'timezone',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
else {
|
||||
$row[]['#markup'] = '';
|
||||
}
|
||||
|
||||
{% else %}
|
||||
{% if subfield.list %}
|
||||
if ($item->{{ subfield.machine_name }}) {
|
||||
$allowed_values = {{ type_class }}::{{ subfield.allowed_values_method }}();
|
||||
$row[]['#markup'] = $allowed_values[$item->{{ subfield.machine_name }}];
|
||||
}
|
||||
else {
|
||||
$row[]['#markup'] = '';
|
||||
}
|
||||
{% else %}
|
||||
$row[]['#markup'] = $item->{{ subfield.machine_name }};
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
$table[$delta] = $row;
|
||||
}
|
||||
|
||||
return [$table];
|
||||
}
|
||||
|
||||
}
|
316
vendor/chi-teck/drupal-code-generator/templates/d8/_field/type.twig
vendored
Normal file
316
vendor/chi-teck/drupal-code-generator/templates/d8/_field/type.twig
vendored
Normal file
|
@ -0,0 +1,316 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldType;
|
||||
|
||||
{% if random %}
|
||||
use Drupal\Component\Utility\Random;
|
||||
{% endif %}
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemBase;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
{% if storage_settings or instance_settings %}
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
{% endif %}
|
||||
{% if email %}
|
||||
use Drupal\Core\Render\Element\Email;
|
||||
{% endif %}
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
|
||||
/**
|
||||
* Defines the '{{ field_id }}' field type.
|
||||
*
|
||||
* @FieldType(
|
||||
* id = "{{ field_id }}",
|
||||
* label = @Translation("{{ field_label }}"),
|
||||
* category = @Translation("General"),
|
||||
* default_widget = "{{ field_id }}",
|
||||
* default_formatter = "{{ field_id }}_default"
|
||||
* )
|
||||
*/
|
||||
class {{ type_class }} extends FieldItemBase {
|
||||
|
||||
{% if storage_settings %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultStorageSettings() {
|
||||
$settings = ['foo' => 'example'];
|
||||
return $settings + parent::defaultStorageSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$element['foo'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Foo'),
|
||||
'#default_value' => $settings['foo'],
|
||||
'#disabled' => $has_data,
|
||||
];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
{% if instance_settings %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultFieldSettings() {
|
||||
$settings = ['bar' => 'example'];
|
||||
return $settings + parent::defaultFieldSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
|
||||
$settings = $this->getSettings();
|
||||
|
||||
$element['bar'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Foo'),
|
||||
'#default_value' => $settings['bar'],
|
||||
];
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEmpty() {
|
||||
{% for subfield in subfields %}
|
||||
{% set condition %}
|
||||
{% if subfield.type == 'boolean' %}$this->{{ subfield.machine_name }} == 1{% else %}$this->{{ subfield.machine_name }} !== NULL{% endif %}
|
||||
{% endset %}
|
||||
{% if loop.index == 1 %}
|
||||
if ({{ condition }}) {
|
||||
{% else %}
|
||||
elseif ({{ condition }}) {
|
||||
{% endif %}
|
||||
return FALSE;
|
||||
}
|
||||
{% endfor %}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
|
||||
|
||||
{% for subfield in subfields %}
|
||||
$properties['{{ subfield.machine_name }}'] = DataDefinition::create('{{ subfield.data_type }}')
|
||||
->setLabel(t('{{ subfield.name }}'));
|
||||
{% endfor %}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConstraints() {
|
||||
$constraints = parent::getConstraints();
|
||||
|
||||
{% for subfield in subfields %}
|
||||
{% if subfield.list %}
|
||||
$options['{{ subfield.machine_name }}']['AllowedValues'] = array_keys({{ type_class }}::{{ subfield.allowed_values_method }}());
|
||||
|
||||
{% endif %}
|
||||
{% if subfield.required %}
|
||||
{% if subfield.type == 'boolean' %}
|
||||
// NotBlank validator is not suitable for booleans because it does not
|
||||
// recognize '0' as an empty value.
|
||||
$options['{{ subfield.machine_name }}']['AllowedValues']['choices'] = [1];
|
||||
$options['{{ subfield.machine_name }}']['AllowedValues']['message'] = $this->t('This value should not be blank.');
|
||||
|
||||
{% else %}
|
||||
$options['{{ subfield.machine_name }}']['NotBlank'] = [];
|
||||
|
||||
{% if subfield.type == 'email' %}
|
||||
$options['{{ subfield.machine_name }}']['Length']['max'] = Email::EMAIL_MAX_LENGTH;
|
||||
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if list or required %}
|
||||
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
|
||||
$constraints[] = $constraint_manager->create('ComplexData', $options);
|
||||
{% endif %}
|
||||
// @todo Add more constrains here.
|
||||
return $constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
|
||||
$columns = [
|
||||
{% for subfield in subfields %}
|
||||
'{{ subfield.machine_name }}' => [
|
||||
{% if subfield.type == 'boolean' %}
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
{% elseif subfield.type == 'string' %}
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
{% elseif subfield.type == 'text' %}
|
||||
'type' => 'text',
|
||||
'size' => 'big',
|
||||
{% elseif subfield.type == 'integer' %}
|
||||
'type' => 'int',
|
||||
'size' => 'normal',
|
||||
{% elseif subfield.type == 'float' %}
|
||||
'type' => 'float',
|
||||
'size' => 'normal',
|
||||
{% elseif subfield.type == 'numeric' %}
|
||||
'type' => 'numeric',
|
||||
'precision' => 10,
|
||||
'scale' => 2,
|
||||
{% elseif subfield.type == 'email' %}
|
||||
'type' => 'varchar',
|
||||
'length' => Email::EMAIL_MAX_LENGTH,
|
||||
{% elseif subfield.type == 'telephone' %}
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
{% elseif subfield.type == 'uri' %}
|
||||
'type' => 'varchar',
|
||||
'length' => 2048,
|
||||
{% elseif subfield.type == 'datetime' %}
|
||||
'type' => 'varchar',
|
||||
'length' => 20,
|
||||
{% endif %}
|
||||
],
|
||||
{% endfor %}
|
||||
];
|
||||
|
||||
$schema = [
|
||||
'columns' => $columns,
|
||||
// @DCG Add indexes here if necessary.
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
|
||||
|
||||
{% if random %}
|
||||
$random = new Random();
|
||||
|
||||
{% endif %}
|
||||
{% for subfield in subfields %}
|
||||
{% if subfield.list %}
|
||||
$values['{{ subfield.machine_name }}'] = array_rand(self::{{ subfield.allowed_values_method }}());
|
||||
|
||||
{% elseif subfield.type == 'boolean' %}
|
||||
$values['{{ subfield.machine_name }}'] = (bool) mt_rand(0, 1);
|
||||
|
||||
{% elseif subfield.type == 'string' %}
|
||||
$values['{{ subfield.machine_name }}'] = $random->word(mt_rand(1, 255));
|
||||
|
||||
{% elseif subfield.type == 'text' %}
|
||||
$values['{{ subfield.machine_name }}'] = $random->paragraphs(5);
|
||||
|
||||
{% elseif subfield.type == 'integer' %}
|
||||
$values['{{ subfield.machine_name }}'] = mt_rand(-1000, 1000);
|
||||
|
||||
{% elseif subfield.type == 'float' %}
|
||||
$scale = rand(1, 5);
|
||||
$random_decimal = mt_rand() / mt_getrandmax() * (1000 - 0);
|
||||
$values['{{ subfield.machine_name }}'] = floor($random_decimal * pow(10, $scale)) / pow(10, $scale);
|
||||
|
||||
{% elseif subfield.type == 'numeric' %}
|
||||
$scale = rand(10, 2);
|
||||
$random_decimal = -1000 + mt_rand() / mt_getrandmax() * (-1000 - 1000);
|
||||
$values['{{ subfield.machine_name }}'] = floor($random_decimal * pow(10, $scale)) / pow(10, $scale);
|
||||
|
||||
{% elseif subfield.type == 'email' %}
|
||||
$values['{{ subfield.machine_name }}'] = strtolower($random->name()) . '@example.com';
|
||||
|
||||
{% elseif subfield.type == 'telephone' %}
|
||||
$values['{{ subfield.machine_name }}'] = mt_rand(pow(10, 8), pow(10, 9) - 1);
|
||||
|
||||
{% elseif subfield.type == 'uri' %}
|
||||
$tlds = ['com', 'net', 'gov', 'org', 'edu', 'biz', 'info'];
|
||||
$domain_length = mt_rand(7, 15);
|
||||
$protocol = mt_rand(0, 1) ? 'https' : 'http';
|
||||
$www = mt_rand(0, 1) ? 'www' : '';
|
||||
$domain = $random->word($domain_length);
|
||||
$tld = $tlds[mt_rand(0, (count($tlds) - 1))];
|
||||
$values['{{ subfield.machine_name }}'] = "$protocol://$www.$domain.$tld";
|
||||
|
||||
{% elseif subfield.type == 'datetime' %}
|
||||
$timestamp = \Drupal::time()->getRequestTime() - mt_rand(0, 86400 * 365);
|
||||
$values['{{ subfield.machine_name }}'] = gmdate('{{ subfield.date_storage_format }}', $timestamp);
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
return $values;
|
||||
}
|
||||
|
||||
{% for subfield in subfields %}
|
||||
{% if subfield.list %}
|
||||
/**
|
||||
* Returns allowed values for '{{ subfield.machine_name }}' sub-field.
|
||||
*
|
||||
* @return array
|
||||
* The list of allowed values.
|
||||
*/
|
||||
public static function {{ subfield.allowed_values_method }}() {
|
||||
return [
|
||||
{% if subfield.type == 'string' %}
|
||||
'alpha' => t('Alpha'),
|
||||
'beta' => t('Beta'),
|
||||
'gamma' => t('Gamma'),
|
||||
{% elseif subfield.type == 'integer' %}
|
||||
123 => 123,
|
||||
456 => 456,
|
||||
789 => 789,
|
||||
{% elseif subfield.type == 'float' %}
|
||||
'12.3' => '12.3',
|
||||
'4.56' => '4.56',
|
||||
'0.789' => '0.789',
|
||||
{% elseif subfield.type == 'numeric' %}
|
||||
'12.35' => '12.35',
|
||||
'45.65' => '45.65',
|
||||
'78.95' => '78.95',
|
||||
{% elseif subfield.type == 'email' %}
|
||||
'alpha@example.com' => 'alpha@example.com',
|
||||
'beta@example.com' => 'beta@example.com',
|
||||
'gamma@example.com' => 'gamma@example.com',
|
||||
{% elseif subfield.type == 'telephone' %}
|
||||
'71234567001' => '+7(123)45-67-001',
|
||||
'71234567002' => '+7(123)45-67-002',
|
||||
'71234567003' => '+7(123)45-67-003',
|
||||
{% elseif subfield.type == 'uri' %}
|
||||
'https://example.com' => 'https://example.com',
|
||||
'http://www.php.net' => 'http://www.php.net',
|
||||
'https://www.drupal.org' => 'https://www.drupal.org',
|
||||
{% elseif subfield.type == 'datetime' %}
|
||||
{% if subfield.date_type == 'date' %}
|
||||
'2018-01-01' => '1 January 2018',
|
||||
'2018-02-01' => '1 February 2018',
|
||||
'2018-03-01' => '1 March 2018',
|
||||
{% else %}
|
||||
'2018-01-01T00:10:10' => '1 January 2018, 00:10:10',
|
||||
'2018-02-01T00:20:20' => '1 February 2018, 00:20:20',
|
||||
'2018-03-01T00:30:30' => '1 March 2018, 00:30:30',
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
];
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}
|
13
vendor/chi-teck/drupal-code-generator/templates/d8/_field/widget-css.twig
vendored
Normal file
13
vendor/chi-teck/drupal-code-generator/templates/d8/_field/widget-css.twig
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
{% set class = field_id|u2h ~ '-elements' %}
|
||||
{% if inline %}
|
||||
.container-inline.{{ class }} .form-item {
|
||||
margin: 0 3px;
|
||||
}
|
||||
.container-inline.{{ class }} label {
|
||||
display: block;
|
||||
}
|
||||
{% else %}
|
||||
tr.odd .{{ class }} .form-item {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
{% endif %}
|
202
vendor/chi-teck/drupal-code-generator/templates/d8/_field/widget.twig
vendored
Normal file
202
vendor/chi-teck/drupal-code-generator/templates/d8/_field/widget.twig
vendored
Normal file
|
@ -0,0 +1,202 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldWidget;
|
||||
|
||||
{% sort %}
|
||||
{% if datetime %}
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
{% endif %}
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\WidgetBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||
{% if list %}
|
||||
use Drupal\{{ machine_name }}\Plugin\Field\FieldType\{{ type_class }};
|
||||
{% endif %}
|
||||
{% endsort %}
|
||||
|
||||
/**
|
||||
* Defines the '{{ field_id }}' field widget.
|
||||
*
|
||||
* @FieldWidget(
|
||||
* id = "{{ field_id }}",
|
||||
* label = @Translation("{{ field_label }}"),
|
||||
* field_types = {"{{ field_id }}"},
|
||||
* )
|
||||
*/
|
||||
class {{ widget_class }} extends WidgetBase {
|
||||
|
||||
{% if widget_settings %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultSettings() {
|
||||
return ['foo' => 'bar'] + parent::defaultSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state) {
|
||||
$settings = $this->getSettings();
|
||||
$element['foo'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Foo'),
|
||||
'#default_value' => $settings['foo'],
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsSummary() {
|
||||
$settings = $this->getSettings();
|
||||
$summary[] = $this->t('Foo: @foo', ['@foo' => $settings['foo']]);
|
||||
return $summary;
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
|
||||
|
||||
{% for subfield in subfields %}
|
||||
{% set title %}'#title' => $this->t('{{ subfield.name }}'),{% endset %}
|
||||
{% set default_value %}'#default_value' => isset($items[$delta]->{{ subfield.machine_name }}) ? $items[$delta]->{{ subfield.machine_name }} : NULL,{% endset %}
|
||||
{% set size %}'#size' => 20,{% endset %}
|
||||
{% if subfield.list %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'select',
|
||||
{{ title }}
|
||||
'#options' => ['' => $this->t('- {{ subfield.required ? 'Select a value' : 'None' }} -')] + {{ type_class }}::{{ subfield.allowed_values_method }}(),
|
||||
{{ default_value }}
|
||||
];
|
||||
{% else %}
|
||||
{% if subfield.type == 'boolean' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'checkbox',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
];
|
||||
{% elseif subfield.type == 'string' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'textfield',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
{% if inline %}
|
||||
{{ size }}
|
||||
{% endif %}
|
||||
];
|
||||
{% elseif subfield.type == 'text' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'textarea',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
];
|
||||
{% elseif subfield.type == 'integer' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'number',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
];
|
||||
{% elseif subfield.type == 'float' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'number',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
'#step' => 0.001,
|
||||
];
|
||||
{% elseif subfield.type == 'numeric' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'number',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
'#step' => 0.01,
|
||||
];
|
||||
{% elseif subfield.type == 'email' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'email',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
{% if inline %}
|
||||
{{ size }}
|
||||
{% endif %}
|
||||
];
|
||||
{% elseif subfield.type == 'telephone' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'tel',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
{% if inline %}
|
||||
{{ size }}
|
||||
{% endif %}
|
||||
];
|
||||
{% elseif subfield.type == 'uri' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'url',
|
||||
{{ title }}
|
||||
{{ default_value }}
|
||||
{% if inline %}
|
||||
{{ size }}
|
||||
{% endif %}
|
||||
];
|
||||
{% elseif subfield.type == 'datetime' %}
|
||||
$element['{{ subfield.machine_name }}'] = [
|
||||
'#type' => 'datetime',
|
||||
{{ title }}
|
||||
'#default_value' => NULL,
|
||||
{% if subfield.date_type == 'date' %}
|
||||
'#date_time_element' => 'none',
|
||||
'#date_time_format' => '',
|
||||
{% endif %}
|
||||
];
|
||||
if (isset($items[$delta]->{{ subfield.machine_name }})) {
|
||||
$element['{{ subfield.machine_name }}']['#default_value'] = DrupalDateTime::createFromFormat(
|
||||
'{{ subfield.date_storage_format }}',
|
||||
$items[$delta]->{{ subfield.machine_name }},
|
||||
'UTC'
|
||||
);
|
||||
}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
$element['#theme_wrappers'] = ['container', 'form_element'];
|
||||
{% if inline %}
|
||||
$element['#attributes']['class'][] = 'container-inline';
|
||||
{% endif %}
|
||||
$element['#attributes']['class'][] = '{{ field_id|u2h }}-elements';
|
||||
$element['#attached']['library'][] = '{{ machine_name }}/{{ field_id }}';
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function errorElement(array $element, ConstraintViolationInterface $violation, array $form, FormStateInterface $form_state) {
|
||||
return isset($violation->arrayPropertyPath[0]) ? $element[$violation->arrayPropertyPath[0]] : $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
|
||||
foreach ($values as $delta => $value) {
|
||||
{% for subfield in subfields %}
|
||||
if ($value['{{ subfield.machine_name }}'] === '') {
|
||||
$values[$delta]['{{ subfield.machine_name }}'] = NULL;
|
||||
}
|
||||
{% if subfield.type == 'datetime' %}
|
||||
if ($value['{{ subfield.machine_name }}'] instanceof DrupalDateTime) {
|
||||
$values[$delta]['{{ subfield.machine_name }}'] = $value['{{ subfield.machine_name }}']->format('{{ subfield.date_storage_format }}');
|
||||
}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue