Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -42,7 +42,7 @@ class Context extends ComponentContext implements ContextInterface {
*
* @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $context_definition
* The context definition.
* @param mixed $context_value|NULL
* @param mixed $context_value|null
* The context value object.
*/
public function __construct(ContextDefinitionInterface $context_definition, $context_value = NULL) {

View file

@ -85,7 +85,7 @@ class ContextDefinition implements ContextDefinitionInterface {
*
* @param string $data_type
* The required data type.
* @param mixed string|null $label
* @param string|null $label
* The label of this context definition for the UI.
* @param bool $required
* Whether the context definition is required.
@ -245,7 +245,7 @@ class ContextDefinition implements ContextDefinitionInterface {
->setDescription($this->getDescription())
->setRequired($this->isRequired());
$constraints = $definition->getConstraints() + $this->getConstraints();
$definition->setConstraints($constraints);
$definition->setConstraints($constraints);
return $definition;
}

View file

@ -3,6 +3,7 @@
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\UseCacheBackendTrait;
use Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait;
@ -20,7 +21,7 @@ use Drupal\Core\Plugin\Factory\ContainerFactory;
*
* @ingroup plugin_api
*/
class DefaultPluginManager extends PluginManagerBase implements PluginManagerInterface, CachedDiscoveryInterface {
class DefaultPluginManager extends PluginManagerBase implements PluginManagerInterface, CachedDiscoveryInterface, CacheableDependencyInterface {
use DiscoveryCachedTrait;
use UseCacheBackendTrait;
@ -238,6 +239,11 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
* method.
*/
public function processDefinition(&$definition, $plugin_id) {
// Only arrays can be operated on.
if (!is_array($definition)) {
return;
}
if (!empty($this->defaults) && is_array($this->defaults)) {
$definition = NestedArray::mergeDeep($this->defaults, $definition);
}
@ -313,4 +319,25 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt
return $this->moduleHandler->moduleExists($provider);
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [];
}
/**
* {@inheritdoc}
*/
public function getCacheTags() {
return $this->cacheTags;
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return CACHE::PERMANENT;
}
}

View file

@ -3,8 +3,8 @@
namespace Drupal\Core\Plugin\Discovery;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
use Drupal\Component\Discovery\YamlDiscovery as ComponentYamlDiscovery;
use Drupal\Component\Plugin\Discovery\DiscoveryTrait;
use Drupal\Core\Discovery\YamlDiscovery as CoreYamlDiscovery;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
@ -25,7 +25,7 @@ class YamlDiscovery implements DiscoveryInterface {
/**
* YAML file discovery and parsing handler.
*
* @var \Drupal\Component\Discovery\YamlDiscovery
* @var \Drupal\Core\Discovery\YamlDiscovery
*/
protected $discovery;
@ -48,7 +48,7 @@ class YamlDiscovery implements DiscoveryInterface {
* An array of directories to scan.
*/
function __construct($name, array $directories) {
$this->discovery = new ComponentYamlDiscovery($name, $directories);
$this->discovery = new CoreYamlDiscovery($name, $directories);
}
/**

View file

@ -0,0 +1,38 @@
<?php
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\PluginAwareInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a base class for plugin forms.
*
* Classes extending this can be in any namespace, but are commonly placed in
* the 'PluginForm' namespace, such as \Drupal\module_name\PluginForm\ClassName.
*/
abstract class PluginFormBase implements PluginFormInterface, PluginAwareInterface {
/**
* The plugin this form is for.
*
* @var \Drupal\Component\Plugin\PluginInspectionInterface
*/
protected $plugin;
/**
* {@inheritdoc}
*/
public function setPlugin(PluginInspectionInterface $plugin) {
$this->plugin = $plugin;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Validation is optional.
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Plugin\PluginAwareInterface;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
/**
* Provides form discovery capabilities for plugins.
*/
class PluginFormFactory implements PluginFormFactoryInterface {
/**
* The class resolver.
*
* @var \Drupal\Core\DependencyInjection\ClassResolverInterface
*/
protected $classResolver;
/**
* PluginFormFactory constructor.
*
* @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
* The class resolver.
*/
public function __construct(ClassResolverInterface $class_resolver) {
$this->classResolver = $class_resolver;
}
/**
* {@inheritdoc}
*/
public function createInstance(PluginWithFormsInterface $plugin, $operation, $fallback_operation = NULL) {
if (!$plugin->hasFormClass($operation)) {
// Use the default form class if no form is specified for this operation.
if ($fallback_operation && $plugin->hasFormClass($fallback_operation)) {
$operation = $fallback_operation;
}
else {
throw new InvalidPluginDefinitionException($plugin->getPluginId(), sprintf('The "%s" plugin did not specify a "%s" form class', $plugin->getPluginId(), $operation));
}
}
$form_class = $plugin->getFormClass($operation);
// If the form specified is the plugin itself, use it directly.
if (ltrim(get_class($plugin), '\\') === ltrim($form_class, '\\')) {
$form_object = $plugin;
}
else {
$form_object = $this->classResolver->getInstanceFromDefinition($form_class);
}
// Ensure the resulting object is a plugin form.
if (!$form_object instanceof PluginFormInterface) {
throw new InvalidPluginDefinitionException($plugin->getPluginId(), sprintf('The "%s" plugin did not specify a valid "%s" form class, must implement \Drupal\Core\Plugin\PluginFormInterface', $plugin->getPluginId(), $operation));
}
if ($form_object instanceof PluginAwareInterface) {
$form_object->setPlugin($plugin);
}
return $form_object;
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Drupal\Core\Plugin;
/**
* Provides an interface for retrieving form objects for plugins.
*
* This allows a plugin to define multiple forms, in addition to the plugin
* itself providing a form. All forms, decoupled or self-contained, must
* implement \Drupal\Core\Plugin\PluginFormInterface. Decoupled forms can
* implement \Drupal\Component\Plugin\PluginAwareInterface in order to gain
* access to the plugin.
*/
interface PluginFormFactoryInterface {
/**
* Creates a new form instance.
*
* @param \Drupal\Core\Plugin\PluginWithFormsInterface $plugin
* The plugin the form is for.
* @param string $operation
* The name of the operation to use, e.g., 'add' or 'edit'.
* @param string $fallback_operation
* (optional) The name of the fallback operation to use.
*
* @return \Drupal\Core\Plugin\PluginFormInterface
* A plugin form instance.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function createInstance(PluginWithFormsInterface $plugin, $operation, $fallback_operation = NULL);
}

View file

@ -7,6 +7,10 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Provides an interface for an embeddable plugin form.
*
* Plugins can implement this form directly, or a standalone class can be used.
* Decoupled forms can implement \Drupal\Component\Plugin\PluginAwareInterface
* in order to gain access to the plugin.
*
* @ingroup plugin_api
*/
interface PluginFormInterface {
@ -27,7 +31,9 @@ interface PluginFormInterface {
* @param array $form
* An associative array containing the initial structure of the plugin form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the complete form.
* The current state of the form. Calling code should pass on a subform
* state created through
* \Drupal\Core\Form\SubformState::createForSubform().
*
* @return array
* The form structure.
@ -41,7 +47,9 @@ interface PluginFormInterface {
* An associative array containing the structure of the plugin form as built
* by static::buildConfigurationForm().
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the complete form.
* The current state of the form. Calling code should pass on a subform
* state created through
* \Drupal\Core\Form\SubformState::createForSubform().
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state);
@ -52,7 +60,9 @@ interface PluginFormInterface {
* An associative array containing the structure of the plugin form as built
* by static::buildConfigurationForm().
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the complete form.
* The current state of the form. Calling code should pass on a subform
* state created through
* \Drupal\Core\Form\SubformState::createForSubform().
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state);

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\Core\Plugin;
use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* Provides an interface for plugins which have forms.
*
* Plugin forms are embeddable forms referenced by the plugin annotation.
* Used by plugin types which have a larger number of plugin-specific forms.
*/
interface PluginWithFormsInterface extends PluginInspectionInterface {
/**
* Gets the form class for the given operation.
*
* @param string $operation
* The name of the operation.
*
* @return string|null
* The form class if defined, NULL otherwise.
*/
public function getFormClass($operation);
/**
* Gets whether the plugin has a form class for the given operation.
*
* @param string $operation
* The name of the operation.
*
* @return bool
* TRUE if the plugin has a form class for the given operation.
*/
public function hasFormClass($operation);
}

View file

@ -0,0 +1,29 @@
<?php
namespace Drupal\Core\Plugin;
/**
* Provides a trait with typical behavior for plugins which have forms.
*/
trait PluginWithFormsTrait {
/**
* {@inheritdoc}
*/
public function getFormClass($operation) {
if (isset($this->getPluginDefinition()['forms'][$operation])) {
return $this->getPluginDefinition()['forms'][$operation];
}
elseif ($operation === 'configure' && $this instanceof PluginFormInterface) {
return static::class;
}
}
/**
* {@inheritdoc}
*/
public function hasFormClass($operation) {
return !empty($this->getFormClass($operation));
}
}