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,5 @@
services:
access_check.{{ machine_name }}.{{ applies_to|trim('_') }}:
class: Drupal\{{ machine_name }}\Access\{{ class }}
tags:
- { name: access_check, applies_to: {{ applies_to }} }

View file

@ -0,0 +1,33 @@
<?php
namespace Drupal\{{ machine_name }}\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Symfony\Component\Routing\Route;
/**
* Checks if passed parameter matches the route configuration.
*
* @DCG
* To make use of this access checker add '{{ applies_to }}: Some value' entry to route
* definition under requirements section.
*/
class {{ class }} implements AccessInterface {
/**
* Access callback.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \ExampleInterface $parameter
* The parameter to test.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, \ExampleInterface $parameter) {
return AccessResult::allowedIf($parameter->getSomeValue() == $route->getRequirement('{{ applies_to }}'));
}
}

View file

@ -0,0 +1,5 @@
services:
{{ machine_name }}.breadcrumb:
class: Drupal\{{ machine_name }}\{{ class }}
tags:
- { name: breadcrumb_builder, priority: 1000 }

View file

@ -0,0 +1,46 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Breadcrumb\Breadcrumb;
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\node\NodeInterface;
/**
* Provides a breadcrumb builder for articles.
*/
class {{ class }} implements BreadcrumbBuilderInterface {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
$node = $route_match->getParameter('node');
return $node instanceof NodeInterface && $node->getType() == 'article';
}
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
$links[] = Link::createFromRoute($this->t('Home'), '<front>');
// Articles page is a view.
$links[] = Link::createFromRoute($this->t('Articles'), 'view.articles.page_1');
$node = $route_match->getParameter('node');
$links[] = Link::createFromRoute($node->label(), '<none>');
$breadcrumb->setLinks($links);
return $breadcrumb;
}
}

View file

@ -0,0 +1,10 @@
services:
cache_context.{{ context_id }}:
class: Drupal\{{ machine_name }}\Cache\Context\{{ class }}
{% if base_class == 'RequestStackCacheContextBase' %}
arguments: ['@request_stack']
{% elseif base_class == 'UserCacheContextBase' %}
arguments: ['@current_user']
{% endif %}
tags:
- { name: cache.context}

View file

@ -0,0 +1,45 @@
<?php
namespace Drupal\{{ machine_name }}\Cache\Context;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\{{ interface }};
{% if base_class %}
use Drupal\Core\Cache\Context\{{ base_class }};
{% endif %}
/**
* Defines the ExampleCacheContext service.
*
* Cache context ID: '{{ context_id }}'.
*
* @DCG
* Check out the core/lib/Drupal/Core/Cache/Context directory for examples of
* cache contexts provided by Drupal core.
*/
class {{ class }} {% if base_class %}extends {{ base_class }} {% endif %}implements {{ interface }} {
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('{{ context_label }}');
}
/**
* {@inheritdoc}
*/
public function getContext({% if calculated %}$parameter = NULL{% endif %}) {
// @DCG: Define the cache context here.
$context = 'some_string_value';
return $context;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata({% if calculated %}$parameter = NULL{% endif %}) {
return new CacheableMetadata();
}
}

View file

@ -0,0 +1,7 @@
{% import 'lib/di.twig' as di %}
services:
{{ service_name }}:
class: Drupal\{{ machine_name }}\{{ class }}
{% if services %}
arguments: [{{ di.arguments(services) }}]
{% endif %}

View file

@ -0,0 +1,34 @@
{% import 'lib/di.twig' as di %}
<?php
namespace Drupal\{{ machine_name }};
{% if services %}
{{ di.use(services) }}
{% endif %}
/**
* {{ class }} service.
*/
class {{ class }} {
{% if services %}
{{ di.properties(services) }}
/**
* Constructs {{ class|article|lower }} object.
*
{{ di.annotation(services) }}
*/
public function __construct({{ di.signature(services) }}) {
{{ di.assignment(services) }}
}
{% endif %}
/**
* Method description.
*/
public function doSomething() {
// @DCG place your code here.
}
}

View file

@ -0,0 +1,6 @@
services:
{{ machine_name }}.event_subscriber:
class: Drupal\{{ machine_name }}\EventSubscriber\{{ class }}
arguments: ['@messenger']
tags:
- { name: event_subscriber }

View file

@ -0,0 +1,63 @@
<?php
namespace Drupal\{{ machine_name }}\EventSubscriber;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
/**
* {{ name }} event subscriber.
*/
class {{ class }} implements EventSubscriberInterface {
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructs event subscriber.
*
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(MessengerInterface $messenger) {
$this->messenger = $messenger;
}
/**
* Kernel request event handler.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
* Response event.
*/
public function onKernelRequest(GetResponseEvent $event) {
$this->messenger->addStatus(__FUNCTION__);
}
/**
* Kernel response event handler.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* Response event.
*/
public function onKernelResponse(FilterResponseEvent $event) {
$this->messenger->addStatus(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
KernelEvents::REQUEST => ['onKernelRequest'],
KernelEvents::RESPONSE => ['onKernelResponse'],
];
}
}

View file

@ -0,0 +1,6 @@
services:
logger.{{ machine_name }}:
class: Drupal\{{ machine_name }}\Logger\{{ class }}
arguments: ['@config.factory', '@logger.log_message_parser', '@date.formatter']
tags:
- { name: logger }

View file

@ -0,0 +1,83 @@
<?php
namespace Drupal\{{ machine_name }}\Logger;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\Core\Logger\RfcLoggerTrait;
use Drupal\Core\Logger\RfcLogLevel;
use Psr\Log\LoggerInterface;
/**
* Redirects messages to a file.
*/
class {{ class }} implements LoggerInterface {
use RfcLoggerTrait;
/**
* A configuration object containing system.file settings.
*
* @var \Drupal\Core\Config\Config
*/
protected $config;
/**
* The message's placeholders parser.
*
* @var \Drupal\Core\Logger\LogMessageParserInterface
*/
protected $parser;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* Constructs {{ class|article }} object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory object.
* @param \Drupal\Core\Logger\LogMessageParserInterface $parser
* The parser to use when extracting message variables.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
*/
public function __construct(ConfigFactoryInterface $config_factory, LogMessageParserInterface $parser, DateFormatterInterface $date_formatter) {
$this->config = $config_factory->get('system.file');
$this->parser = $parser;
$this->dateFormatter = $date_formatter;
}
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []) {
// Populate the message placeholders and then replace them in the message.
$message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
$message = empty($message_placeholders) ? $message : strtr($message, $message_placeholders);
$entry = [
'message' => strip_tags($message),
'date' => $this->dateFormatter->format($context['timestamp']),
'type' => $context['channel'],
'ip' => $context['ip'],
'request_uri' => $context['request_uri'],
'referer' => $context['referer'],
'severity' => (string) RfcLogLevel::getLevels()[$level],
'uid' => $context['uid'],
];
file_put_contents(
$this->config->get('path.temporary') . '/drupal.log',
print_r($entry, TRUE),
FILE_APPEND
);
}
}

View file

@ -0,0 +1,5 @@
services:
{{ machine_name }}.middleware:
class: Drupal\{{ machine_name }}\{{ class }}
tags:
- { name: http_middleware, priority: 1000 }

View file

@ -0,0 +1,46 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* {{ class }} middleware.
*/
class {{ class }} implements HttpKernelInterface {
use StringTranslationTrait;
/**
* The kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* Constructs the {{ class }} object.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The decorated kernel.
*/
public function __construct(HttpKernelInterface $http_kernel) {
$this->httpKernel = $http_kernel;
}
/**
* {@inheritdoc}
*/
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
if ($request->getClientIp() == '127.0.0.10') {
return new Response($this->t('Bye!'), 403);
}
return $this->httpKernel->handle($request, $type, $catch);
}
}

View file

@ -0,0 +1,6 @@
services:
{{ machine_name }}.foo_param_converter:
class: Drupal\{{ machine_name }}\{{ class }}
arguments: ['@database']
tags:
- { name: paramconverter }

View file

@ -0,0 +1,65 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Core\Database\Connection;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Symfony\Component\Routing\Route;
/**
* Converts parameters for upcasting database record IDs to full std objects.
*
* @DCG
* To use this converter specify parameter type in a relevant route as follows:
* @code
* {{ machine_name }}.{{ parameter_type }}_parameter_converter:
* path: example/{record}
* defaults:
* _controller: '\Drupal\{{ machine_name }}\Controller\{{ controller_class }}::build'
* requirements:
* _access: 'TRUE'
* options:
* parameters:
* record:
* type: {{ parameter_type }}
* @endcode
*
* Note that for entities you can make use of existing parameter converter
* provided by Drupal core.
* @see \Drupal\Core\ParamConverter\EntityConverter
*/
class {{ class }} implements ParamConverterInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new {{ class }}.
*
* @param \Drupal\Core\Database\Connection $connection
* The default database connection.
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
// Return NULL if record not found to trigger 404 HTTP error.
return $this->connection->query('SELECT * FROM {table_name} WHERE id = ?', [$value])->fetch() ?: NULL;
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
return !empty($definition['type']) && $definition['type'] == '{{ parameter_type }}';
}
}

View file

@ -0,0 +1,6 @@
services:
path_processor.{{ machine_name }}:
class: Drupal\{{ machine_name }}\PathProcessor\{{ class }}
tags:
- { name: path_processor_inbound, priority: 1000 }
- { name: path_processor_outbound, priority: 1000 }

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\{{ machine_name }}\PathProcessor;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\PathProcessor\OutboundPathProcessorInterface;
use Drupal\Core\Render\BubbleableMetadata;
use Symfony\Component\HttpFoundation\Request;
/**
* Path processor to replace 'node' with 'content' in URLs.
*/
class {{ class }} implements InboundPathProcessorInterface, OutboundPathProcessorInterface {
/**
* {@inheritdoc}
*/
public function processInbound($path, Request $request) {
return preg_replace('#^/content/#', '/node/', $path);
}
/**
* {@inheritdoc}
*/
public function processOutbound($path, &$options = [], Request $request = NULL, BubbleableMetadata $bubbleable_metadata = NULL) {
return preg_replace('#^/node/#', '/content/', $path);
}
}

View file

@ -0,0 +1,5 @@
services:
{{ machine_name }}.page_cache_request_policy.example:
class: Drupal\{{ machine_name }}\PageCache\{{ class }}
tags:
- { name: page_cache_request_policy }

View file

@ -0,0 +1,24 @@
<?php
namespace Drupal\{{ machine_name }}\PageCache;
use Drupal\Core\PageCache\RequestPolicyInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* A policy allowing to bypass cache for requests with 'no-cache' parameter.
*
* Example: https://example.com/node?no-cache.
*/
class {{ class }} implements RequestPolicyInterface {
/**
* {@inheritdoc}
*/
public function check(Request $request) {
if (!is_null($request->get('no-cache'))) {
return self::DENY;
}
}
}

View file

@ -0,0 +1,7 @@
services:
{{ machine_name }}.page_cache_response_policy.example:
class: Drupal\{{ machine_name }}\PageCache\{{ class }}
public: false
tags:
- { name: page_cache_response_policy }
- { name: dynamic_page_cache_response_policy }

View file

@ -0,0 +1,23 @@
<?php
namespace Drupal\{{ machine_name }}\PageCache;
use Drupal\Core\PageCache\ResponsePolicyInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* A policy disallowing caching requests with certain cookies.
*/
class {{ class }} implements ResponsePolicyInterface {
/**
* {@inheritdoc}
*/
public function check(Response $response, Request $request) {
if ($request->cookies->get('foo')) {
return self::DENY;
}
}
}

View file

@ -0,0 +1,5 @@
services:
{{ machine_name }}.route_subscriber:
class: Drupal\{{ machine_name }}\EventSubscriber\{{ class }}
tags:
- { name: event_subscriber }

View file

@ -0,0 +1,39 @@
<?php
namespace Drupal\{{ machine_name }}\EventSubscriber;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\RouteCollection;
/**
* {{ name }} route subscriber.
*/
class {{ class }} extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
foreach ($collection->all() as $route) {
// Hide taxonomy pages from unprivileged users.
if (strpos($route->getPath(), '/taxonomy/term') === 0) {
$route->setRequirement('_role', 'administrator');
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
// Use a lower priority than \Drupal\views\EventSubscriber\RouteSubscriber
// to ensure the requirement will be added to its routes.
$events[RoutingEvents::ALTER] = ['onAlterRoutes', -300];
return $events;
}
}

View file

@ -0,0 +1,6 @@
services:
theme.negotiator.{{ machine_name }}.example:
class: Drupal\{{ machine_name }}\Theme\{{ class }}
arguments: ['@request_stack']
tags:
- { name: theme_negotiator, priority: 1000 }

View file

@ -0,0 +1,49 @@
<?php
namespace Drupal\{{ machine_name }}\Theme;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Defines a theme negotiator that deals with the active theme on example page.
*/
class {{ class }} implements ThemeNegotiatorInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Constructs a new {{ class }}.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack used to retrieve the current request.
*/
public function __construct(RequestStack $request_stack) {
$this->requestStack = $request_stack;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
return $route_match->getRouteName() == '{{ machine_name }}.example';
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match) {
// Allow users to pass theme name through 'theme' query parameter.
$theme = $this->requestStack->getCurrentRequest()->query->get('theme');
if (is_string($theme)) {
return $theme;
}
}
}

View file

@ -0,0 +1,8 @@
services:
{{ machine_name }}.twig_extension:
class: Drupal\{{ machine_name }}\{{ class }}
{% if di %}
arguments: ['@example']
{% endif %}
tags:
- { name: twig.extension }

View file

@ -0,0 +1,66 @@
<?php
namespace Drupal\{{ machine_name }};
{% if di %}
use Drupal\example\ExampleInterface;
{% endif %}
/**
* Twig extension.
*/
class {{ class }} extends \Twig_Extension {
{% if di %}
/**
* The example service.
*
* @var \Drupal\example\ExampleInterface
*/
protected $example;
/**
* Constructs a new {{ class }} instance.
*
* @param \Drupal\example\ExampleInterface $example
* The example service.
*/
public function __construct(ExampleInterface $example) {
$this->example = $example;
}
{% endif %}
/**
* {@inheritdoc}
*/
public function getFunctions() {
return [
new \Twig_SimpleFunction('foo', function ($argument = NULL) {
return 'Foo: ' . $argument;
}),
];
}
/**
* {@inheritdoc}
*/
public function getFilters() {
return [
new \Twig_SimpleFilter('bar', function ($text) {
return str_replace('bar', 'BAR', $text);
}),
];
}
/**
* {@inheritdoc}
*/
public function getTests() {
return [
new \Twig_SimpleTest('color', function ($text) {
return preg_match('/^#(?:[0-9a-f]{3}){1,2}$/i', $text);
}),
];
}
}

View file

@ -0,0 +1,6 @@
services:
{{ machine_name }}.uninstall_validator:
class: Drupal\{{ machine_name }}\{{ class }}
tags:
- { name: module_install.uninstall_validator }
arguments: ['@plugin.manager.block', '@entity_type.manager', '@string_translation']

View file

@ -0,0 +1,70 @@
<?php
namespace Drupal\{{ machine_name }};
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
/**
* Prevents uninstalling of modules providing used block plugins.
*/
class {{ class }} implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* The block plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $blockManager;
/**
* The block entity storage.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
*/
protected $blockStorage;
/**
* Constructs a new FilterUninstallValidator.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $block_manager
* The filter plugin manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(PluginManagerInterface $block_manager, EntityTypeManagerInterface $entity_manager, TranslationInterface $string_translation) {
$this->blockManager = $block_manager;
$this->blockStorage = $entity_manager->getStorage('block');
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public function validate($module) {
$reasons = [];
foreach ($this->blockStorage->loadMultiple() as $block) {
/** @var \Drupal\block\BlockInterface $block */
$definition = $block->getPlugin()
->getPluginDefinition();
if ($definition['provider'] == $module) {
$message_arguments = [
':url' => $block->toUrl('edit-form')->toString(),
'@block_id' => $block->id(),
];
$reasons[] = $this->t('Provides a block plugin that is in use in the following block: <a href=":url">@block_id</a>', $message_arguments);
}
}
return $reasons;
}
}