diff --git a/core/lib/Drupal/Component/Plugin/Context/Context.php b/core/lib/Drupal/Component/Plugin/Context/Context.php index 0c478d3..f1b8e8f 100644 --- a/core/lib/Drupal/Component/Plugin/Context/Context.php +++ b/core/lib/Drupal/Component/Plugin/Context/Context.php @@ -37,7 +37,7 @@ public function __construct($contextDefinition) { } /** - * Implements \Drupal\Component\Plugin\Context\ContextInterface::setContext(). + * Implements \Drupal\Component\Plugin\Context\ContextInterface::setContextValue(). */ public function setContextValue($value) { $value = $this->validate($value); @@ -45,9 +45,9 @@ public function setContextValue($value) { } /** - * Implements \Drupal\Component\Plugin\Context\ContextInterface::getContext(). + * Implements \Drupal\Component\Plugin\Context\ContextInterface::getContextValue(). */ - public function getContext() { + public function getContextValue() { return $this->contextValue; } diff --git a/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php b/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php index 3c9cc9e..157f008 100644 --- a/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php +++ b/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php @@ -15,24 +15,24 @@ interface ContextInterface { /** - * Set the context value of this class. + * Sets the context value. * * @param mixed $value - * A context is some value, generally a class matching the definition - * passed to setContextDefinition(). + * The value of this context, generally an object based upon the class + * matching the definition passed to setContextDefinition(). */ public function setContextValue($value); /** - * Get the set context of this class. + * Gets the context value. * * @return object - * The currently set context within this class. + * The currently set context value within this class. */ - public function getContext(); + public function getContextValue(); /** - * Set the definition that the context must conform to. + * Sets the definition that the context must conform to. * * @param mixed $contextDefinition * A defining characteristic representation of the context against which @@ -42,22 +42,26 @@ public function getContext(); public function setContextDefinition($contextDefinition); /** - * Get the provided definition that the context must conform to. + * Gets the provided definition that the context must conform to. * - * @return string + * @return mixed * The defining characteristic representation of the context. */ public function getContextDefinition(); /** - * Validate the provided context against the provided definition. + * Validate the provided context value against the provided definition. * - * @param mixed $context - * The context that should be validated against the context definition. + * @param mixed $value + * The context value that should be validated against the context + * definition. * * @return mixed - * Returns the object passed to it, or a class based representation of the - * context. If it fails validation, an exception will be thrown. + * Returns the context value passed to it. If it fails validation, an + * exception will be thrown. + * + * @throws \Drupal\Component\Plugin\Exception\ContextException + * If validation fails. */ public function validate($value); diff --git a/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php index 8ab7860..4538ed0 100644 --- a/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php @@ -1,4 +1,5 @@ getContexts() as $key => $context) { - $contexts[$key] = $context->getContext(); + $contexts[$key] = $context->getContextValue(); } return $contexts; } @@ -85,7 +86,7 @@ public function getContextValues() { * Implements \Drupal\Component\Plugin\ContextAwarePluginInterface::getContextValue(). */ public function getContextValue($key) { - return $this->getContext($key)->getContext(); + return $this->getContext($key)->getContextValue(); } /** diff --git a/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php b/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php index 1aacc20..0892716 100644 --- a/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php +++ b/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php @@ -1,4 +1,5 @@ create($this->contextDefinition, $value); // If we do have a typed data definition, validate it and return the // typed data instance instead. - if ($typed_data->validate()) { + $violations = $typed_data->validate(); + if (count($violations) == 0) { return $typed_data; } throw new ContextException("The context passed could not be validated through typed data."); diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php index 2aba6e3..2eab5fa 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php @@ -98,7 +98,7 @@ function testContext() { } // Set an appropriate context value appropriately and check to make sure - //its methods work as expected. + // its methods work as expected. $user = entity_create('user', array('name' => $name)); $plugin->setContextValue('user', $user); $this->assertEqual($user->label(), $plugin->getTitle()); @@ -118,7 +118,7 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The node context is not a valid context.'); } - // Test TypedData Context Plugins + // Test typed data context plugins. $typed_data_plugin = $manager->createInstance('string_context'); // Try to get a valid context value that has not been set. @@ -189,8 +189,8 @@ function testContext() { $complex_plugin->setContextValue('node', $node); $context_wrappers = $complex_plugin->getContexts(); // Make sure what came out of the wrappers is good. - $this->assertEqual($context_wrappers['user']->getContext()->label(), $user->label()); - $this->assertEqual($context_wrappers['node']->getContext()->label(), $node->label()); + $this->assertEqual($context_wrappers['user']->getContextValue()->label(), $user->label()); + $this->assertEqual($context_wrappers['node']->getContextValue()->label(), $node->label()); // Make sure what comes out of the context values is good. $contexts = $complex_plugin->getContextValues();