Skip to content

Commit b01f86b

Browse files
author
Mateu Aguiló Bosch
committed
[FEATURE] Catchup with final 8.0.0 version
1 parent b3b2f38 commit b01f86b

13 files changed

Lines changed: 162 additions & 87 deletions

File tree

lib/Drupal/Component/Annotation/Reflection/MockFileFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MockFileFinder implements ClassFinderInterface {
2626
protected $filename;
2727

2828
/**
29-
* Implements Doctrine\Common\Reflection\ClassFinderInterface::findFile().
29+
* {@inheritdoc}
3030
*/
3131
public function findFile($class) {
3232
return $this->filename;

lib/Drupal/Component/FileCache/FileCache.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,13 @@ public function delete($filepath) {
153153
}
154154
}
155155

156+
/**
157+
* Resets the static cache.
158+
*
159+
* @todo Replace this once https://www.drupal.org/node/2260187 is in.
160+
*/
161+
public static function reset() {
162+
static::$cached = [];
163+
}
164+
156165
}

lib/Drupal/Component/Plugin/Context/Context.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,20 @@ class Context implements ContextInterface {
3131
protected $contextDefinition;
3232

3333
/**
34-
* Sets the contextDefinition for us without needing to call the setter.
34+
* Create a context object.
3535
*
3636
* @param \Drupal\Component\Plugin\Context\ContextDefinitionInterface $context_definition
3737
* The context definition.
38+
* @param mixed|null $context_value
39+
* The value of the context.
3840
*/
39-
public function __construct(ContextDefinitionInterface $context_definition) {
41+
public function __construct(ContextDefinitionInterface $context_definition, $context_value = NULL) {
4042
$this->contextDefinition = $context_definition;
43+
$this->contextValue = $context_value;
4144
}
4245

4346
/**
44-
* Implements \Drupal\Component\Plugin\Context\ContextInterface::setContextValue().
45-
*/
46-
public function setContextValue($value) {
47-
$this->contextValue = $value;
48-
}
49-
50-
/**
51-
* Implements \Drupal\Component\Plugin\Context\ContextInterface::getContextValue().
47+
* {@inheritdoc}
5248
*/
5349
public function getContextValue() {
5450
// Support optional contexts.
@@ -77,19 +73,12 @@ public function hasContextValue() {
7773
/**
7874
* {@inheritdoc}
7975
*/
80-
public function setContextDefinition(ContextDefinitionInterface $context_definition) {
81-
$this->contextDefinition = $context_definition;
82-
}
83-
84-
/**
85-
* Implements \Drupal\Component\Plugin\Context\ContextInterface::getContextDefinition().
86-
*/
8776
public function getContextDefinition() {
8877
return $this->contextDefinition;
8978
}
9079

9180
/**
92-
* Implements \Drupal\Component\Plugin\Context\ContextInterface::getConstraints().
81+
* {@inheritdoc}
9382
*/
9483
public function getConstraints() {
9584
if (empty($this->contextDefinition['class'])) {
@@ -99,7 +88,7 @@ public function getConstraints() {
9988
}
10089

10190
/**
102-
* Implements \Drupal\Component\Plugin\Context\ContextInterface::validate().
91+
* {@inheritdoc}
10392
*/
10493
public function validate() {
10594
$validator = Validation::createValidatorBuilder()

lib/Drupal/Component/Plugin/Context/ContextInterface.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
*/
1313
interface ContextInterface {
1414

15-
/**
16-
* Sets the context value.
17-
*
18-
* @param mixed $value
19-
* The value of this context, matching the context definition.
20-
*
21-
* @see \Drupal\Component\Plugin\Context\ContextInterface::setContextDefinition().
22-
*/
23-
public function setContextValue($value);
24-
2515
/**
2616
* Gets the context value.
2717
*
@@ -38,15 +28,6 @@ public function getContextValue();
3828
*/
3929
public function hasContextValue();
4030

41-
/**
42-
* Sets the definition that the context must conform to.
43-
*
44-
* @param \Drupal\Component\Plugin\Context\ContextDefinitionInterface $context_definition
45-
* A defining characteristic representation of the context against which
46-
* that context can be validated.
47-
*/
48-
public function setContextDefinition(ContextDefinitionInterface $context_definition);
49-
5031
/**
5132
* Gets the provided definition that the context must conform to.
5233
*

lib/Drupal/Component/Plugin/ContextAwarePluginBase.php

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,30 @@ abstract class ContextAwarePluginBase extends PluginBase implements ContextAware
4141
* The plugin implementation definition.
4242
*/
4343
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
44-
$context = array();
45-
if (isset($configuration['context'])) {
46-
$context = $configuration['context'];
47-
unset($configuration['context']);
48-
}
44+
$context_configuration = isset($configuration['context']) ? $configuration['context'] : [];
45+
unset($configuration['context']);
46+
4947
parent::__construct($configuration, $plugin_id, $plugin_definition);
50-
foreach ($context as $key => $value) {
48+
49+
$this->contexts = $this->createContextFromConfiguration($context_configuration);
50+
}
51+
52+
/**
53+
* Creates context objects from any context mappings in configuration.
54+
*
55+
* @param array $context_configuration
56+
* An associative array of context names and values.
57+
*
58+
* @return \Drupal\Component\Plugin\Context\ContextInterface[]
59+
* An array of context objects.
60+
*/
61+
protected function createContextFromConfiguration(array $context_configuration) {
62+
$contexts = [];
63+
foreach ($context_configuration as $key => $value) {
5164
$context_definition = $this->getContextDefinition($key);
52-
$this->context[$key] = new Context($context_definition);
53-
$this->context[$key]->setContextValue($value);
65+
$contexts[$key] = new Context($context_definition, $value);
5466
}
67+
return $contexts;
5568
}
5669

5770
/**
@@ -124,7 +137,7 @@ public function getContextValue($name) {
124137
* {@inheritdoc}
125138
*/
126139
public function setContextValue($name, $value) {
127-
$this->getContext($name)->setContextValue($value);
140+
$this->context[$name] = new Context($this->getContextDefinition($name), $value);
128141
return $this;
129142
}
130143

lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ public function getContextDefinitions();
3333
* @param string $name
3434
* The name of the context in the plugin definition.
3535
*
36-
* @throws \Drupal\Component\Plugin\Exception\PluginException
37-
* If the requested context is not defined.
38-
*
3936
* @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface.
4037
* The definition against which the context value must validate.
38+
*
39+
* @throws \Drupal\Component\Plugin\Exception\PluginException
40+
* If the requested context is not defined.
4141
*/
4242
public function getContextDefinition($name);
4343

4444
/**
4545
* Gets the defined contexts.
4646
*
47-
* @throws \Drupal\Component\Plugin\Exception\PluginException
48-
* If contexts are defined but not set.
49-
*
5047
* @return array
5148
* The set context objects.
49+
*
50+
* @throws \Drupal\Component\Plugin\Exception\PluginException
51+
* If contexts are defined but not set.
5252
*/
5353
public function getContexts();
5454

@@ -58,11 +58,11 @@ public function getContexts();
5858
* @param string $name
5959
* The name of the context in the plugin definition.
6060
*
61-
* @throws \Drupal\Component\Plugin\Exception\PluginException
62-
* If the requested context is not set.
63-
*
6461
* @return \Drupal\Component\Plugin\Context\ContextInterface
6562
* The context object.
63+
*
64+
* @throws \Drupal\Component\Plugin\Exception\PluginException
65+
* If the requested context is not set.
6666
*/
6767
public function getContext($name);
6868

@@ -81,11 +81,11 @@ public function getContextValues();
8181
* @param string $name
8282
* The name of the context in the plugin configuration.
8383
*
84-
* @throws \Drupal\Component\Plugin\Exception\PluginException
85-
* If the requested context is not set.
86-
*
8784
* @return mixed
8885
* The currently set context value.
86+
*
87+
* @throws \Drupal\Component\Plugin\Exception\PluginException
88+
* If the requested context is not set.
8989
*/
9090
public function getContextValue($name);
9191

@@ -108,11 +108,11 @@ public function setContext($name, ContextInterface $context);
108108
* The value to set the context to. The value has to validate against the
109109
* provided context definition.
110110
*
111-
* @throws \Drupal\Component\Plugin\Exception\PluginException
112-
* If the value does not pass validation.
113-
*
114111
* @return \Drupal\Component\Plugin\ContextAwarePluginInterface.
115112
* A context aware plugin object for chaining.
113+
*
114+
* @throws \Drupal\Component\Plugin\Exception\PluginException
115+
* If the value does not pass validation.
116116
*/
117117
public function setContextValue($name, $value);
118118

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains \Drupal\Component\Plugin\Definition\PluginDefinitionInterface.
6+
*/
7+
8+
namespace Drupal\Component\Plugin\Definition;
9+
10+
/**
11+
* Defines a plugin definition.
12+
*
13+
* Object-based plugin definitions MUST implement this interface.
14+
*
15+
* @ingroup Plugin
16+
*/
17+
interface PluginDefinitionInterface {
18+
19+
/**
20+
* Sets the class.
21+
*
22+
* @param string $class
23+
* A fully qualified class name.
24+
*
25+
* @return static
26+
*
27+
* @throws \InvalidArgumentException
28+
* If the class is invalid.
29+
*/
30+
public function setClass($class);
31+
32+
/**
33+
* Gets the class.
34+
*
35+
* @return string
36+
* A fully qualified class name.
37+
*/
38+
public function getClass();
39+
40+
}

lib/Drupal/Component/Plugin/Discovery/StaticDiscovery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StaticDiscovery implements DiscoveryInterface {
1616
use DiscoveryCachedTrait;
1717

1818
/**
19-
* Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
19+
* {@inheritdoc}
2020
*/
2121
public function getDefinitions() {
2222
if (!$this->definitions) {

lib/Drupal/Component/Plugin/Discovery/StaticDiscoveryDecorator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getDefinition($base_plugin_id, $exception_on_invalid = TRUE) {
5252
}
5353

5454
/**
55-
* Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
55+
* {@inheritdoc}
5656
*/
5757
public function getDefinitions() {
5858
if (isset($this->registerDefinitions)) {

lib/Drupal/Component/Plugin/Exception/InvalidDecoratedMethod.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace Drupal\Component\Plugin\Exception;
88

9-
use Drupal\Component\Plugin\Exception\ExceptionInterface;
109
use \BadMethodCallException;
1110

1211
/**

0 commit comments

Comments
 (0)