Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,47 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Tests\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Tests;
{% endblock %}
{% block use_class %}
use Drupal\simpletest\WebTestBase;
{% endblock %}
{% block class_declaration %}
/**
* Provides automated tests for the {{module}} module.
*/
class {{class_name}}Test extends WebTestBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function getInfo() {
return [
'name' => "{{module}} {{class_name}}'s controller functionality",
'description' => 'Test Unit for module {{module}} and controller {{class_name}}.',
'group' => 'Other',
];
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
}
/**
* Tests {{module}} functionality.
*/
public function test{{class_name}}() {
// Check that the basic functions of module {{module}}.
$this->assertEquals(TRUE, TRUE, 'Test Unit Generated via Drupal Console.');
}
{% endblock %}

View file

@ -0,0 +1,14 @@
{
"name": "drupal/{{ machine_name }}",
"type": "drupal-{{ type }}",
"description": "{{ description }}",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/{{ machine_name }}",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/{{ machine_name }}",
"source": "http://cgit.drupalcode.org/{{ machine_name }}"
},
"require": { }
}

View file

@ -0,0 +1,17 @@
{{ module_name }}:
{% for input in inputs %}
{% if input.default_value is defined and input.default_value|length %}
{% if input.default_value is iterable %}
{{ input.name }}:
{% for value in input.default_value %}
- {{ value }}
{% endfor %}
{% else %}
{% if input.type in ['checkbox','number','radio'] %}
{{ input.name }}: {{ input.default_value }}
{% else %}
{{ input.name }}: "{{ input.default_value }}"
{% endif %}
{% endif %}
{% endif %}
{% endfor %}

View file

@ -0,0 +1,12 @@
{{ module }}.{{ entity_name }}.*:
type: config_entity
label: '{{ label }} config'
mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
uuid:
type: string

View file

@ -0,0 +1,34 @@
{% extends "base/file.php.twig" %}
{% block file_path %}
{{ entity_name }}.page.inc{% endblock %}
{% block extra_info %}
*
* Page callback for {{ label }} entities.
{% endblock %}
{% block use_class %}
use Drupal\Core\Render\Element;
{% endblock %}
{% block file_methods %}
/**
* Prepares variables for {{ label }} templates.
*
* Default template: {{ entity_name }}.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_{{ entity_name | machine_name }}(array &$variables) {
// Fetch {{ entity_class }} Entity Object.
${{ entity_name | machine_name }} = $variables['elements']['#{{ entity_name }}'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
{% endblock %}

View file

@ -0,0 +1 @@
bundle: {{ bundle }}

View file

@ -0,0 +1,22 @@
{% block file_methods %}
{% if not file_exists %}
{% include 'module/php_tag.php.twig' %}
{% endif %}
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function {{machine_name}}_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the {{ machine_name }} module.
case 'help.page.{{ machine_name }}':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('{{ description|escape }}') . '</p>';
return $output;
default:
}
}
{% endblock %}

View file

@ -0,0 +1,11 @@
name: '{{ module }}'
type: {{ type }}
description: '{{ description }}'
core: {{ core }}
package: '{{ package }}'
{% if dependencies %}
dependencies:
{% for dependency in dependencies %}
- {{ dependency }}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,5 @@
(function ($, Drupal) {
Drupal.AjaxCommands.prototype.{{ method }} = function (ajax, response, status) {
console.log(response.message);
}
})(jQuery, Drupal);

View file

@ -0,0 +1,10 @@
entity.{{ entity_name }}.add_form:
{# Note: a content entity with bundles will add via a dedicated controller. #}
{% if not bundle_entity_type %}
route_name: entity.{{ entity_name }}.add_form
{% else %}
route_name: entity.{{ entity_name }}.add_page
{% endif %}
title: 'Add {{ label }}'
appears_on:
- entity.{{ entity_name }}.collection

View file

@ -0,0 +1,6 @@
entity.{{ entity_name }}.add_form:
route_name: entity.{{ entity_name }}.add_form
title: 'Add {{ label }}'
appears_on:
- entity.{{ entity_name }}.collection

View file

@ -0,0 +1,10 @@
{# Initial new line ensures that the new definitions starts on a new line #}
# {{ label }} menu items definition
entity.{{ entity_name }}.collection:
title: '{{ label }}'
route_name: entity.{{ entity_name }}.collection
description: 'List {{ label }} (bundles)'
parent: system.admin_structure
weight: 99

View file

@ -0,0 +1,18 @@
{# Initial new line ensures that the new definitions starts on a new line #}
# {{ label }} menu items definition
entity.{{ entity_name }}.collection:
title: '{{ label }} list'
route_name: entity.{{ entity_name }}.collection
description: 'List {{ label }} entities'
parent: system.admin_structure
weight: 100
{# Note: a content entity with bundles will have the settings configured on the bundle (config) entity. #}
{% if not bundle_entity_type %}
{{ entity_name }}.admin.structure.settings:
title: '{{ label }} settings'
description: 'Configure {{ label }} entities'
route_name: {{ entity_name }}.settings
parent: system.admin_structure
{% endif %}

View file

@ -0,0 +1,7 @@
{{ module_name }}.{{form_id}}:
title: '{{ menu_link_title }}'
route_name: {{ module_name }}.{{form_id}}
description: '{{ menu_link_desc }}'
parent: {{ menu_parent }}
weight: 99

View file

@ -0,0 +1,32 @@
# {{ label }} routing definition
{# Note: a content entity with bundles will have the settings configured on the bundle (config) entity. #}
{% if not bundle_entity_type %}
{{ entity_name }}.settings_tab:
route_name: {{ entity_name }}.settings
title: 'Settings'
base_route: {{ entity_name }}.settings
{% endif %}
entity.{{ entity_name }}.canonical:
route_name: entity.{{ entity_name }}.canonical
base_route: entity.{{ entity_name }}.canonical
title: 'View'
entity.{{ entity_name }}.edit_form:
route_name: entity.{{ entity_name }}.edit_form
base_route: entity.{{ entity_name }}.canonical
title: 'Edit'
{% if revisionable %}
entity.{{ entity_name }}.version_history:
route_name: entity.{{ entity_name }}.version_history
base_route: entity.{{ entity_name }}.canonical
title: 'Revisions'
{% endif %}
entity.{{ entity_name }}.delete_form:
route_name: entity.{{ entity_name }}.delete_form
base_route: entity.{{ entity_name }}.canonical
title: Delete
weight: 10

View file

@ -0,0 +1,5 @@
{% extends "base/file.php.twig" %}
{% block file_path %}{{machine_name}}.module.{% endblock %}

View file

@ -0,0 +1,5 @@
{{ module }}-library:
js:
js/{{ js_name }}.js: {}
dependencies:
- core/drupal.ajax

View file

@ -0,0 +1,11 @@
/**
* Implements hook_theme().
*/
function {{machine_name}}_theme() {
return [
'{{machine_name}}' => [
'render element' => 'children',
],
];
}

View file

@ -0,0 +1,25 @@
{% extends "base/file.php.twig" %}
{% block file_path %}{{machine_name}}.module{% endblock %}
{% block use_class %}
use Drupal\Core\Routing\RouteMatchInterface;
{% endblock %}
{% block file_methods %}
/**
* Implements hook_help().
*/
function {{machine_name}}_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the {{ machine_name }} module.
case 'help.page.{{ machine_name }}':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('{{ description|escape }}') . '</p>';
return $output;
default:
}
}
{% endblock %}

View file

@ -0,0 +1,40 @@
{% extends "base/file.php.twig" %}
{% block file_path %}{{ module }}\{{ module }}.views.inc.{% endblock %}
{% block extra_info %} * Provide a custom views field data that isn't tied to any other module.{% endblock %}
{% block use_class %}
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Render\Markup;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\system\ActionConfigEntityInterface;
{% endblock %}
{% block file_methods %}
/**
* Implements hook_views_data().
*/
function {{module}}_views_data() {
$data['views']['table']['group'] = t('Custom Global');
$data['views']['table']['join'] = [
// #global is a special flag which allows a table to appear all the time.
'#global' => [],
];
$data['views']['{{ class_machine_name }}'] = [
'title' => t('{{ title }}'),
'help' => t('{{ description }}'),
'field' => [
'id' => '{{ class_machine_name }}',
],
];
return $data;
}
{% endblock %}

View file

@ -0,0 +1,10 @@
{% block routing_file %}
{% endblock %}
{% if permissions|length %}
{% for permission in permissions %}
{{ module_name }}.route:
requirements:
_permission: {{ permission.permission }}:
{% endfor %}
{% endif %}

View file

@ -0,0 +1,11 @@
{% if permissions|length %}
{% for permission in permissions %}
{{ permission.permission }}:
title: '{{ permission.title }}'
description: '{{ permission.description }}'
{% if permission.restrict_access != 'none' %}
restrict access: {{ permission.restrict_access }}
{% endif %}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,32 @@
add {{ label|lower }} entities:
title: 'Create new {{ label }} entities'
administer {{ label|lower }} entities:
title: 'Administer {{ label }} entities'
description: 'Allow to access the administration form to configure {{ label }} entities.'
restrict access: true
delete {{ label|lower }} entities:
title: 'Delete {{ label }} entities'
edit {{ label|lower }} entities:
title: 'Edit {{ label }} entities'
view published {{ label|lower }} entities:
title: 'View published {{ label }} entities'
view unpublished {{ label|lower }} entities:
title: 'View unpublished {{ label }} entities'
{% if revisionable %}
view all {{ label|lower }} revisions:
title: 'View all {{ label }} revisions'
revert all {{ label|lower }} revisions:
title: 'Revert all {{ label }} revisions'
description: 'Role requires permission <em>view {{ label }} revisions</em> and <em>edit rights</em> for {{ label|lower }} entities in question or <em>administer {{ label|lower }} entities</em>.'
delete all {{ label|lower }} revisions:
title: 'Delete all revisions'
description: 'Role requires permission to <em>view {{ label }} revisions</em> and <em>delete rights</em> for {{ label|lower }} entities in question or <em>administer {{ label|lower }} entities</em>.'
{% endif %}

View file

@ -0,0 +1 @@
<?php

View file

@ -0,0 +1,6 @@
{% if not file_exists %}
services:
{% endif %}
plugin.manager.{{ machine_name | lower }}:
class: Drupal\{{ module }}\Plugin\{{ class_name }}Manager
parent: default_plugin_manager

View file

@ -0,0 +1,6 @@
{% if not file_exists %}
services:
{% endif %}
plugin.manager.{{ plugin_name | lower }}:
class: Drupal\{{ module }}\{{ class_name }}Manager
arguments: ['@module_handler', '@cache.discovery']

View file

@ -0,0 +1,8 @@
# Example {{ plugin_name }} plugin definitions.
# Plugin property $defaults are defined in {{ class_name }}Manager.
first:
id: one
label: One
second:
id: two
label: Two

View file

@ -0,0 +1,12 @@
{% block file_methods %}
{% if not file_exists %}
{% include 'module/php_tag.php.twig' %}
{% endif %}
/**
* Implements hook_post_update_NAME() on Module {{ module }} Post Update {{ post_update_name }}.
*/
function {{ module }}_post_update_{{ post_update_name }}(&$sandbox) {
drupal_set_message('Module {{ module }} Post Update # {{ post_update_name }} () was executed successfully.');
}
{% endblock %}

View file

@ -0,0 +1,15 @@
{% if class_name is defined %}
{% for route in routes %}
{% if learning is defined and learning %}
{{ yaml_comment('application.messages.learning.route') }}
{% endif %}
{{ route.name }}:
path: '{{ route.path }}'
defaults:
_controller: '\Drupal\{{ module }}\Controller\{{ class_name }}::{{ route.method }}'
_title: '{{route.title}}'
requirements:
_permission: 'access content'
{% endfor %}
{% endif %}

View file

@ -0,0 +1,18 @@
{% if class_name is defined %}
{{ module_name }}.{{form_id}}:
path: '{{ path }}'
defaults:
_form: '\Drupal\{{ module_name }}\Form\{{ class_name }}'
_title: '{{ class_name }}'
{% if config_form %}
requirements:
_permission: 'access administration pages'
options:
_admin_route: TRUE
{% else %}
requirements:
_access: 'TRUE'
{% endif %}
{% endif %}

View file

@ -0,0 +1,14 @@
{% if name is defined %}
{% if not file_exists %}
services:
{% endif %}
{{ name | lower }}:
class: {{ class_path }}
{% if services is defined %}
arguments: [{{ servicesAsParametersKeys(services)|join(', ') }}]
{% endif %}
{% if tags is defined %}
tags:
- { {{ tagsAsArray(tags)|join(', ') }} }
{% endif %}
{% endif %}

View file

@ -0,0 +1,33 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Ajax\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Ajax;
{% endblock %}
{% block use_class %}
use Drupal\Core\Ajax\CommandInterface;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}.
*/
class {{ class_name }} implements CommandInterface {% endblock %}
{% block class_methods %}
/**
* Render custom ajax command.
*
* @return ajax
* Command function.
*/
public function render() {
return [
'command' => '{{ method }}',
'message' => 'My Awesome Message',
];
}
{% endblock %}

View file

@ -0,0 +1,42 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Annotation\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Annotation;
{% endblock %}
{% block use_class %}
use Drupal\Component\Annotation\Plugin;
{% endblock %}
{% block class_declaration %}
/**
* Defines a {{ label }} item annotation object.
*
* @see \Drupal\{{ module }}\Plugin\{{ class_name }}Manager
* @see plugin_api
*
* @Annotation
*/
class {{ class_name }} extends Plugin {% endblock %}
{% block class_methods %}
/**
* The plugin ID.
*
* @var string
*/
public $id;
/**
* The label of the plugin.
*
* @var \Drupal\Core\Annotation\Translation
*
* @ingroup plugin_translatable
*/
public $label;
{% endblock %}

View file

@ -0,0 +1,112 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Authentication\Provider\{{class}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Authentication\Provider;
{% endblock %}
{% block use_class %}
use Drupal\Core\Authentication\AuthenticationProviderInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class }}.
*/
class {{ class }} implements AuthenticationProviderInterface {% endblock %}
{% block class_variables %}
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
{% endblock %}
{% block class_construct %}
/**
* Constructs a HTTP basic authentication provider object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->configFactory = $config_factory;
$this->entityTypeManager = $entity_type_manager;
}
{% endblock %}
{% block class_create %}
{% endblock %}
{% block class_methods %}
/**
* Checks whether suitable authentication credentials are on the request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*
* @return bool
* TRUE if authentication credentials suitable for this provider are on the
* request, FALSE otherwise.
*/
public function applies(Request $request) {
// If you return TRUE and the method Authentication logic fails,
// you will get out from Drupal navigation if you are logged in.
return FALSE;
}
/**
* {@inheritdoc}
*/
public function authenticate(Request $request) {
$consumer_ip = $request->getClientIp();
$ips = [];
if (in_array($consumer_ip, $ips)) {
// Return Anonymous user.
return $this->entityTypeManager->getStorage('user')->load(0);
}
else {
throw new AccessDeniedHttpException();
}
}
/**
* {@inheritdoc}
*/
public function cleanup(Request $request) {}
/**
* {@inheritdoc}
*/
public function handleException(GetResponseForExceptionEvent $event) {
$exception = $event->getException();
if ($exception instanceof AccessDeniedHttpException) {
$event->setException(
new UnauthorizedHttpException('Invalid consumer origin.', $exception)
);
return TRUE;
}
return FALSE;
}
{% endblock %}

View file

@ -0,0 +1,85 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{extension}}\Command\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{extension}}\Command;
{% endblock %}
{% block use_class %}
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
{% if container_aware %}
use Drupal\Console\Core\Command\ContainerAwareCommand;
{% else %}
use Drupal\Console\Core\Command\Command;
{% endif %}
use Drupal\Console\Annotations\DrupalCommand;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}.
*
* @DrupalCommand (
* extension="{{extension}}",
* extensionType="{{ extension_type }}"
* )
*/
class {{ class_name }} extends {% if container_aware %}ContainerAwareCommand{% else %}Command{% endif %} {% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Constructs a new {{ class_name }} object.
*/
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
{{ serviceClassInitialization(services) }}
parent::__construct();
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
protected function configure() {
$this
->setName('{{ name }}')
->setDescription($this->trans('commands.{{ command_key }}.description'));
}
{% if initialize %}
/**
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output) {
parent::initialize($input, $output);
$this->getIo()->info('initialize');
}
{% endif %}
{% if interact %}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output) {
$this->getIo()->info('interact');
}
{% endif %}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$this->getIo()->info('execute');
$this->getIo()->info($this->trans('commands.{{ command_key }}.messages.success'));
{% if class_generator %}
$this->generator->generate([]);
{% endif %}
}
{%- endblock -%}

View file

@ -0,0 +1,5 @@
description: 'Drupal Console generated command.'
options: {}
arguments: {}
messages:
success: 'I am a new generated command.'

View file

@ -0,0 +1,69 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Controller\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Controller;
{% endblock %}
{% block use_class %}
use Drupal\Core\Controller\ControllerBase;
{% if services is not empty %}
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}.
*/
class {{ class_name }} extends ControllerBase {% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Constructs a new {{ class_name }} object.
*/
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
{% for route in routes %}
/**
* {{ route.method | capitalize }}.
*
* @return string
* Return Hello string.
*/
public function {{route.method}}({{ argumentsFromRoute(route.path)|join(', ') }}) {
{% if argumentsFromRoute(route.path) is not empty %}
return [
'#type' => 'markup',
'#markup' => $this->t('Implement method: {{route.method}} with parameter(s): {{ argumentsFromRoute(route.path)|join(', ') }}'),
];
{% else %}
return [
'#type' => 'markup',
'#markup' => $this->t('Implement method: {{route.method}}')
];
{% endif %}
}
{% endfor %}
{% endblock %}

View file

@ -0,0 +1,175 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Controller\{{ entity_class }}Controller.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Controller;
{% endblock %}
{% block use_class %}
use Drupal\Component\Utility\Xss;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
use Drupal\{{ module }}\Entity\{{ entity_class }}Interface;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ entity_class }}Controller.
*
* Returns responses for {{ label }} routes.
*/
class {{ entity_class }}Controller extends ControllerBase implements ContainerInjectionInterface {% endblock %}
{% block class_methods %}
/**
* Displays a {{ label }} revision.
*
* @param int ${{ entity_name }}_revision
* The {{ label }} revision ID.
*
* @return array
* An array suitable for drupal_render().
*/
public function revisionShow(${{ entity_name }}_revision) {
${{ entity_name }} = $this->entityManager()->getStorage('{{ entity_name }}')->loadRevision(${{ entity_name }}_revision);
$view_builder = $this->entityManager()->getViewBuilder('{{ entity_name }}');
return $view_builder->view(${{ entity_name }});
}
/**
* Page title callback for a {{ label }} revision.
*
* @param int ${{ entity_name }}_revision
* The {{ label }} revision ID.
*
* @return string
* The page title.
*/
public function revisionPageTitle(${{ entity_name }}_revision) {
${{ entity_name }} = $this->entityManager()->getStorage('{{ entity_name }}')->loadRevision(${{ entity_name }}_revision);
return $this->t('Revision of %title from %date', ['%title' => ${{ entity_name }}->label(), '%date' => format_date(${{ entity_name }}->getRevisionCreationTime())]);
}
/**
* Generates an overview table of older revisions of a {{ label }} .
*
* @param \Drupal\{{ module }}\Entity\{{ entity_class }}Interface ${{ entity_name }}
* A {{ label }} object.
*
* @return array
* An array as expected by drupal_render().
*/
public function revisionOverview({{ entity_class }}Interface ${{ entity_name }}) {
$account = $this->currentUser();
$langcode = ${{ entity_name }}->language()->getId();
$langname = ${{ entity_name }}->language()->getName();
$languages = ${{ entity_name }}->getTranslationLanguages();
$has_translations = (count($languages) > 1);
${{ entity_name }}_storage = $this->entityManager()->getStorage('{{ entity_name }}');
$build['#title'] = $has_translations ? $this->t('@langname revisions for %title', ['@langname' => $langname, '%title' => ${{ entity_name }}->label()]) : $this->t('Revisions for %title', ['%title' => ${{ entity_name }}->label()]);
$header = [$this->t('Revision'), $this->t('Operations')];
$revert_permission = (($account->hasPermission("revert all {{ label|lower }} revisions") || $account->hasPermission('administer {{ label|lower }} entities')));
$delete_permission = (($account->hasPermission("delete all {{ label|lower }} revisions") || $account->hasPermission('administer {{ label|lower }} entities')));
$rows = [];
$vids = ${{ entity_name }}_storage->revisionIds(${{ entity_name }});
$latest_revision = TRUE;
foreach (array_reverse($vids) as $vid) {
/** @var \Drupal\{{ module }}\{{ entity_class }}Interface $revision */
$revision = ${{ entity_name }}_storage->loadRevision($vid);
// Only show revisions that are affected by the language that is being
// displayed.
if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
$username = [
'#theme' => 'username',
'#account' => $revision->getRevisionUser(),
];
// Use revision link to link to revisions that are not active.
$date = \Drupal::service('date.formatter')->format($revision->getRevisionCreationTime(), 'short');
if ($vid != ${{ entity_name }}->getRevisionId()) {
$link = $this->l($date, new Url('entity.{{ entity_name }}.revision', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid]));
}
else {
$link = ${{ entity_name }}->link($date);
}
$row = [];
$column = [
'data' => [
'#type' => 'inline_template',
'#template' => '{{ '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}' }}',
'#context' => [
'date' => $link,
'username' => \Drupal::service('renderer')->renderPlain($username),
'message' => ['#markup' => $revision->getRevisionLogMessage(), '#allowed_tags' => Xss::getHtmlTagList()],
],
],
];
$row[] = $column;
if ($latest_revision) {
$row[] = [
'data' => [
'#prefix' => '<em>',
'#markup' => $this->t('Current revision'),
'#suffix' => '</em>',
],
];
foreach ($row as &$current) {
$current['class'] = ['revision-current'];
}
$latest_revision = FALSE;
}
else {
$links = [];
if ($revert_permission) {
$links['revert'] = [
'title' => $this->t('Revert'),
{% if is_translatable %}
'url' => $has_translations ?
Url::fromRoute('entity.{{ entity_name }}.translation_revert', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid, 'langcode' => $langcode]) :
Url::fromRoute('entity.{{ entity_name }}.revision_revert', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid]),
{% else %}
'url' => Url::fromRoute('entity.{{ entity_name }}.revision_revert', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid]),
{% endif %}
];
}
if ($delete_permission) {
$links['delete'] = [
'title' => $this->t('Delete'),
'url' => Url::fromRoute('entity.{{ entity_name }}.revision_delete', ['{{ entity_name }}' => ${{ entity_name }}->id(), '{{ entity_name }}_revision' => $vid]),
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
}
$rows[] = $row;
}
}
$build['{{ entity_name }}_revisions_table'] = [
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
];
return $build;
}
{% endblock %}

View file

@ -0,0 +1,60 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.{{ bundle_name }}.body
- node.type.{{ bundle_name }}
module:
- path
- text
id: node.{{ bundle_name }}.default
targetEntityType: node
bundle: {{ bundle_name }}
mode: default
content:
body:
type: text_textarea_with_summary
weight: 31
settings:
rows: 9
summary_rows: 3
placeholder: ''
third_party_settings: { }
created:
type: datetime_timestamp
weight: 10
settings: { }
third_party_settings: { }
path:
type: path
weight: 30
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
display_label: true
weight: 15
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 16
third_party_settings: { }
title:
type: string_textfield
weight: -5
settings:
size: 60
placeholder: ''
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 5
settings:
match_operator: CONTAINS
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }

View file

@ -0,0 +1,23 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.{{ bundle_name }}.body
- node.type.{{ bundle_name }}
module:
- text
- user
id: node.{{ bundle_name }}.default
targetEntityType: node
bundle: {{ bundle_name }}
mode: default
content:
body:
label: hidden
type: text_default
weight: 101
settings: { }
third_party_settings: { }
links:
weight: 100
hidden: { }

View file

@ -0,0 +1,25 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.{{ bundle_name }}.body
- node.type.{{ bundle_name }}
module:
- text
- user
id: node.{{ bundle_name }}.teaser
targetEntityType: node
bundle: {{ bundle_name }}
mode: teaser
content:
body:
label: hidden
type: text_summary_or_trimmed
weight: 101
settings:
trim_length: 600
third_party_settings: { }
links:
weight: 100
hidden: { }

View file

@ -0,0 +1,21 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.body
- node.type.{{ bundle_name }}
module:
- text
id: node.{{ bundle_name }}.body
field_name: body
entity_type: node
bundle: {{ bundle_name }}
label: Body
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
display_summary: true
field_type: text_with_summary

View file

@ -0,0 +1,17 @@
langcode: en
status: true
dependencies:
module:
- menu_ui
third_party_settings:
menu_ui:
available_menus:
- main
parent: 'main:'
name: '{{ bundle_title }}'
type: {{ bundle_name }}
description: 'Generated by Drupal Console'
help: ''
new_revision: false
preview_mode: 1
display_submitted: true

View file

@ -0,0 +1,21 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Form\{{ entity_class }}DeleteForm.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\ContentEntityDeleteForm;
{% endblock %}
{% block class_declaration %}
/**
* Provides a form for deleting {{ label }} entities.
*
* @ingroup {{module}}
*/
class {{ entity_class }}DeleteForm extends ContentEntityDeleteForm {% endblock %}

View file

@ -0,0 +1,131 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Form\{{ entity_class }}RevisionDeleteForm.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides a form for deleting a {{ label }} revision.
*
* @ingroup {{module}}
*/
class {{ entity_class }}RevisionDeleteForm extends ConfirmFormBase {% endblock %}
{% block class_methods %}
/**
* The {{ label }} revision.
*
* @var \Drupal\{{module}}\Entity\{{ entity_class }}Interface
*/
protected $revision;
/**
* The {{ label }} storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected ${{ entity_class }}Storage;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new {{ entity_class }}RevisionDeleteForm.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* The entity storage.
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(EntityStorageInterface $entity_storage, Connection $connection) {
$this->{{ entity_class }}Storage = $entity_storage;
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
$entity_manager = $container->get('entity.manager');
return new static(
$entity_manager->getStorage('{{ entity_name }}'),
$container->get('database')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{ entity_name }}_revision_delete_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to delete the revision from %revision-date?', ['%revision-date' => format_date($this->revision->getRevisionCreationTime())]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.{{ entity_name }}.version_history', ['{{ entity_name }}' => $this->revision->id()]);
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, ${{ entity_name }}_revision = NULL) {
$this->revision = $this->{{ entity_class }}Storage->loadRevision(${{ entity_name }}_revision);
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->{{ entity_class }}Storage->deleteRevision($this->revision->getRevisionId());
$this->logger('content')->notice('{{ label }}: deleted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
drupal_set_message(t('Revision from %revision-date of {{ label }} %title has been deleted.', ['%revision-date' => format_date($this->revision->getRevisionCreationTime()), '%title' => $this->revision->label()]));
$form_state->setRedirect(
'entity.{{ entity_name }}.canonical',
['{{ entity_name }}' => $this->revision->id()]
);
if ($this->connection->query('SELECT COUNT(DISTINCT vid) FROM {{ '{'~entity_name~'_field_revision}' }} WHERE id = :id', [':id' => $this->revision->id()])->fetchField() > 1) {
$form_state->setRedirect(
'entity.{{ entity_name }}.version_history',
['{{ entity_name }}' => $this->revision->id()]
);
}
}
{% endblock %}

View file

@ -0,0 +1,123 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Form\{{ entity_class }}RevisionRevertTranslationForm.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\{{module}}\Entity\{{ entity_class }}Interface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides a form for reverting a {{ label }} revision for a single translation.
*
* @ingroup {{module}}
*/
class {{ entity_class }}RevisionRevertTranslationForm extends {{ entity_class }}RevisionRevertForm {% endblock %}
{% block class_methods %}
/**
* The language to be reverted.
*
* @var string
*/
protected $langcode;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a new {{ entity_class }}RevisionRevertTranslationForm.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* The {{ label }} storage.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
*/
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter, LanguageManagerInterface $language_manager) {
parent::__construct($entity_storage, $date_formatter);
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')->getStorage('{{ entity_name }}'),
$container->get('date.formatter'),
$container->get('language_manager')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{ entity_name }}_revision_revert_translation_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to revert @language translation to the revision from %revision-date?', ['@language' => $this->languageManager->getLanguageName($this->langcode), '%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, ${{ entity_name }}_revision = NULL, $langcode = NULL) {
$this->langcode = $langcode;
$form = parent::buildForm($form, $form_state, ${{ entity_name }}_revision);
$form['revert_untranslated_fields'] = [
'#type' => 'checkbox',
'#title' => $this->t('Revert content shared among translations'),
'#default_value' => FALSE,
];
return $form;
}
/**
* {@inheritdoc}
*/
protected function prepareRevertedRevision({{ entity_class }}Interface $revision, FormStateInterface $form_state) {
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
/** @var \Drupal\{{module}}\Entity\{{ entity_class }}Interface $default_revision */
$latest_revision = $this->{{ entity_class }}Storage->load($revision->id());
$latest_revision_translation = $latest_revision->getTranslation($this->langcode);
$revision_translation = $revision->getTranslation($this->langcode);
foreach ($latest_revision_translation->getFieldDefinitions() as $field_name => $definition) {
if ($definition->isTranslatable() || $revert_untranslated_fields) {
$latest_revision_translation->set($field_name, $revision_translation->get($field_name)->getValue());
}
}
$latest_revision_translation->setNewRevision();
$latest_revision_translation->isDefaultRevision(TRUE);
$revision->setRevisionCreationTime(REQUEST_TIME);
return $latest_revision_translation;
}
{% endblock %}

View file

@ -0,0 +1,157 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Form\{{ entity_class }}RevisionRevertForm.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\{{module}}\Entity\{{ entity_class }}Interface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides a form for reverting a {{ label }} revision.
*
* @ingroup {{module}}
*/
class {{ entity_class }}RevisionRevertForm extends ConfirmFormBase {% endblock %}
{% block class_methods %}
/**
* The {{ label }} revision.
*
* @var \Drupal\{{module}}\Entity\{{ entity_class }}Interface
*/
protected $revision;
/**
* The {{ label }} storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected ${{ entity_class }}Storage;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* Constructs a new {{ entity_class }}RevisionRevertForm.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* The {{ label }} storage.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
*/
public function __construct(EntityStorageInterface $entity_storage, DateFormatterInterface $date_formatter) {
$this->{{ entity_class }}Storage = $entity_storage;
$this->dateFormatter = $date_formatter;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')->getStorage('{{ entity_name }}'),
$container->get('date.formatter')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{ entity_name }}_revision_revert_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.{{ entity_name }}.version_history', ['{{ entity_name }}' => $this->revision->id()]);
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Revert');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return '';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, ${{ entity_name }}_revision = NULL) {
$this->revision = $this->{{ entity_class }}Storage->loadRevision(${{ entity_name }}_revision);
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// The revision timestamp will be updated when the revision is saved. Keep
// the original one for the confirmation message.
$original_revision_timestamp = $this->revision->getRevisionCreationTime();
$this->revision = $this->prepareRevertedRevision($this->revision, $form_state);
$this->revision->revision_log = t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
$this->revision->save();
$this->logger('content')->notice('{{ label }}: reverted %title revision %revision.', ['%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
drupal_set_message(t('{{ label }} %title has been reverted to the revision from %revision-date.', ['%title' => $this->revision->label(), '%revision-date' => $this->dateFormatter->format($original_revision_timestamp)]));
$form_state->setRedirect(
'entity.{{ entity_name }}.version_history',
['{{ entity_name }}' => $this->revision->id()]
);
}
/**
* Prepares a revision to be reverted.
*
* @param \Drupal\{{module}}\Entity\{{ entity_class }}Interface $revision
* The revision to be reverted.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\{{module}}\Entity\{{ entity_class }}Interface
* The prepared revision ready to be stored.
*/
protected function prepareRevertedRevision({{ entity_class }}Interface $revision, FormStateInterface $form_state) {
$revision->setNewRevision();
$revision->isDefaultRevision(TRUE);
$revision->setRevisionCreationTime(REQUEST_TIME);
return $revision;
}
{% endblock %}

View file

@ -0,0 +1,83 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Form\{{ entity_class }}Form.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
{% endblock %}
{% block class_declaration %}
/**
* Form controller for {{ label }} edit forms.
*
* @ingroup {{module}}
*/
class {{ entity_class }}Form extends ContentEntityForm {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */
$form = parent::buildForm($form, $form_state);
{% if revisionable %}
if (!$this->entity->isNew()) {
$form['new_revision'] = [
'#type' => 'checkbox',
'#title' => $this->t('Create new revision'),
'#default_value' => FALSE,
'#weight' => 10,
];
}
{% endif %}
$entity = $this->entity;
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
{% if revisionable %}
// Save as a new revision if requested to do so.
if (!$form_state->isValueEmpty('new_revision') && $form_state->getValue('new_revision') != FALSE) {
$entity->setNewRevision();
// If a new revision is created, save the current user as revision author.
$entity->setRevisionCreationTime(REQUEST_TIME);
$entity->setRevisionUserId(\Drupal::currentUser()->id());
}
else {
$entity->setNewRevision(FALSE);
}
{% endif %}
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label {{ label }}.', [
'%label' => $entity->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label {{ label }}.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.{{ entity_name }}.canonical', ['{{ entity_name }}' => $entity->id()]);
}
{% endblock %}

View file

@ -0,0 +1,61 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Form\{{ entity_class }}SettingsForm.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ entity_class }}SettingsForm.
*
* @ingroup {{module}}
*/
class {{ entity_class }}SettingsForm extends FormBase {% endblock %}
{% block class_methods %}
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return '{{ entity_class|lower }}_settings';
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Empty implementation of the abstract submit class.
}
/**
* Defines the settings form for {{ label }} entities.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* Form definition array.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['{{ entity_class|lower }}_settings']['#markup'] = 'Settings form for {{ label }} entities. Manage field settings here.';
return $form;
}
{% endblock %}

View file

@ -0,0 +1,32 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Entity\{{ entity_class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Entity;
{% endblock %}
{% block use_class %}
use Drupal\views\EntityViewsData;
{% endblock %}
{% block class_declaration %}
/**
* Provides Views data for {{ label }} entities.
*/
class {{ entity_class }}ViewsData extends EntityViewsData {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
{% endblock %}

View file

@ -0,0 +1,16 @@
{% block hook_theme %}
/**
* Implements hook_theme().
*/
function {{ module }}_theme() {
$theme = [];
{% include '/module/src/Entity/entity-content.theme.php.twig' with {'entity_name': entity_name, } %}
$theme['{{ entity_name }}_content_add_list'] = [
'render element' => 'content',
'variables' => ['content' => NULL],
'file' => '{{ entity_name }}.page.inc',
];
return $theme;
}
{% endblock %}

View file

@ -0,0 +1,18 @@
{% block hook_theme_suggestions_hook %}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function {{ module }}_theme_suggestions_{{ entity_name }}(array $variables) {
$suggestions = [];
$entity = $variables['elements']['#{{ entity_name }}'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = '{{ entity_name }}__' . $sanitized_view_mode;
$suggestions[] = '{{ entity_name }}__' . $entity->bundle();
$suggestions[] = '{{ entity_name }}__' . $entity->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = '{{ entity_name }}__' . $entity->id();
$suggestions[] = '{{ entity_name }}__' . $entity->id() . '__' . $sanitized_view_mode;
return $suggestions;
}
{% endblock %}

View file

@ -0,0 +1,333 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Entity\{{ entity_class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Entity;
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
{% if revisionable %}
use Drupal\Core\Entity\RevisionableContentEntityBase;
use Drupal\Core\Entity\RevisionableInterface;
{% else %}
use Drupal\Core\Entity\ContentEntityBase;
{% endif %}
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
{% endblock %}
{% block class_declaration %}
/**
* Defines the {{ label }} entity.
*
* @ingroup {{ module }}
*
* @ContentEntityType(
* id = "{{ entity_name }}",
* label = @Translation("{{ label }}"),
{% if bundle_entity_type %}
* bundle_label = @Translation("{{ label }} type"),
{% endif %}
* handlers = {
{% if revisionable %}
* "storage" = "Drupal\{{ module }}\{{ entity_class }}Storage",
{% endif %}
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\{{ module }}\{{ entity_class }}ListBuilder",
* "views_data" = "Drupal\{{ module }}\Entity\{{ entity_class }}ViewsData",
{% if is_translatable %}
* "translation" = "Drupal\{{ module }}\{{ entity_class }}TranslationHandler",
{% endif %}
*
* "form" = {
* "default" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "add" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "edit" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "delete" = "Drupal\{{ module }}\Form\{{ entity_class }}DeleteForm",
* },
* "access" = "Drupal\{{ module }}\{{ entity_class }}AccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\{{ module }}\{{ entity_class }}HtmlRouteProvider",
* },
* },
* base_table = "{{ entity_name }}",
{% if is_translatable %}
* data_table = "{{ entity_name }}_field_data",
{% endif %}
{% if revisionable %}
* revision_table = "{{ entity_name }}_revision",
* revision_data_table = "{{ entity_name }}_field_revision",
{% endif %}
{% if is_translatable %}
* translatable = TRUE,
{% endif %}
* admin_permission = "administer {{ label|lower }} entities",
* entity_keys = {
* "id" = "id",
{% if revisionable %}
* "revision" = "vid",
{% endif %}
{% if bundle_entity_type %}
* "bundle" = "type",
{% endif %}
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "status" = "status",
* },
* links = {
* "canonical" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}",
{% if bundle_entity_type %}
* "add-page" = "{{ base_path }}/{{ entity_name }}/add",
* "add-form" = "{{ base_path }}/{{ entity_name }}/add/{{ '{'~bundle_entity_type~'}' }}",
{% else %}
* "add-form" = "{{ base_path }}/{{ entity_name }}/add",
{% endif %}
* "edit-form" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/edit",
* "delete-form" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/delete",
{% if revisionable %}
* "version-history" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/revisions",
* "revision" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/revisions/{{ '{'~entity_name~'_revision}' }}/view",
* "revision_revert" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/revisions/{{ '{'~entity_name~'_revision}' }}/revert",
* "revision_delete" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/revisions/{{ '{'~entity_name~'_revision}' }}/delete",
{% if is_translatable %}
* "translation_revert" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/revisions/{{ '{'~entity_name~'_revision}' }}/revert/{langcode}",
{% endif %}
{% endif %}
* "collection" = "{{ base_path }}/{{ entity_name }}",
* },
{% if bundle_entity_type %}
* bundle_entity_type = "{{ bundle_entity_type }}",
* field_ui_base_route = "entity.{{ bundle_entity_type }}.edit_form"
{% else %}
* field_ui_base_route = "{{ entity_name }}.settings"
{% endif %}
* )
*/
class {{ entity_class }} extends {% if revisionable %}RevisionableContentEntityBase{% else %}ContentEntityBase{% endif %} implements {{ entity_class }}Interface {% endblock %}
{% block use_trait %}
use EntityChangedTrait;
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'user_id' => \Drupal::currentUser()->id(),
];
}
{% if revisionable %}
/**
* {@inheritdoc}
*/
protected function urlRouteParameters($rel) {
$uri_route_parameters = parent::urlRouteParameters($rel);
if ($rel === 'revision_revert' && $this instanceof RevisionableInterface) {
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
}
elseif ($rel === 'revision_delete' && $this instanceof RevisionableInterface) {
$uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
}
return $uri_route_parameters;
}
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
$translation = $this->getTranslation($langcode);
// If no owner has been set explicitly, make the anonymous user the owner.
if (!$translation->getOwner()) {
$translation->setOwnerId(0);
}
}
// If no revision author has been set explicitly, make the {{ entity_name }} owner the
// revision author.
if (!$this->getRevisionUser()) {
$this->setRevisionUserId($this->getOwnerId());
}
}
{% endif %}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getCreatedTime() {
return $this->get('created')->value;
}
/**
* {@inheritdoc}
*/
public function setCreatedTime($timestamp) {
$this->set('created', $timestamp);
return $this;
}
/**
* {@inheritdoc}
*/
public function getOwner() {
return $this->get('user_id')->entity;
}
/**
* {@inheritdoc}
*/
public function getOwnerId() {
return $this->get('user_id')->target_id;
}
/**
* {@inheritdoc}
*/
public function setOwnerId($uid) {
$this->set('user_id', $uid);
return $this;
}
/**
* {@inheritdoc}
*/
public function setOwner(UserInterface $account) {
$this->set('user_id', $account->id());
return $this;
}
/**
* {@inheritdoc}
*/
public function isPublished() {
return (bool) $this->getEntityKey('status');
}
/**
* {@inheritdoc}
*/
public function setPublished($published) {
$this->set('status', $published ? TRUE : FALSE);
return $this;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of author of the {{ label }} entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setTranslatable(TRUE)
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the {{ label }} entity.'))
{% if revisionable %}
->setRevisionable(TRUE)
{% endif %}
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the {{ label }} is published.'))
{% if revisionable %}
->setRevisionable(TRUE)
{% endif %}
->setDefaultValue(TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'weight' => -3,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
{% if revisionable and is_translatable %}
$fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Revision translation affected'))
->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
->setReadOnly(TRUE)
->setRevisionable(TRUE)
->setTranslatable(TRUE);
{% endif %}
return $fields;
}
{% endblock %}

View file

@ -0,0 +1,7 @@
{% block hook_theme %}
$theme['{{ entity_name }}'] = [
'render element' => 'elements',
'file' => '{{ entity_name }}.page.inc',
'template' => '{{ entity_name }}',
];
{% endblock %}

View file

@ -0,0 +1,72 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Entity\{{ entity_class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Entity;
{% endblock %}
{% block use_class %}
{% if bundle_of %}
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
{% else %}
use Drupal\Core\Config\Entity\ConfigEntityBase;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Defines the {{ label }} entity.
*
* @ConfigEntityType(
* id = "{{ entity_name }}",
* label = @Translation("{{ label }}"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\{{ module }}\{{ entity_class }}ListBuilder",
* "form" = {
* "add" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "edit" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "delete" = "Drupal\{{ module }}\Form\{{ entity_class }}DeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\{{ module }}\{{ entity_class }}HtmlRouteProvider",
* },
* },
* config_prefix = "{{ entity_name }}",
* admin_permission = "administer site configuration",
{% if bundle_of %}
* bundle_of = "{{ bundle_of }}",
{% endif %}
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}",
* "add-form" = "{{ base_path }}/{{ entity_name }}/add",
* "edit-form" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/edit",
* "delete-form" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}/delete",
* "collection" = "{{ base_path }}/{{ entity_name }}"
* }
* )
*/
class {{ entity_class }} extends {% if bundle_of %}ConfigEntityBundleBase{% else %}ConfigEntityBase{% endif %} implements {{ entity_class }}Interface {% endblock %}
{% block class_methods %}
/**
* The {{ label }} ID.
*
* @var string
*/
protected $id;
/**
* The {{ label }} label.
*
* @var string
*/
protected $label;
{% endblock %}

View file

@ -0,0 +1,128 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Entity\{{ entity_class }}Interface.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Entity;
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\ContentEntityInterface;
{% if revisionable %}
use Drupal\Core\Entity\RevisionLogInterface;
{% endif %}
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\user\EntityOwnerInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides an interface for defining {{ label }} entities.
*
* @ingroup {{module}}
*/
interface {{ entity_class }}Interface extends ContentEntityInterface{% if revisionable %}, RevisionLogInterface{% endif %}, EntityChangedInterface, EntityOwnerInterface {% endblock %}
{% block class_methods %}
// Add get/set methods for your configuration properties here.
/**
* Gets the {{ label }} name.
*
* @return string
* Name of the {{ label }}.
*/
public function getName();
/**
* Sets the {{ label }} name.
*
* @param string $name
* The {{ label }} name.
*
* @return \Drupal\{{ module }}\Entity\{{ entity_class }}Interface
* The called {{ label }} entity.
*/
public function setName($name);
/**
* Gets the {{ label }} creation timestamp.
*
* @return int
* Creation timestamp of the {{ label }}.
*/
public function getCreatedTime();
/**
* Sets the {{ label }} creation timestamp.
*
* @param int $timestamp
* The {{ label }} creation timestamp.
*
* @return \Drupal\{{ module }}\Entity\{{ entity_class }}Interface
* The called {{ label }} entity.
*/
public function setCreatedTime($timestamp);
/**
* Returns the {{ label }} published status indicator.
*
* Unpublished {{ label }} are only visible to restricted users.
*
* @return bool
* TRUE if the {{ label }} is published.
*/
public function isPublished();
/**
* Sets the published status of a {{ label }}.
*
* @param bool $published
* TRUE to set this {{ label }} to published, FALSE to set it to unpublished.
*
* @return \Drupal\{{ module }}\Entity\{{ entity_class }}Interface
* The called {{ label }} entity.
*/
public function setPublished($published);
{% if revisionable %}
/**
* Gets the {{ label }} revision creation timestamp.
*
* @return int
* The UNIX timestamp of when this revision was created.
*/
public function getRevisionCreationTime();
/**
* Sets the {{ label }} revision creation timestamp.
*
* @param int $timestamp
* The UNIX timestamp of when this revision was created.
*
* @return \Drupal\{{ module }}\Entity\{{ entity_class }}Interface
* The called {{ label }} entity.
*/
public function setRevisionCreationTime($timestamp);
/**
* Gets the {{ label }} revision author.
*
* @return \Drupal\user\UserInterface
* The user entity for the revision author.
*/
public function getRevisionUser();
/**
* Sets the {{ label }} revision author.
*
* @param int $uid
* The user ID of the revision author.
*
* @return \Drupal\{{ module }}\Entity\{{ entity_class }}Interface
* The called {{ label }} entity.
*/
public function setRevisionUserId($uid);
{% endif %}
{% endblock %}

View file

@ -0,0 +1,21 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Entity\{{ entity_class }}Interface.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Entity;
{% endblock %}
{% block use_class %}
use Drupal\Core\Config\Entity\ConfigEntityInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides an interface for defining {{ label }} entities.
*/
interface {{ entity_class }}Interface extends ConfigEntityInterface {% endblock %}
{% block class_methods %}
// Add get/set methods for your configuration properties here.{% endblock %}

View file

@ -0,0 +1,61 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Form\{{ entity_class }}DeleteForm.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
{% endblock %}
{% block class_declaration %}
/**
* Builds the form to delete {{ label }} entities.
*/
class {{ entity_class }}DeleteForm extends EntityConfirmFormBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.{{ entity_name }}.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(
$this->t('content @type: deleted @label.',
[
'@type' => $this->entity->bundle(),
'@label' => $this->entity->label(),
]
)
);
$form_state->setRedirectUrl($this->getCancelUrl());
}
{% endblock %}

View file

@ -0,0 +1,73 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Form\{{ entity_class }}Form.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ entity_class }}Form.
*/
class {{ entity_class }}Form extends EntityForm {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
${{ entity_name | machine_name }} = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => ${{ entity_name | machine_name }}->label(),
'#description' => $this->t("Label for the {{ label }}."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => ${{ entity_name | machine_name }}->id(),
'#machine_name' => [
'exists' => '\Drupal\{{ module }}\Entity\{{ entity_class }}::load',
],
'#disabled' => !${{ entity_name | machine_name }}->isNew(),
];
/* You will need additional form elements for your custom properties. */
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
${{ entity_name | machine_name }} = $this->entity;
$status = ${{ entity_name | machine_name }}->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label {{ label }}.', [
'%label' => ${{ entity_name | machine_name }}->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label {{ label }}.', [
'%label' => ${{ entity_name | machine_name }}->label(),
]));
}
$form_state->setRedirectUrl(${{ entity_name | machine_name }}->toUrl('collection'));
}
{% endblock %}

View file

@ -0,0 +1,63 @@
{% block use_class %}
use Drupal\Core\Form\FormStateInterface;
{% endblock %}
{% block file_methods %}
{% if form_id is not empty %}
/**
* Implements hook_form_FORM_ID_alter() on behalf of {{ module }}.module.
{% if metadata.class is defined %}
* @see \{{ metadata.class }} method {{ metadata.method }} at {{ metadata.file }}
{% endif %}
*/
function {{ module }}_form_{{ form_id }}_alter(&$form, FormStateInterface $form_state) {
drupal_set_message('{{ module }}_form_{{ form_id }}_alter() executed.');
{% else %}
/**
* Implements hook_form_alter() on behalf of {{ module }}.module.
*/
function {{ module }}_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Change form id here
if ($form_id == 'form_test_alter_form') {
drupal_set_message('form_test_form_alter() executed.');
{% endif %}
{%- if metadata.unset -%}
{% for field in metadata.unset %}
$form['{{ field }}']['#access'] = FALSE;
{% endfor %}
{% endif %}
{% if inputs %}
{% for input in inputs %}
$form['{{ input.name }}'] = [
'#type' => '{{ input.type }}',
'#title' => t('{{ input.label|e }}'),
{%- if input.description is defined and input.description is defined -%}
'#description' => t('{{ input.description|e }}'),
{% endif %}
{%- if input.options is defined and input.options|length -%}
'#options' => {{ input.options }},
{% endif %}
{%- if input.maxlength is defined and input.maxlength|length -%}
'#maxlength' => {{ input.maxlength }},
{% endif %}
{%- if input.size is defined and input.size|length -%}
'#size' => {{ input.size }},
{% endif %}
{%- if input.default_value is defined and input.default_value|length -%}
'#default_value' => '{{ input.default_value }}',
{% endif %}
{%- if input.weight is defined and input.weight|length -%}
'#weight' => '{{ input.weight }}',
{% endif %}
];
{% endfor %}
{% endif %}
{% if form_id is empty %}
}
{% endif %}
}
{% endblock %}

View file

@ -0,0 +1,122 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
Drupal\{{module_name}}\Form\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module_name}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
{% if services is not empty %}
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}.
*/
class {{ class_name }} extends ConfigFormBase {% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Constructs a new {{ class_name }} object.
*/
public function __construct(
ConfigFactoryInterface $config_factory,
{{ servicesAsParameters(services)|join(',\n ') }}
) {
parent::__construct($config_factory);
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'{{module_name}}.{{class_name_short}}',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{form_id}}';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('{{module_name}}.{{class_name_short}}');
{% for input in inputs %}
{% if input.fieldset is defined and input.fieldset is not empty %}
$form['{{ input.fieldset }}']['{{ input.name }}'] = [
{% else %}
$form['{{ input.name }}'] = [
{% endif %}
'#type' => '{{ input.type }}',
'#title' => $this->t('{{ input.label|e }}'),
{% if input.description is defined and input.description|length %}
'#description' => $this->t('{{ input.description|e }}'),
{% endif %}
{% if input.options is defined and input.options is not empty %}
'#options' => {{ input.options }},
{% endif %}
{% if input.maxlength is defined and input.maxlength is not empty %}
'#maxlength' => {{ input.maxlength }},
{% endif %}
{% if input.size is defined and input.size is not empty %}
'#size' => {{ input.size }},
{% endif %}
{% if input.type != 'password_confirm' and input.type != 'fieldset' %}
'#default_value' => $config->get('{{ input.name }}'),
{% endif %}
];
{% endfor %}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this->config('{{module_name}}.{{class_name_short}}')
{% for input in inputs %}
->set('{{ input.name }}', $form_state->getValue('{{ input.name }}'))
{% endfor %}
->save();
}
{% endblock %}

View file

@ -0,0 +1,115 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module_name}}\Form\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module_name}}\Form;
{% endblock %}
{% block use_class %}
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
{% if services is not empty %}
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}.
*/
class {{ class_name }} extends FormBase {% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Constructs a new {{ class_name }} object.
*/
public function __construct(
{{ servicesAsParameters(services)|join(',\n ') }}
) {
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
public static function create(ContainerInterface $container) {
return new static(
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function getFormId() {
return '{{form_id}}';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
{% for input in inputs %}
{% if input.fieldset is defined and input.fieldset|length %}
$form['{{ input.fieldset }}']['{{ input.name }}'] = [
{% else %}
$form['{{ input.name }}'] = [
{% endif %}
'#type' => '{{ input.type }}',
'#title' => $this->t('{{ input.label|e }}'),
{% if input.description is defined and input.description|length %}
'#description' => $this->t('{{ input.description|e }}'),
{% endif %}
{% if input.options is defined and input.options|length %}
'#options' => {{ input.options }},
{% endif %}
{% if input.maxlength is defined and input.maxlength|length %}
'#maxlength' => {{ input.maxlength }},
{% endif %}
{% if input.size is defined and input.size|length %}
'#size' => {{ input.size }},
{% endif %}
{% if input.default_value is defined and input.default_value|length %}
'#default_value' => {{ input.default_value }},
{% endif %}
{% if input.weight is defined and input.weight|length %}
'#weight' => '{{ input.weight }}',
{% endif %}
];
{% endfor %}
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Display result.
foreach ($form_state->getValues() as $key => $value) {
drupal_set_message($key . ': ' . $value);
}
}
{% endblock %}

View file

@ -0,0 +1,38 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{extension}}\Generator\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{extension}}\Generator;
{% endblock %}
{% block use_class %}
use Drupal\Console\Core\Generator\Generator;
use Drupal\Console\Core\Generator\GeneratorInterface;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class_name }}
*
* @package Drupal\Console\Generator
*/
class {{ class_name }} extends Generator implements GeneratorInterface
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function generate(array $parameters)
{
// Example how to render a twig template using the renderFile method
// $this->renderFile(
// 'path/to/file.php.twig',
// 'path/to/file.php',
// $parameters
// );
}
{% endblock %}

View file

@ -0,0 +1,44 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\Action\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\Action;
{% endblock %}
{% block use_class %}
use Drupal\Core\Action\ActionBase;
use Drupal\Core\Session\AccountInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{class_name}}' action.
*
* @Action(
* id = "{{plugin_id}}",
* label = @Translation("{{label}}"),
* type = "{{type}}",
* )
*/
class {{class_name}} extends ActionBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function execute($object = NULL) {
// Insert code here.
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$access = $object->status->access('edit', $account, TRUE)
->andIf($object->access('update', $account, TRUE));
return $return_as_object ? $access : $access->isAllowed();
}
{% endblock %}

View file

@ -0,0 +1,138 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\Block\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\Block;
{% endblock %}
{% block use_class %}
use Drupal\Core\Block\BlockBase;
{% if inputs %}
use Drupal\Core\Form\FormStateInterface;
{% endif %}
{% if services is not empty %}
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{class_name}}' block.
*
* @Block(
* id = "{{plugin_id}}",
* admin_label = @Translation("{{label}}"),
* )
*/
class {{class_name}} extends BlockBase {% if services is not empty %}implements ContainerFactoryPluginInterface {% endif %}{% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Constructs a new {{class_name}} object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param string $plugin_definition
* The plugin implementation definition.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
{{ servicesAsParameters(services)|join(', \n\t') }}
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
{% if inputs %}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
{% for input in inputs %}
{% if input.default_value is defined and input.default_value|length %}
'{{ input.name }}' => {{ input.default_value }},
{% endif %}
{% endfor %}
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function blockForm($form, FormStateInterface $form_state) {
{% for input in inputs %}
$form['{{ input.name }}'] = [
'#type' => '{{ input.type }}',
'#title' => $this->t('{{ input.label|escape }}'),
{% if input.description is defined and input.description is not empty %}
'#description' => $this->t('{{ input.description|e }}'),
{% endif %}
{% if input.options is defined and input.options|length %}
'#options' => {{ input.options }},
{% endif %}
'#default_value' => $this->configuration['{{ input.name }}'],
{% if input.maxlength is defined and input.maxlength|length %}
'#maxlength' => {{ input.maxlength }},
{% endif %}
{% if input.size is defined and input.size|length %}
'#size' => {{ input.size }},
{% endif %}
{% if input.weight is defined and input.weight|length %}
'#weight' => '{{ input.weight }}',
{% endif %}
];
{% endfor %}
return $form;
}
/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $form_state) {
{% for input in inputs %}
$this->configuration['{{ input.name }}'] = $form_state->getValue('{{ input.name }}');
{% endfor %}
}
{% endif %}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
{% for input in inputs %}
$build['{{plugin_id}}_{{ input.name }}']['#markup'] = '<p>' . $this->configuration['{{ input.name }}'] . '</p>';
{% else %}
$build['{{plugin_id}}']['#markup'] = 'Implement {{class_name}}.';
{% endfor %}
return $build;
}
{% endblock %}

View file

@ -0,0 +1,86 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\CKEditorPlugin\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin\CKEditorPlugin;
{% endblock %}
{% block use_class %}
use Drupal\ckeditor\CKEditorPluginBase;
use Drupal\editor\Entity\Editor;
{% endblock %}
{% block class_declaration %}
/**
* Defines the "{{ plugin_id }}" plugin.
*
* NOTE: The plugin ID ('id' key) corresponds to the CKEditor plugin name.
* It is the first argument of the CKEDITOR.plugins.add() function in the
* plugin.js file.
*
* @CKEditorPlugin(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}")
* )
*/
class {{ class_name }} extends CKEditorPluginBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*
* NOTE: The keys of the returned array corresponds to the CKEditor button
* names. They are the first argument of the editor.ui.addButton() or
* editor.ui.addRichCombo() functions in the plugin.js file.
*/
public function getButtons() {
// Make sure that the path to the image matches the file structure of
// the CKEditor plugin you are implementing.
return [
'{{ button_name }}' => [
'label' => t('{{ label }}'),
'image' => '{{ button_icon_path }}',
],
];
}
/**
* {@inheritdoc}
*/
public function getFile() {
// Make sure that the path to the plugin.js matches the file structure of
// the CKEditor plugin you are implementing.
return drupal_get_path('module', '{{ module }}') . '/js/plugins/{{ plugin_id }}/plugin.js';
}
/**
* {@inheritdoc}
*/
public function isInternal() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getDependencies(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
public function getLibraries(Editor $editor) {
return [];
}
/**
* {@inheritdoc}
*/
public function getConfig(Editor $editor) {
return [];
}
{% endblock %}

View file

@ -0,0 +1,129 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\Condition\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin\Condition;
{% endblock %}
{% block use_class %}
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\ContextDefinition;
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{ label }}' condition to enable a condition based in module selected status.
*
* @Condition(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}"),
* context = {
* "{{ context_id }}" = @ContextDefinition("{{ context_definition_id }}", required = {{ context_definition_required }} , label = @Translation("{{ context_definition_label }}"))
* }
* )
*
*/
class {{ class_name }} extends ConditionPluginBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
{
return new static(
$configuration,
$plugin_id,
$plugin_definition
);
}
/**
* Creates a new {{ class_name }} object.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Sort all modules by their names.
$modules = system_rebuild_module_data();
uasort($modules, 'system_sort_modules_by_info_name');
$options = [NULL => t('Select a module')];
foreach($modules as $module_id => $module) {
$options[$module_id] = $module->info['name'];
}
$form['module'] = [
'#type' => 'select',
'#title' => $this->t('Select a module to validate'),
'#default_value' => $this->configuration['module'],
'#options' => $options,
'#description' => $this->t('Module selected status will be use to evaluate condition.'),
];
return parent::buildConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['module'] = $form_state->getValue('module');
parent::submitConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return ['module' => ''] + parent::defaultConfiguration();
}
/**
* Evaluates the condition and returns TRUE or FALSE accordingly.
*
* @return bool
* TRUE if the condition has been met, FALSE otherwise.
*/
public function evaluate() {
if (empty($this->configuration['module']) && !$this->isNegated()) {
return TRUE;
}
$module = $this->configuration['module'];
$modules = system_rebuild_module_data();
return $modules[$module]->status;
}
/**
* Provides a human readable summary of the condition's configuration.
*/
public function summary()
{
$module = $this->getContextValue('module');
$modules = system_rebuild_module_data();
$status = ($modules[$module]->status)?t('enabled'):t('disabled');
return t('The module @module is @status.', ['@module' => $module, '@status' => $status]);
}
{% endblock %}

View file

@ -0,0 +1,93 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\Field\FieldFormatter\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin\Field\FieldFormatter;
{% endblock %}
{% block use_class %}
use Drupal\Component\Utility\Html;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface;
{% endblock %}
{% block class_declaration %}
/**
* Plugin implementation of the '{{ plugin_id }}' formatter.
*
* @FieldFormatter(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}"){% if field_type %},
* field_types = {
* "{{ field_type }}"
* }
{% else %}
* At least one field_types annotation array entry is necessary to display this formatter in the UI.
* ex. field_types = { "field_type" }
{% endif %}
* )
*/
class {{ class_name }} extends FormatterBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
// Implement default settings.
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
return [
// Implement settings form.
] + parent::settingsForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
// Implement settings summary.
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
foreach ($items as $delta => $item) {
$elements[$delta] = ['#markup' => $this->viewValue($item)];
}
return $elements;
}
/**
* Generate the output appropriate for one field item.
*
* @param \Drupal\Core\Field\FieldItemInterface $item
* One field item.
*
* @return string
* The textual output generated.
*/
protected function viewValue(FieldItemInterface $item) {
// The text value has no text format assigned to it, so the user input
// should equal the output, including newlines.
return nl2br(Html::escape($item->value));
}
{% endblock %}

View file

@ -0,0 +1,224 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\Field\FieldFormatter\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin\Field\FieldFormatter;
{% endblock %}
{% block use_class %}
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\Core\Utility\LinkGeneratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Cache\Cache;
{% endblock %}
{% block class_declaration %}
/**
* Plugin implementation of the '{{ plugin_id }}' formatter.
*
* @FieldFormatter(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}"),
* field_types = {
* "image"
* }
* )
*/
class {{ class_name }} extends ImageFormatterBase implements ContainerFactoryPluginInterface {% endblock %}
{% block class_methods %}
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The link generator.
*
* @var \Drupal\Core\Utility\LinkGeneratorInterface
*/
protected $linkGenerator;
/**
* The image style entity storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $imageStyleStorage;
/**
* Constructs a new {{ class_name }} object.
*
* @param string $plugin_id
* The plugin_id for the formatter.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the formatter is associated.
* @param array $settings
* The formatter settings.
* @param string $label
* The formatter label display setting.
* @param string $view_mode
* The view mode.
* @param array $third_party_settings
* Any third party settings settings.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
* The link generator service.
* @param \Drupal\Core\Entity\EntityStorageInterface $image_style_storage
* The entity storage for the image.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, LinkGeneratorInterface $link_generator, EntityStorageInterface $image_style_storage) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->currentUser = $current_user;
$this->linkGenerator = $link_generator;
$this->imageStyleStorage = $image_style_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$plugin_id,
$plugin_definition,
$configuration['field_definition'],
$configuration['settings'],
$configuration['label'],
$configuration['view_mode'],
$configuration['third_party_settings'],
$container->get('current_user'),
$container->get('link_generator'),
$container->get('entity_type.manager')->getStorage('image_style')
);
}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'image_style' => '',
'image_link' => '',
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$image_styles = image_style_options(FALSE);
$element['image_style'] = [
'#title' => t('Image style'),
'#type' => 'select',
'#default_value' => $this->getSetting('image_style'),
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
'#description' => [
'#markup' => $this->linkGenerator->generate($this->t('Configure Image Styles'), new Url('entity.image_style.collection')),
'#access' => $this->currentUser->hasPermission('administer image styles'),
],
];
return $element;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
$image_styles = image_style_options(FALSE);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
// Styles could be lost because of enabled/disabled modules that defines
// their styles in code.
$image_style_setting = $this->getSetting('image_style');
if (isset($image_styles[$image_style_setting])) {
$summary[] = t('Image style: @style', ['@style' => $image_styles[$image_style_setting]]);
}
else {
$summary[] = t('Original image');
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = [];
$files = $this->getEntitiesToView($items, $langcode);
// Early opt-out if the field is empty.
if (empty($files)) {
return $elements;
}
$url = NULL;
$image_link_setting = $this->getSetting('image_link');
// Check if the formatter involves a link.
if ($image_link_setting == 'content') {
$entity = $items->getEntity();
if (!$entity->isNew()) {
$url = $entity->toUrl();
}
}
elseif ($image_link_setting == 'file') {
$link_file = TRUE;
}
$image_style_setting = $this->getSetting('image_style');
// Collect cache tags to be added for each item in the field.
$cache_tags = [];
if (!empty($image_style_setting)) {
$image_style = $this->imageStyleStorage->load($image_style_setting);
$cache_tags = $image_style->getCacheTags();
}
foreach ($files as $delta => $file) {
if (isset($link_file)) {
$image_uri = $file->getFileUri();
$url = Url::fromUri(file_create_url($image_uri));
}
$cache_tags = Cache::mergeTags($cache_tags, $file->getCacheTags());
// Extract field item attributes for the theme function, and unset them
// from the $item so that the field template does not re-render them.
$item = $file->_referringItem;
$item_attributes = $item->_attributes;
unset($item->_attributes);
$elements[$delta] = [
'#theme' => 'image_formatter',
'#item' => $item,
'#item_attributes' => $item_attributes,
'#image_style' => $image_style_setting,
'#url' => $url,
'#cache' => [
'tags' => $cache_tags,
],
];
}
return $elements;
}
{% endblock %}

View file

@ -0,0 +1,143 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\Field\FieldType\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin\Field\FieldType;
{% endblock %}
{% block use_class %}
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;
{% endblock %}
{% block class_declaration %}
/**
* Plugin implementation of the '{{ plugin_id }}' field type.
*
* @FieldType(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}"),
* description = @Translation("{{ description }}"){% if default_widget or default_formatter %},
{% endif %}
{% if default_widget %}
* default_widget = "{{ default_widget }}"{% if default_widget and default_formatter %},
{% endif %}
{% else %}
{% endif %}
{% if default_formatter %}
* default_formatter = "{{ default_formatter }}"
{% else %}
{% endif %}
* )
*/
class {{ class_name }} extends FieldItemBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function defaultStorageSettings() {
return [
'max_length' => 255,
'is_ascii' => FALSE,
'case_sensitive' => FALSE,
] + parent::defaultStorageSettings();
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
// Prevent early t() calls by using the TranslatableMarkup.
$properties['value'] = DataDefinition::create('string')
->setLabel(new TranslatableMarkup('Text value'))
->setSetting('case_sensitive', $field_definition->getSetting('case_sensitive'))
->setRequired(TRUE);
return $properties;
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = [
'columns' => [
'value' => [
'type' => $field_definition->getSetting('is_ascii') === TRUE ? 'varchar_ascii' : 'varchar',
'length' => (int) $field_definition->getSetting('max_length'),
'binary' => $field_definition->getSetting('case_sensitive'),
],
],
];
return $schema;
}
/**
* {@inheritdoc}
*/
public function getConstraints() {
$constraints = parent::getConstraints();
if ($max_length = $this->getSetting('max_length')) {
$constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints[] = $constraint_manager->create('ComplexData', [
'value' => [
'Length' => [
'max' => $max_length,
'maxMessage' => t('%name: may not be longer than @max characters.', [
'%name' => $this->getFieldDefinition()->getLabel(),
'@max' => $max_length
]),
],
],
]);
}
return $constraints;
}
/**
* {@inheritdoc}
*/
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
$random = new Random();
$values['value'] = $random->word(mt_rand(1, $field_definition->getSetting('max_length')));
return $values;
}
/**
* {@inheritdoc}
*/
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$elements = [];
$elements['max_length'] = [
'#type' => 'number',
'#title' => t('Maximum length'),
'#default_value' => $this->getSetting('max_length'),
'#required' => TRUE,
'#description' => t('The maximum length of the field in characters.'),
'#min' => 1,
'#disabled' => $has_data,
];
return $elements;
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
return $value === NULL || $value === '';
}
{% endblock %}

View file

@ -0,0 +1,97 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\Field\FieldWidget\{{ class_name }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin\Field\FieldWidget;
{% endblock %}
{% block use_class %}
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
{% endblock %}
{% block class_declaration %}
/**
* Plugin implementation of the '{{ plugin_id }}' widget.
*
* @FieldWidget(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}"){% if field_type %},
* field_types = {
* "{{ field_type }}"
* }
{% else %}
* At least one field_types annotation array entry is necessary to display this formatter in the UI.
* ex. field_types = { "field_type" }
{% endif %}
* )
*/
class {{ class_name }} extends WidgetBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
return [
'size' => 60,
'placeholder' => '',
] + parent::defaultSettings();
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = [];
$elements['size'] = [
'#type' => 'number',
'#title' => t('Size of textfield'),
'#default_value' => $this->getSetting('size'),
'#required' => TRUE,
'#min' => 1,
];
$elements['placeholder'] = [
'#type' => 'textfield',
'#title' => t('Placeholder'),
'#default_value' => $this->getSetting('placeholder'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
];
return $elements;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = [];
$summary[] = t('Textfield size: @size', ['@size' => $this->getSetting('size')]);
if (!empty($this->getSetting('placeholder'))) {
$summary[] = t('Placeholder: @placeholder', ['@placeholder' => $this->getSetting('placeholder')]);
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['value'] = $element + [
'#type' => 'textfield',
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
'#size' => $this->getSetting('size'),
'#placeholder' => $this->getSetting('placeholder'),
'#maxlength' => $this->getFieldSetting('max_length'),
];
return $element;
}
{% endblock %}

View file

@ -0,0 +1,35 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\ImageEffect\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\ImageEffect;
{% endblock %}
{% block use_class %}
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ImageEffectBase;
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{class_name}}' image effect.
*
* @ImageEffect(
* id = "{{plugin_id}}",
* label = @Translation("{{label}}"),
* description = @Translation("{{description}}")
* )
*/
class {{ class_name }} extends ImageEffectBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function applyEffect(ImageInterface $image) {
// Implement Image Effect.
return imagefilter($image->getToolkit()->getResource());
}
{% endblock %}

View file

@ -0,0 +1,85 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\Mail\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\Mail;
{% endblock %}
{% block use_class %}
use Drupal\Core\Mail\Plugin\Mail\PhpMail;
{% if services is not empty %}
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{class_name}}' mail plugin.
*
* @Mail(
* id = "{{plugin_id}}",
* label = @Translation("{{label}}")
* )
*/
class {{class_name}} extends PhpMail {% if services is not empty %}implements ContainerFactoryPluginInterface {% endif %}
{% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Constructs a new {{class_name}} object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param string $plugin_definition
* The plugin implementation definition.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
{{ servicesAsParameters(services)|join(', \n\t') }}
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function format(array $message) {
}
/**
* {@inheritdoc}
*/
public function mail(array $message) {
}
{% endblock %}

View file

@ -0,0 +1,118 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module_name}}\Plugin\rest\resource\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module_name}}\Plugin\rest\resource;
{% endblock %}
{% block use_class %}
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\rest\ModifiedResourceResponse;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
{% endblock %}
{% block class_declaration %}
/**
* Provides a resource to get view modes by entity and bundle.
*
* @RestResource(
* id = "{{ plugin_id }}",
* label = @Translation("{{ plugin_label }}"),
* uri_paths = {
* "canonical" = "/{{ plugin_url }}"
* }
* )
*/
class {{ class_name }} extends ResourceBase {% endblock %}
{% block class_variables %}
/**
* A current user instance.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
{% endblock %}
{% block class_construct %}
/**
* Constructs a new {{ class_name }} object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param array $serializer_formats
* The available serialization formats.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
* A current user instance.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
array $serializer_formats,
LoggerInterface $logger,
AccountProxyInterface $current_user) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
$this->currentUser = $current_user;
}
{% endblock %}
{% block class_create %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->getParameter('serializer.formats'),
$container->get('logger.factory')->get('{{module_name}}'),
$container->get('current_user')
);
}
{% endblock %}
{% block class_methods %}
{% for state, state_settings in plugin_states %}
/**
* Responds to {{ state }} requests.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*
* @return \Drupal\rest\{{ state_settings.response_class }}
* The HTTP response object.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* Throws exception expected.
*/
public function {{ state|lower }}(EntityInterface $entity) {
// You must to implement the logic of your REST Resource here.
// Use current user after pass authentication to validate access.
if (!$this->currentUser->hasPermission('access content')) {
throw new AccessDeniedHttpException();
}
return new {{ state_settings.response_class }}({{ (state == 'DELETE') ? 'NULL' : '$entity' }}, {{ state_settings.http_code }});
}
{% endfor %}
{% endblock %}

View file

@ -0,0 +1,69 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\views\field\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\views\field;
{% endblock %}
{% block use_class %}
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Utility\Random;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
{% endblock %}
{% block class_declaration %}
/**
* A handler to provide a field that is completely custom by the administrator.
*
* @ingroup views_field_handlers
*
* @ViewsField("{{ class_machine_name }}")
*/
class {{ class_name }} extends FieldPluginBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function usesGroupBy() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function query() {
// Do nothing -- to override the parent query.
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['hide_alter_empty'] = ['default' => FALSE];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
// Return a random text, here you can include your custom logic.
// Include any namespace required to call the method required to generate
// the desired output.
$random = new Random();
return $random->name();
}
{% endblock %}

View file

@ -0,0 +1,33 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\migrate\process\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\migrate\process;
{% endblock %}
{% block use_class %}
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{class_name}}' migrate process plugin.
*
* @MigrateProcessPlugin(
* id = "{{plugin_id}}"
* )
*/
class {{class_name}} extends ProcessPluginBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Plugin logic goes here.
}
{% endblock %}

View file

@ -0,0 +1,55 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\migrate\source\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\migrate\source;
{% endblock %}
{% block use_class %}
use Drupal\migrate\Plugin\migrate\source\SqlBase;
{% endblock %}
{% block class_declaration %}
/**
* Provides a '{{class_name}}' migrate source.
*
* @MigrateSource(
* id = "{{plugin_id}}"
* )
*/
class {{class_name}} extends SqlBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('{{table}}', '{{alias}}')
->fields('{{alias}}'){% if group_by %}
->groupBy('{{alias}}.{{group_by}}')
{% endif %};
}
/**
* {@inheritdoc}
*/
public function fields() {
$fields = [
{% for field in fields %}
'{{field.id}}' => $this->t('{{field.description}}'),
{% endfor %}
];
return $fields;
}
/**
* {@inheritdoc}
*/
public function getIds() {
return [
];
}
{% endblock %}

View file

@ -0,0 +1,98 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Plugin\{{ plugin }}\{{class_name}}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Plugin\{{ plugin }};
{% endblock %}
{% block use_class %}
{% if pluginInterface is not empty %}
use {{ pluginInterface }};
{% endif %}
{% if services is not empty %}
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
{% endif %}
{% endblock %}
{% block class_declaration %}
{% if pluginAnnotation is not empty %}
/**
* @{{ plugin_annotation }}(
{% for property in pluginAnnotationProperties %}
{% if property.name == 'id' %}
* id = "{{- plugin_id }}",
{% elseif property.type == "\\Drupal\\Core\\Annotation\\Translation" %}
* {{ property.name }} = @Translation("{{property.description}}"),
{% else %}
* {{ property.name }} = "{{ property.type }}",
{% endif %}
{% endfor %}
* )
*/
{% endif %}
class {{class_name}} implements {% if plugin_interface is not empty %} {{ plugin_interface }} {% endif %}{% if services is not empty %}, ContainerFactoryPluginInterface {% endif %}{% endblock %}
{% block class_construct %}
{% if services is not empty %}
/**
* Constructs a new {{class_name}} object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param string $plugin_definition
* The plugin implementation definition.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
{{ servicesAsParameters(services)|join(', \n\t') }}
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
{{ serviceClassInitialization(services) }}
}
{% endif %}
{% endblock %}
{% block class_create %}
{% if services is not empty %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
{{ serviceClassInjection(services) }}
);
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function build() {
$build = [];
// Implement your logic
return $build;
}
{% for method in pluginInterfaceMethods %}
/**
* {@inheritdoc}
*/
{{ method.declaration }} {
// {{ method.description }}
}
{% endfor %}
{% endblock %}

View file

@ -0,0 +1,28 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\Routing\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\Routing;
{% endblock %}
{% block use_class %}
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class }}.
*
* Listens to the dynamic route events.
*/
class {{ class }} extends RouteSubscriberBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
}{% endblock %}

View file

@ -0,0 +1,56 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\Tests\{{ module }}\FunctionalJavascript\{{ class }}
{% endblock %}
{% block namespace_class %}
namespace Drupal\Tests\{{ module }}\FunctionalJavascript;
{% endblock %}
{% block use_class %}
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
{% endblock %}
{% block class_declaration %}
/**
* JavaScript tests.
*
* @ingroup {{ module }}
*
* @group {{ module }}
*/
class {{ class }} extends JavaScriptTestBase {% endblock %}
{% block class_methods %}
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['{{ module }}'];
/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
}
/**
* Tests that the home page loads with a 200 response.
*/
public function testFrontpage() {
$this->drupalGet(Url::fromRoute('<front>'));
$page = $this->getSession()->getPage();
$this->assertSession()->statusCodeEquals(200);
}
{% endblock %}

View file

@ -0,0 +1,54 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\Tests\{{ machine_name }}\Functional\LoadTest
{% endblock %}
{% block namespace_class %}
namespace Drupal\Tests\{{ machine_name }}\Functional;
{% endblock %}
{% block use_class %}
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
{% endblock %}
{% block class_declaration %}
/**
* Simple test to ensure that main page loads with module enabled.
*
* @group {{ machine_name }}
*/
class LoadTest extends BrowserTestBase {% endblock %}
{% block class_methods %}
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['{{ machine_name }}'];
/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
}
/**
* Tests that the home page loads with a 200 response.
*/
public function testLoad() {
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertSession()->statusCodeEquals(200);
}
{% endblock %}

View file

@ -0,0 +1,96 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\TwigExtension\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\TwigExtension;
{% endblock %}
{% block use_class %}
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class }}.
*/
class {{ class }} extends \Twig_Extension {% endblock %}
{% set properties = services[1:] %}
{% block class_properties %}
{% for service in properties %}
/**
* {{ service.class }} definition.
*
* @var {{ service.short }}
*/
protected ${{service.camel_case_name}};
{% endfor %}
{% endblock %}
{% block class_construct %}
{% if services|length > 1 %}
/**
* Constructs a new {{ class }} object.
*/
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
parent::__construct($renderer);
{{ serviceClassInitialization(properties) }}
}
{% endif %}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function getTokenParsers() {
return [];
}
/**
* {@inheritdoc}
*/
public function getNodeVisitors() {
return [];
}
/**
* {@inheritdoc}
*/
public function getFilters() {
return [];
}
/**
* {@inheritdoc}
*/
public function getTests() {
return [];
}
/**
* {@inheritdoc}
*/
public function getFunctions() {
return [];
}
/**
* {@inheritdoc}
*/
public function getOperators() {
return [];
}
/**
* {@inheritdoc}
*/
public function getName() {
return '{{ name }}';
}
{% endblock %}

View file

@ -0,0 +1,55 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ entity_class }}AccessControlHandler.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}};
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
{% endblock %}
{% block class_declaration %}
/**
* Access controller for the {{ label }} entity.
*
* @see \Drupal\{{module}}\Entity\{{ entity_class }}.
*/
class {{ entity_class }}AccessControlHandler extends EntityAccessControlHandler {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\{{ module }}\Entity\{{ entity_class }}Interface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished {{ label|lower }} entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published {{ label|lower }} entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit {{ label|lower }} entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete {{ label|lower }} entities');
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add {{ label|lower }} entities');
}
{% endblock %}

View file

@ -0,0 +1,54 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\CacheContext;
{% endblock %}
{% block use_class %}
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class }}.
*/
class {{ class }} implements CacheContextInterface {% endblock %}
{% block class_construct %}
/**
* Constructs a new {{ class }} object.
*/
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
{{ serviceClassInitialization(services) }}
}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function getLabel() {
drupal_set_message('Lable of cache context');
}
/**
* {@inheritdoc}
*/
public function getContext() {
// Actual logic of context variation will lie here.
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
{% endblock %}

View file

@ -0,0 +1,212 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\{{ entity_class }}HtmlRouteProvider.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }};
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
{% endblock %}
{% block class_declaration %}
/**
* Provides routes for {{ label }} entities.
*
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class {{ entity_class }}HtmlRouteProvider extends AdminHtmlRouteProvider {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type->id();
{% if revisionable %}
if ($history_route = $this->getHistoryRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.version_history", $history_route);
}
if ($revision_route = $this->getRevisionRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.revision", $revision_route);
}
if ($revert_route = $this->getRevisionRevertRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.revision_revert", $revert_route);
}
if ($delete_route = $this->getRevisionDeleteRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.revision_delete", $delete_route);
}
{% if is_translatable %}
if ($translation_route = $this->getRevisionTranslationRevertRoute($entity_type)) {
$collection->add("{$entity_type_id}.revision_revert_translation_confirm", $translation_route);
}
{% endif %}
{% endif %}
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
$collection->add("$entity_type_id.settings", $settings_form_route);
}
return $collection;
}
{% if revisionable %}
/**
* Gets the version history route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getHistoryRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('version-history')) {
$route = new Route($entity_type->getLinkTemplate('version-history'));
$route
->setDefaults([
'_title' => "{$entity_type->getLabel()} revisions",
'_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionOverview',
])
->setRequirement('_permission', 'access {{ label|lower }} revisions')
->setOption('_admin_route', TRUE);
return $route;
}
}
/**
* Gets the revision route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('revision')) {
$route = new Route($entity_type->getLinkTemplate('revision'));
$route
->setDefaults([
'_controller' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionShow',
'_title_callback' => '\Drupal\{{ module }}\Controller\{{ entity_class }}Controller::revisionPageTitle',
])
->setRequirement('_permission', 'access {{ label|lower }} revisions')
->setOption('_admin_route', TRUE);
return $route;
}
}
/**
* Gets the revision revert route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionRevertRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('revision_revert')) {
$route = new Route($entity_type->getLinkTemplate('revision_revert'));
$route
->setDefaults([
'_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertForm',
'_title' => 'Revert to earlier revision',
])
->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
->setOption('_admin_route', TRUE);
return $route;
}
}
/**
* Gets the revision delete route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionDeleteRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('revision_delete')) {
$route = new Route($entity_type->getLinkTemplate('revision_delete'));
$route
->setDefaults([
'_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionDeleteForm',
'_title' => 'Delete earlier revision',
])
->setRequirement('_permission', 'delete all {{ label|lower }} revisions')
->setOption('_admin_route', TRUE);
return $route;
}
}
{% if is_translatable %}
/**
* Gets the revision translation revert route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getRevisionTranslationRevertRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('translation_revert')) {
$route = new Route($entity_type->getLinkTemplate('translation_revert'));
$route
->setDefaults([
'_form' => '\Drupal\{{ module }}\Form\{{ entity_class }}RevisionRevertTranslationForm',
'_title' => 'Revert to earlier revision of a translation',
])
->setRequirement('_permission', 'revert all {{ label|lower }} revisions')
->setOption('_admin_route', TRUE);
return $route;
}
}
{% endif %}
{% endif %}
/**
* Gets the settings form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
if (!$entity_type->getBundleEntityType()) {
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
$route
->setDefaults([
'_form' => 'Drupal\{{ module }}\Form\{{ entity_class }}SettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
{% endblock %}

View file

@ -0,0 +1,40 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ entity_class }}ListBuilder.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}};
{% endblock %}
{% block use_class %}
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides a listing of {{ label }} entities.
*/
class {{ entity_class }}ListBuilder extends ConfigEntityListBuilder {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('{{ label }}');
$header['id'] = $this->t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}
{% endblock %}

View file

@ -0,0 +1,36 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\{{ entity_class }}HtmlRouteProvider.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }};
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
{% endblock %}
{% block class_declaration %}
/**
* Provides routes for {{ label }} entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class {{ entity_class }}HtmlRouteProvider extends AdminHtmlRouteProvider {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
// Provide your custom entity routes here.
return $collection;
}
{% endblock %}

View file

@ -0,0 +1,67 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\{{ entity_class }}Storage.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }};
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\{{ module }}\Entity\{{ entity_class }}Interface;
{% endblock %}
{% block class_declaration %}
/**
* Defines the storage handler class for {{ label }} entities.
*
* This extends the base storage class, adding required special handling for
* {{ label }} entities.
*
* @ingroup {{ module }}
*/
class {{ entity_class }}Storage extends SqlContentEntityStorage implements {{ entity_class }}StorageInterface {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function revisionIds({{ entity_class }}Interface $entity) {
return $this->database->query(
'SELECT vid FROM {{ '{'~entity_name~'_revision}' }} WHERE id=:id ORDER BY vid',
[':id' => $entity->id()]
)->fetchCol();
}
/**
* {@inheritdoc}
*/
public function userRevisionIds(AccountInterface $account) {
return $this->database->query(
'SELECT vid FROM {{ '{'~entity_name~'_field_revision}' }} WHERE uid = :uid ORDER BY vid',
[':uid' => $account->id()]
)->fetchCol();
}
/**
* {@inheritdoc}
*/
public function countDefaultLanguageRevisions({{ entity_class }}Interface $entity) {
return $this->database->query('SELECT COUNT(*) FROM {{ '{'~entity_name~'_field_revision}' }} WHERE id = :id AND default_langcode = 1', [':id' => $entity->id()])
->fetchField();
}
/**
* {@inheritdoc}
*/
public function clearRevisionsLanguage(LanguageInterface $language) {
return $this->database->update('{{ entity_name }}_revision')
->fields(['langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED])
->condition('langcode', $language->getId())
->execute();
}
{% endblock %}

View file

@ -0,0 +1,18 @@
{% extends "base/class.php.twig" %}
{% block namespace_class %}
namespace Drupal\{{module}};
{% endblock %}
{% block use_class %}
use Drupal\content_translation\ContentTranslationHandler;
{% endblock %}
{% block class_declaration %}
/**
* Defines the translation handler for {{ entity_name }}.
*/
class {{ entity_class }}TranslationHandler extends ContentTranslationHandler {% endblock %}
{% block class_methods %}
// Override here the needed methods from ContentTranslationHandler.
{% endblock %}

View file

@ -0,0 +1,56 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}}\EventSubscriber;
{% endblock %}
{% block use_class %}
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
{% endblock %}
{% block class_declaration %}
/**
* Class {{ class }}.
*/
class {{ class }} implements EventSubscriberInterface {% endblock %}
{% block class_construct %}
/**
* Constructs a new {{ class }} object.
*/
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
{{ serviceClassInitialization(services) }}
}
{% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
static function getSubscribedEvents() {
{% for event_name, callback in events %}
$events['{{ event_name }}'] = ['{{ callback }}'];
{% endfor %}
return $events;
}
{% for event_name, callback in events %}
/**
* This method is called whenever the {{ event_name }} event is
* dispatched.
*
* @param GetResponseEvent $event
*/
public function {{ callback }}(Event $event) {
drupal_set_message('Event {{ event_name }} thrown by Subscriber in module {{ module }}.', 'status', TRUE);
}
{% endfor %}
{% endblock %}

View file

@ -0,0 +1,70 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\{{ entity_class }}StorageInterface.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }};
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\ContentEntityStorageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\{{ module }}\Entity\{{ entity_class }}Interface;
{% endblock %}
{% block class_declaration %}
/**
* Defines the storage handler class for {{ label }} entities.
*
* This extends the base storage class, adding required special handling for
* {{ label }} entities.
*
* @ingroup {{ module }}
*/
interface {{ entity_class }}StorageInterface extends ContentEntityStorageInterface {% endblock %}
{% block class_methods %}
/**
* Gets a list of {{ label }} revision IDs for a specific {{ label }}.
*
* @param \Drupal\{{ module }}\Entity\{{ entity_class }}Interface $entity
* The {{ label }} entity.
*
* @return int[]
* {{ label }} revision IDs (in ascending order).
*/
public function revisionIds({{ entity_class }}Interface $entity);
/**
* Gets a list of revision IDs having a given user as {{ label }} author.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The user entity.
*
* @return int[]
* {{ label }} revision IDs (in ascending order).
*/
public function userRevisionIds(AccountInterface $account);
/**
* Counts the number of revisions in the default language.
*
* @param \Drupal\{{ module }}\Entity\{{ entity_class }}Interface $entity
* The {{ label }} entity.
*
* @return int
* The number of revisions in the default language.
*/
public function countDefaultLanguageRevisions({{ entity_class }}Interface $entity);
/**
* Unsets the language for all {{ label }} with the given language.
*
* @param \Drupal\Core\Language\LanguageInterface $language
* The language object.
*/
public function clearRevisionsLanguage(LanguageInterface $language);
{% endblock %}

View file

@ -0,0 +1,48 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ entity_class }}ListBuilder.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}};
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
{% endblock %}
{% block class_declaration %}
/**
* Defines a class to build a listing of {{ label }} entities.
*
* @ingroup {{ module }}
*/
class {{ entity_class }}ListBuilder extends EntityListBuilder {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('{{ label }} ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\{{module}}\Entity\{{ entity_class }} */
$row['id'] = $entity->id();
$row['name'] = Link::createFromRoute(
$entity->label(),
'entity.{{ entity_name }}.edit_form',
['{{ entity_name }}' => $entity->id()]
);
return $row + parent::buildRow($entity);
}
{% endblock %}

View file

@ -0,0 +1,23 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\{{ class_name }}Base.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin;
{% endblock %}
{% block use_class %}
use Drupal\Component\Plugin\PluginBase;
{% endblock %}
{% block class_declaration %}
/**
* Base class for {{ label }} plugins.
*/
abstract class {{ class_name }}Base extends PluginBase implements {{ class_name }}Interface {% endblock %}
{% block class_methods %}
// Add common methods and abstract methods for your plugin type here.
{% endblock %}

View file

@ -0,0 +1,23 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\{{ class_name }}Interface.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin;
{% endblock %}
{% block use_class %}
use Drupal\Component\Plugin\PluginInspectionInterface;
{% endblock %}
{% block class_declaration %}
/**
* Defines an interface for {{ label }} plugins.
*/
interface {{ class_name }}Interface extends PluginInspectionInterface {% endblock %}
{% block class_methods %}
// Add get/set methods for your plugin type here.
{% endblock %}

View file

@ -0,0 +1,41 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\Plugin\{{ class_name }}Manager.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Plugin;
{% endblock %}
{% block use_class %}
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
{% endblock %}
{% block class_declaration %}
/**
* Provides the {{ label }} plugin manager.
*/
class {{ class_name }}Manager extends DefaultPluginManager {% endblock %}
{% block class_methods %}
/**
* Constructs a new {{ class_name }}Manager object.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook with.
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/{{ class_name }}', $namespaces, $module_handler, 'Drupal\{{ module }}\Plugin\{{ class_name }}Interface', 'Drupal\{{ module }}\Annotation\{{ class_name }}');
$this->alterInfo('{{ module }}_{{ machine_name }}_info');
$this->setCacheBackend($cache_backend, '{{ module }}_{{ machine_name }}_plugins');
}
{% endblock %}

View file

@ -0,0 +1,15 @@
{% extends "base/interface.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ interface }}.
{% endblock %}
{% block namespace_interface %}
namespace Drupal\{{module}};
{% endblock %}
{% block interface_declaration %}
/**
* Interface {{ interface }}.
*/
interface {{ interface }} {% endblock %}

View file

@ -0,0 +1,22 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{module}}\{{ class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{module}};{% endblock %}
{% block class_declaration %}
/**
* Class {{ class }}.
*/
class {{ class }}{% if(interface is defined and interface) %} implements {{ interface }}{% endif %} {% endblock %}
{% block class_construct %}
/**
* Constructs a new {{ class }} object.
*/
public function __construct({{ servicesAsParameters(services)|join(', ') }}) {
{{ serviceClassInitialization(services) }}
}
{% endblock %}

View file

@ -0,0 +1,22 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\{{ class_name }}ManagerInterface.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }};
{% endblock %}
{% block use_class %}
use Drupal\Component\Plugin\PluginManagerInterface;
{% endblock %}
{% block class_declaration %}
/**
* Defines an interface for {{ plugin_name }} managers.
*/
interface {{ class_name }}ManagerInterface extends PluginManagerInterface {% endblock %}
{% block class_methods %}
// Add getters and other public methods for {{ plugin_name }} managers.
{% endblock %}

View file

@ -0,0 +1,76 @@
{% extends "base/class.php.twig" %}
{% block file_path %}
\Drupal\{{ module }}\{{ class_name }}Manager.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }};
{% endblock %}
{% block use_class %}
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
{% endblock %}
{% block class_declaration %}
/**
* Provides the default {{ plugin_name }} manager.
*/
class {{ class_name }}Manager extends DefaultPluginManager implements {{ class_name }}ManagerInterface {% endblock %}
{% block class_methods %}
/**
* Provides default values for all {{ plugin_name }} plugins.
*
* @var array
*/
protected $defaults = [
// Add required and optional plugin properties.
'id' => '',
'label' => '',
];
/**
* Constructs a new {{ class_name }}Manager object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
*/
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
// Add more services as required.
$this->moduleHandler = $module_handler;
$this->setCacheBackend($cache_backend, '{{ plugin_name }}', ['{{ plugin_name }}']);
}
/**
* {@inheritdoc}
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('{{ plugin_file_name }}', $this->moduleHandler->getModuleDirectories());
$this->discovery->addTranslatableProperty('label', 'label_context');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
}
return $this->discovery;
}
/**
* {@inheritdoc}
*/
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
// You can add validation of the plugin definition here.
if (empty($definition['id'])) {
throw new PluginException(sprintf('Example plugin property (%s) definition "is" is required.', $plugin_id));
}
}
// Add other methods here as defined in the {{ class_name }}ManagerInterface.
{% endblock %}

View file

@ -0,0 +1,11 @@
id: {{ plugin_id }}
label: '{{ label }}'
status: true
langcode: en
type: {{ type }}
plugin: {{ plugin_id }}
dependencies:
module:
- {{ type }}
- {{ module }}

Some files were not shown because too many files have changed in this diff Show more