Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -1,75 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\block\EventSubscriber\BlockContextSubscriberBase.
*/
namespace Drupal\block\EventSubscriber;
use Drupal\block\Event\BlockContextEvent;
use Drupal\block\Event\BlockEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Provides a base class for block context subscribers.
*/
abstract class BlockContextSubscriberBase implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[BlockEvents::ACTIVE_CONTEXT][] = 'onBlockActiveContext';
$events[BlockEvents::ADMINISTRATIVE_CONTEXT][] = 'onBlockAdministrativeContext';
return $events;
}
/**
* Determines the available run-time contexts.
*
* For blocks to render correctly, all of the contexts that they require
* must be populated with values. So this method must set a value for each
* context that it adds. For example:
* @code
* // Determine a specific node to pass as context to blocks.
* $node = ...
*
* // Set that specific node as the value of the 'node' context.
* $context = new Context(new ContextDefinition('entity:node'));
* $context->setContextValue($node);
* $event->setContext('node.node', $context);
* @endcode
*
* @param \Drupal\block\Event\BlockContextEvent $event
* The Event to which to register available contexts.
*/
abstract public function onBlockActiveContext(BlockContextEvent $event);
/**
* Determines the available configuration-time contexts.
*
* When a block is being configured, the configuration UI must know which
* named contexts are potentially available, but does not care about the
* value, since the value can be different for each request, and might not
* be available at all during the configuration UI's request.
*
* For example:
* @code
* // During configuration, there is no specific node to pass as context.
* // However, inform the system that a context named 'node.node' is
* // available, and provide its definition, so that blocks can be
* // configured to use it. When the block is rendered, the value of this
* // context will be supplied by onBlockActiveContext().
* $context = new Context(new ContextDefinition('entity:node'));
* $event->setContext('node.node', $context);
* @endcode
*
* @param \Drupal\block\Event\BlockContextEvent $event
* The Event to which to register available contexts.
*
* @see static::onBlockActiveContext()
*/
abstract public function onBlockAdministrativeContext(BlockContextEvent $event);
}

View file

@ -1,63 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\block\EventSubscriber\CurrentLanguageContext.
*/
namespace Drupal\block\EventSubscriber;
use Drupal\block\Event\BlockContextEvent;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Sets the current language as a context.
*/
class CurrentLanguageContext extends BlockContextSubscriberBase {
use StringTranslationTrait;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs a new CurrentLanguageContext.
*
* @param \Drupal\Core\Language\LanguageManagerInterface
* The language manager.
*/
public function __construct(LanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public function onBlockActiveContext(BlockContextEvent $event) {
// Add a context for each language type.
$language_types = $this->languageManager->getLanguageTypes();
$info = $this->languageManager->getDefinedLanguageTypesInfo();
foreach ($language_types as $type_key) {
if (isset($info[$type_key]['name'])) {
$context = new Context(new ContextDefinition('language', $info[$type_key]['name']));
$context->setContextValue($this->languageManager->getCurrentLanguage($type_key));
$event->setContext('language.' . $type_key, $context);
}
}
}
/**
* {@inheritdoc}
*/
public function onBlockAdministrativeContext(BlockContextEvent $event) {
$this->onBlockActiveContext($event);
}
}

View file

@ -1,69 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\block\EventSubscriber\CurrentUserContext.
*/
namespace Drupal\block\EventSubscriber;
use Drupal\block\Event\BlockContextEvent;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Sets the current user as a context.
*/
class CurrentUserContext extends BlockContextSubscriberBase {
use StringTranslationTrait;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* The user storage.
*
* @var \Drupal\user\UserStorageInterface
*/
protected $userStorage;
/**
* Constructs a new CurrentUserContext.
*
* @param \Drupal\Core\Session\AccountInterface $account
* The current user.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(AccountInterface $account, EntityManagerInterface $entity_manager) {
$this->account = $account;
$this->userStorage = $entity_manager->getStorage('user');
}
/**
* {@inheritdoc}
*/
public function onBlockActiveContext(BlockContextEvent $event) {
$current_user = $this->userStorage->load($this->account->id());
$context = new Context(new ContextDefinition('entity:user', $this->t('Current user')));
$context->setContextValue($current_user);
$event->setContext('user.current_user', $context);
}
/**
* {@inheritdoc}
*/
public function onBlockAdministrativeContext(BlockContextEvent $event) {
$this->onBlockActiveContext($event);
}
}

View file

@ -1,65 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\block\EventSubscriber\NodeRouteContext.
*/
namespace Drupal\block\EventSubscriber;
use Drupal\block\Event\BlockContextEvent;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\node\Entity\Node;
/**
* Sets the current node as a context on node routes.
*/
class NodeRouteContext extends BlockContextSubscriberBase {
/**
* The route match object.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructs a new NodeRouteContext.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object.
*/
public function __construct(RouteMatchInterface $route_match) {
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public function onBlockActiveContext(BlockContextEvent $event) {
if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) {
$context = new Context(new ContextDefinition($route_contexts['node']['type']));
if ($node = $this->routeMatch->getParameter('node')) {
$context->setContextValue($node);
}
$event->setContext('node.node', $context);
}
elseif ($this->routeMatch->getRouteName() == 'node.add') {
$node_type = $this->routeMatch->getParameter('node_type');
$context = new Context(new ContextDefinition('entity:node'));
$context->setContextValue(Node::create(array('type' => $node_type->id())));
$event->setContext('node.node', $context);
}
}
/**
* {@inheritdoc}
*/
public function onBlockAdministrativeContext(BlockContextEvent $event) {
$context = new Context(new ContextDefinition('entity:node'));
$event->setContext('node.node', $context);
}
}