Initial Drupal 11 with DDEV setup
This commit is contained in:
71
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_formatter/formatter.twig
vendored
Normal file
71
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_formatter/formatter.twig
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldFormatter;
|
||||
|
||||
{% apply sort_namespaces %}
|
||||
use Drupal\Core\Field\Attribute\FieldFormatter;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FormatterBase;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
{% if configurable %}
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
{% endif %}
|
||||
{% endapply %}
|
||||
|
||||
/**
|
||||
* Plugin implementation of the '{{ plugin_label }}' formatter.
|
||||
*/
|
||||
#[FieldFormatter(
|
||||
id: '{{ plugin_id }}',
|
||||
label: new TranslatableMarkup('{{ plugin_label }}'),
|
||||
field_types: ['string'],
|
||||
)]
|
||||
class {{ class }} extends FormatterBase {
|
||||
|
||||
{% if configurable %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultSettings(): array {
|
||||
$setting = ['foo' => 'bar'];
|
||||
return $setting + parent::defaultSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state): array {
|
||||
$elements['foo'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Foo'),
|
||||
'#default_value' => $this->getSetting('foo'),
|
||||
];
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsSummary(): array {
|
||||
return [
|
||||
$this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]),
|
||||
];
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items, $langcode): array {
|
||||
$element = [];
|
||||
foreach ($items as $delta => $item) {
|
||||
$element[$delta] = [
|
||||
'#markup' => $item->value,
|
||||
];
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
||||
7
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_formatter/schema.twig
vendored
Normal file
7
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_formatter/schema.twig
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
field.formatter.settings.{{ plugin_id }}:
|
||||
type: mapping
|
||||
label: {{ plugin_label }} formatter settings
|
||||
mapping:
|
||||
foo:
|
||||
type: string
|
||||
label: Foo
|
||||
27
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_type/schema.twig
vendored
Normal file
27
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_type/schema.twig
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
{% if configurable_storage %}
|
||||
field.storage_settings.{{ plugin_id }}:
|
||||
type: mapping
|
||||
label: {{ plugin_label }} storage settings
|
||||
mapping:
|
||||
foo:
|
||||
type: string
|
||||
label: Foo
|
||||
|
||||
{% endif %}
|
||||
{% if configurable_instance %}
|
||||
field.field_settings.{{ plugin_id }}:
|
||||
type: mapping
|
||||
label: {{ plugin_label }} field settings
|
||||
mapping:
|
||||
bar:
|
||||
type: string
|
||||
label: Bar
|
||||
|
||||
{% endif %}
|
||||
field.value.{{ plugin_id }}:
|
||||
type: mapping
|
||||
label: Default value
|
||||
mapping:
|
||||
value:
|
||||
type: label
|
||||
label: Value
|
||||
151
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_type/type.twig
vendored
Normal file
151
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_type/type.twig
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldType;
|
||||
|
||||
{% apply sort_namespaces %}
|
||||
use Drupal\Component\Utility\Random;
|
||||
use Drupal\Core\Field\Attribute\FieldType;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldItemBase;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
{% if configurable_storage or configurable_instance %}
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
{% endif %}
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
{% endapply %}
|
||||
|
||||
/**
|
||||
* Defines the '{{ plugin_id }}' field type.
|
||||
*/
|
||||
#[FieldType(
|
||||
id: '{{ plugin_id }}',
|
||||
label: new TranslatableMarkup('{{ plugin_label }}'),
|
||||
description: new TranslatableMarkup('Some description'),
|
||||
default_widget: 'string_textfield',
|
||||
default_formatter: 'string',
|
||||
)]
|
||||
final class {{ class }} extends FieldItemBase {
|
||||
|
||||
{% if configurable_storage %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultStorageSettings(): array {
|
||||
$settings = ['foo' => ''];
|
||||
return $settings + parent::defaultStorageSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data): array {
|
||||
$element['foo'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Foo'),
|
||||
'#default_value' => $this->getSetting('foo'),
|
||||
'#disabled' => $has_data,
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
{% if configurable_instance %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultFieldSettings(): array {
|
||||
$settings = ['bar' => ''];
|
||||
return $settings + parent::defaultFieldSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fieldSettingsForm(array $form, FormStateInterface $form_state): array {
|
||||
$element['bar'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Bar'),
|
||||
'#default_value' => $this->getSetting('bar'),
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEmpty(): bool {
|
||||
return match ($this->get('value')->getValue()) {
|
||||
NULL, '' => TRUE,
|
||||
default => FALSE,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition): array {
|
||||
|
||||
// @DCG
|
||||
// See /core/lib/Drupal/Core/TypedData/Plugin/DataType directory for
|
||||
// available data types.
|
||||
$properties['value'] = DataDefinition::create('string')
|
||||
->setLabel(t('Text value'))
|
||||
->setRequired(TRUE);
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConstraints(): array {
|
||||
$constraints = parent::getConstraints();
|
||||
|
||||
$constraint_manager = $this->getTypedDataManager()->getValidationConstraintManager();
|
||||
|
||||
// @DCG Suppose our value must not be longer than 10 characters.
|
||||
$options['value']['Length']['max'] = 10;
|
||||
|
||||
// @DCG
|
||||
// See /core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint
|
||||
// directory for available constraints.
|
||||
$constraints[] = $constraint_manager->create('ComplexData', $options);
|
||||
return $constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition): array {
|
||||
|
||||
$columns = [
|
||||
'value' => [
|
||||
'type' => 'varchar',
|
||||
'not null' => FALSE,
|
||||
'description' => 'Column description.',
|
||||
'length' => 255,
|
||||
],
|
||||
];
|
||||
|
||||
$schema = [
|
||||
'columns' => $columns,
|
||||
// @todo Add indexes here if necessary.
|
||||
];
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function generateSampleValue(FieldDefinitionInterface $field_definition): array {
|
||||
$random = new Random();
|
||||
$values['value'] = $random->word(mt_rand(1, 50));
|
||||
return $values;
|
||||
}
|
||||
|
||||
}
|
||||
7
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_widget/schema.twig
vendored
Normal file
7
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_widget/schema.twig
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
field.widget.settings.{{ plugin_id }}:
|
||||
type: mapping
|
||||
label: {{ plugin_label }} widget settings
|
||||
mapping:
|
||||
foo:
|
||||
type: string
|
||||
label: Foo
|
||||
99
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_widget/widget.twig
vendored
Normal file
99
vendor/chi-teck/drupal-code-generator/templates/Plugin/Field/_widget/widget.twig
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
{% import '@lib/di.twig' as di %}
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\Field\FieldWidget;
|
||||
|
||||
{% apply sort_namespaces %}
|
||||
use Drupal\Core\Field\Attribute\FieldWidget;
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\WidgetBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
{% if services %}
|
||||
{{ di.use(services) }}
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
{% endif %}
|
||||
{% endapply %}
|
||||
|
||||
/**
|
||||
* Defines the '{{ plugin_id }}' field widget.
|
||||
*/
|
||||
#[FieldWidget(
|
||||
id: '{{ plugin_id }}',
|
||||
label: new TranslatableMarkup('{{ plugin_label }}'),
|
||||
field_types: ['string'],
|
||||
)]
|
||||
final class {{ class }} extends WidgetBase {% if services %}implements ContainerFactoryPluginInterface {% endif %}{
|
||||
|
||||
{% if services %}
|
||||
/**
|
||||
* Constructs the plugin instance.
|
||||
*/
|
||||
public function __construct(
|
||||
array $configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
{{ di.signature(services) }}
|
||||
) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self {
|
||||
return new self(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
{{ di.container(services) }}
|
||||
);
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
{% if configurable %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultSettings(): array {
|
||||
$setting = ['foo' => 'bar'];
|
||||
return $setting + parent::defaultSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsForm(array $form, FormStateInterface $form_state): array {
|
||||
$element['foo'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Foo'),
|
||||
'#default_value' => $this->getSetting('foo'),
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function settingsSummary(): array {
|
||||
return [
|
||||
$this->t('Foo: @foo', ['@foo' => $this->getSetting('foo')]),
|
||||
];
|
||||
}
|
||||
|
||||
{% endif %}
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state): array {
|
||||
$element['value'] = $element + [
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $items[$delta]->value ?? NULL,
|
||||
];
|
||||
return $element;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user