Initial Drupal 11 with DDEV setup
This commit is contained in:
@ -0,0 +1,4 @@
|
||||
services:
|
||||
plugin.manager.{{ plugin_type }}:
|
||||
class: Drupal\{{ machine_name }}\{{ class_prefix }}PluginManager
|
||||
parent: default_plugin_manager
|
||||
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Attribute;
|
||||
|
||||
use Drupal\Component\Plugin\Attribute\AttributeBase;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* The {{ plugin_type }} attribute.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
final class {{ class_prefix }} extends AttributeBase {
|
||||
|
||||
/**
|
||||
* Constructs a new {{ class_prefix }} instance.
|
||||
*
|
||||
* @param string $id
|
||||
* The plugin ID. There are some implementation bugs that make the plugin
|
||||
* available only if the ID follows a specific pattern. It must be either
|
||||
* identical to group or prefixed with the group. E.g. if the group is "foo"
|
||||
* the ID must be either "foo" or "foo:bar".
|
||||
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $label
|
||||
* (optional) The human-readable name of the plugin.
|
||||
* @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
|
||||
* (optional) A brief description of the plugin.
|
||||
* @param class-string|null $deriver
|
||||
* (optional) The deriver class.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $id,
|
||||
public readonly ?TranslatableMarkup $label,
|
||||
public readonly ?TranslatableMarkup $description = NULL,
|
||||
public readonly ?string $deriver = NULL,
|
||||
) {}
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }};
|
||||
|
||||
/**
|
||||
* Interface for {{ plugin_type }} plugins.
|
||||
*/
|
||||
interface {{ class_prefix }}Interface {
|
||||
|
||||
/**
|
||||
* Returns the translated plugin label.
|
||||
*/
|
||||
public function label(): string;
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }};
|
||||
|
||||
use Drupal\Component\Plugin\PluginBase;
|
||||
|
||||
/**
|
||||
* Base class for {{ plugin_type }} plugins.
|
||||
*/
|
||||
abstract class {{ class_prefix }}PluginBase extends PluginBase implements {{ class_prefix }}Interface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function label(): string {
|
||||
// Cast the label to a string since it is a TranslatableMarkup object.
|
||||
return (string) $this->pluginDefinition['label'];
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }};
|
||||
|
||||
{% apply sort_namespaces %}
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
use Drupal\{{ machine_name }}\Attribute\{{ class_prefix }};
|
||||
{% endapply %}
|
||||
|
||||
/**
|
||||
* {{ class_prefix }} plugin manager.
|
||||
*/
|
||||
final class {{ class_prefix }}PluginManager extends DefaultPluginManager {
|
||||
|
||||
/**
|
||||
* Constructs the object.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
|
||||
parent::__construct('Plugin/{{ class_prefix }}', $namespaces, $module_handler, {{ class_prefix }}Interface::class, {{ class_prefix }}::class);
|
||||
$this->alterInfo('{{ plugin_type }}_info');
|
||||
$this->setCacheBackend($cache_backend, '{{ plugin_type }}_plugins');
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Plugin\{{ class_prefix }};
|
||||
|
||||
{% apply sort_namespaces %}
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\{{ machine_name }}\Attribute\{{ class_prefix }};
|
||||
use Drupal\{{ machine_name }}\{{ class_prefix }}PluginBase;
|
||||
{% endapply %}
|
||||
|
||||
/**
|
||||
* Plugin implementation of the {{ plugin_type }}.
|
||||
*/
|
||||
#[{{ class_prefix }}(
|
||||
id: 'foo',
|
||||
label: new TranslatableMarkup('Foo'),
|
||||
description: new TranslatableMarkup('Foo description.'),
|
||||
)]
|
||||
final class Foo extends {{ class_prefix }}PluginBase {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user