diff --git a/core/lib/Drupal/Component/Plugin/Context/Context.php b/core/lib/Drupal/Component/Plugin/Context/Context.php index f172086..0c478d3 100644 --- a/core/lib/Drupal/Component/Plugin/Context/Context.php +++ b/core/lib/Drupal/Component/Plugin/Context/Context.php @@ -15,11 +15,11 @@ class Context implements ContextInterface { /** - * The context. + * The value of the context. * * @var mixed */ - protected $context; + protected $contextValue; /** * The class name or an array definition to which a context must conform. @@ -39,16 +39,16 @@ public function __construct($contextDefinition) { /** * Implements \Drupal\Component\Plugin\Context\ContextInterface::setContext(). */ - public function setContext($context) { - $context = $this->validate($context); - $this->context = $context; + public function setContextValue($value) { + $value = $this->validate($value); + $this->contextValue = $value; } /** - * Implements ContextInterface::getContext(). + * Implements \Drupal\Component\Plugin\Context\ContextInterface::getContext(). */ public function getContext() { - return $this->context; + return $this->contextValue; } /** @@ -68,12 +68,12 @@ public function getContextDefinition() { /** * Implements \Drupal\Component\Plugin\Context\ContextInterface::validate(). */ - public function validate($context) { + public function validate($value) { // Check to make sure we have a class name, and that the passed context is // an instance of that class name. if (is_string($this->contextDefinition)) { - if ($context instanceof $this->contextDefinition) { - return $context; + if ($value instanceof $this->contextDefinition) { + return $value; } throw new ContextException("The context passed was not an instance of $this->contextDefinition."); } diff --git a/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php b/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php index 2eb5348..3c9cc9e 100644 --- a/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php +++ b/core/lib/Drupal/Component/Plugin/Context/ContextInterface.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Component\Plugin\Context\Context. + * Contains \Drupal\Component\Plugin\Context\ContextInterface. */ namespace Drupal\Component\Plugin\Context; @@ -10,18 +10,18 @@ use Drupal\Component\Plugin\Exception\ContextException; /** - * A generic context interface. + * A generic context interface or wrapping data a plugin needs to operate. */ interface ContextInterface { /** - * Set the context of this class. + * Set the context value of this class. * - * @param mixed $context + * @param mixed $value * A context is some value, generally a class matching the definition * passed to setContextDefinition(). */ - public function setContext($context); + public function setContextValue($value); /** * Get the set context of this class. @@ -59,6 +59,6 @@ public function getContextDefinition(); * Returns the object passed to it, or a class based representation of the * context. If it fails validation, an exception will be thrown. */ - public function validate($context); + public function validate($value); } diff --git a/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php index 61f0d42..8ab7860 100644 --- a/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Component/Plugin/ContextAwarePluginBase.php @@ -94,7 +94,7 @@ public function getContextValue($key) { public function setContextValue($key, $value) { $context_definition = $this->getContextDefinition($key); $this->configuration['context'][$key] = new Context($context_definition); - $this->configuration['context'][$key]->setContext($value); + $this->configuration['context'][$key]->setContextValue($value); return $this; } diff --git a/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php b/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php index e97e874..1aacc20 100644 --- a/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php +++ b/core/lib/Drupal/Component/Plugin/ContextAwarePluginInterface.php @@ -17,7 +17,7 @@ /** * Returns the context definitions of the plugin. * - * @return mixed + * @return array|null * The context definitions if set, otherwise NULL. */ public function getContextDefinitions(); @@ -34,7 +34,7 @@ public function getContextDefinitions(); public function getContextDefinition($key); /** - * Gets the wrappers for set values for all defined contexts. + * Gets the defined contexts. * * @return array * Returns the array of all set context wrappers. @@ -42,14 +42,14 @@ public function getContextDefinition($key); public function getContexts(); /** - * Gets the context wrapper for a defined context. + * Gets the defined context. * * @param string $key * The name of the context in the plugin configuration. This string is * usually identical to the representative string in the plugin definition. * - * @return object - * Returns a context wrapper object. + * @return \Drupal\Core\Plugin\Context\Context object + * Returns a context object. */ public function getContext($key); diff --git a/core/lib/Drupal/Component/Plugin/Exception/ContextException.php b/core/lib/Drupal/Component/Plugin/Exception/ContextException.php index fbb1c2d..e9d7ded 100644 --- a/core/lib/Drupal/Component/Plugin/Exception/ContextException.php +++ b/core/lib/Drupal/Component/Plugin/Exception/ContextException.php @@ -1,7 +1,7 @@ contextDefinition)) { $typed_data_manager = new TypedDataManager(); - $typed_data = $typed_data_manager->create($this->contextDefinition, $context); + $typed_data = $typed_data_manager->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()) { @@ -35,7 +35,7 @@ public function validate($context) { } throw new ContextException("The context passed could not be validated through typed data."); } - return parent::validate($context); + return parent::validate($value); } } diff --git a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php index f8254c2..06b35d7 100644 --- a/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php +++ b/core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php @@ -13,9 +13,8 @@ * Drupal specific class for plugins that use context. * * This class specifically overrides setContextValue to use the core version of - * the Context wrapper class. This code is exactly the same as what is in - * Component ContextAwarePluginBase but it is using a different Context - * class. + * the Context class. This code is exactly the same as what is in Component + * ContextAwarePluginBase but it is using a different Context class. */ abstract class ContextAwarePluginBase extends PluginBase { @@ -25,7 +24,7 @@ public function setContextValue($key, $value) { $context_definition = $this->getContextDefinition($key); $this->configuration['context'][$key] = new Context($context_definition); - $this->configuration['context'][$key]->setContext($value); + $this->configuration['context'][$key]->setContextValue($value); return $this; } 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 0236fed..2aba6e3 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/ContextPluginTest.php @@ -42,7 +42,7 @@ function testContext() { // Create a node, add it as context, catch the exception. $node = entity_create('node', array('title' => $name)); - // Try to get a valid context wrapper that has not been set. + // Try to get a valid context that has not been set. try { $plugin->getContext('user'); $this->fail('The user context should not yet be set.'); @@ -51,7 +51,7 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The user context is not yet set.'); } - // Try to get an invalid context wrapper. + // Try to get an invalid context. try { $plugin->getContext('node'); $this->fail('The node context should not be a valid context.'); @@ -60,7 +60,7 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The node context is not a valid context.'); } - // Try to get a valid context that has not been set. + // Try to get a valid context value that has not been set. try { $plugin->getContextValue('user'); $this->fail('The user context should not yet be set.'); @@ -79,7 +79,7 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The user context is not yet set.'); } - // Try to get a context that is not valid. + // Try to get a context value that is not valid. try { $plugin->getContextValue('node'); $this->fail('The node context should not be a valid context.'); @@ -88,7 +88,7 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The node context is not a valid context.'); } - // Try to pass the wrong class type as a context. + // Try to pass the wrong class type as a context value. try { $plugin->setContextValue('user', $node); $this->fail('The node context should fail validation for a user context.'); @@ -97,8 +97,8 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The context passed was not an instance of Drupal\user\Plugin\Core\Entity\User.'); } - // Set an appropriate context appropriately and check to make sure its - // methods work as expected. + // Set an appropriate context value appropriately and check to make sure + //its methods work as expected. $user = entity_create('user', array('name' => $name)); $plugin->setContextValue('user', $user); $this->assertEqual($user->label(), $plugin->getTitle()); @@ -121,7 +121,7 @@ function testContext() { // Test TypedData Context Plugins $typed_data_plugin = $manager->createInstance('string_context'); - // Try to get a valid context that has not been set. + // Try to get a valid context value that has not been set. try { $typed_data_plugin->getContextValue('string'); $this->fail('The string context should not yet be set.'); @@ -130,8 +130,8 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The string context is not yet set.'); } - // Try to call a method of the plugin that requires context before it has - // been set. + // Try to call a method of the plugin that requires a context value before + // it has been set. try { $typed_data_plugin->getTitle(); $this->fail('The string context should not yet be set.'); @@ -140,14 +140,14 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The string context is not yet set.'); } - // Set the context appropriately and check the title. + // Set the context value appropriately and check the title. $typed_data_plugin->setContextValue('string', $name); $this->assertEqual($name, $typed_data_plugin->getTitle()); - // Test Complex compound contexts. + // Test Complex compound context handling. $complex_plugin = $manager->createInstance('complex_context'); - // With no contexts set, get the context wrappers. + // With no contexts set, try to get the contexts. try { $complex_plugin->getContexts(); $this->fail('There should not be any contexts set yet.'); @@ -156,7 +156,7 @@ function testContext() { $this->assertEqual($e->getMessage(), 'There are no set contexts.'); } - // With no contexts set, get the contexts. + // With no contexts set, try to get the context values. try { $complex_plugin->getContextValues(); $this->fail('There should not be any contexts set yet.'); @@ -165,10 +165,10 @@ function testContext() { $this->assertEqual($e->getMessage(), 'There are no set contexts.'); } - // Set the user context. + // Set the user context value. $complex_plugin->setContextValue('user', $user); - // With only the user context set, get the context wrappers. + // With only the user context set, try to get the contexts. try { $complex_plugin->getContexts(); $this->fail('The node context should not yet be set.'); @@ -177,7 +177,7 @@ function testContext() { $this->assertEqual($e->getMessage(), 'The node context is not yet set.'); } - // With only the user context set, get the contexts. + // With only the user context set, try to get the context values. try { $complex_plugin->getContextValues(); $this->fail('The node context should not yet be set.'); @@ -192,7 +192,7 @@ function testContext() { $this->assertEqual($context_wrappers['user']->getContext()->label(), $user->label()); $this->assertEqual($context_wrappers['node']->getContext()->label(), $node->label()); - // Make sure what comes out of Contexts is good. + // Make sure what comes out of the context values is good. $contexts = $complex_plugin->getContextValues(); $this->assertEqual($contexts['user']->label(), $user->label()); $this->assertEqual($contexts['node']->label(), $node->label()); diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php index 32553d5..f91675c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginTestBase.php @@ -71,21 +71,21 @@ public function setUp() { 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlock', ), 'user_name' => array( - 'label' => 'User Name', + 'label' => 'User name', 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserNameBlock', 'context' => array( 'user' => 'Drupal\user\Plugin\Core\Entity\User' ), ), 'string_context' => array( - 'label' => 'String Typed Data', + 'label' => 'String typed data', 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\TypedDataStringBlock', 'context' => array( 'string' => array('type' => 'string'), ), ), 'complex_context' => array( - 'label' => 'Complex Context', + 'label' => 'Complex context', 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockComplexContextBlock', 'context' => array( 'user' => 'Drupal\user\Plugin\Core\Entity\User', diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/MockBlockManager.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/MockBlockManager.php index 042bd22..4ef8283 100644 --- a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/MockBlockManager.php +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/MockBlockManager.php @@ -69,7 +69,7 @@ public function __construct() { // A block plugin that requires context to function. This block requires a // user object in order to return the user name from the getTitle() method. $this->discovery->setDefinition('user_name', array( - 'label' => t('User Name'), + 'label' => t('User name'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserNameBlock', 'context' => array( 'user' => 'Drupal\user\Plugin\Core\Entity\User' @@ -78,7 +78,7 @@ public function __construct() { // A block plugin that requires a typed data string context to function. $this->discovery->setDefinition('string_context', array( - 'label' => t('String Typed Data'), + 'label' => t('String typed data'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\TypedDataStringBlock', 'context' => array( 'string' => array('type' => 'string'), @@ -87,7 +87,7 @@ public function __construct() { // A complex context plugin that requires both a user and node for context. $this->discovery->setDefinition('complex_context', array( - 'label' => t('Complex Context'), + 'label' => t('Complex context'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockComplexContextBlock', 'context' => array( 'user' => 'Drupal\user\Plugin\Core\Entity\User', diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/mock_block/TypedDataStringBlock.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/mock_block/TypedDataStringBlock.php index 46cddaf..d58350d 100644 --- a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/mock_block/TypedDataStringBlock.php +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/plugin_test/mock_block/TypedDataStringBlock.php @@ -18,7 +18,7 @@ class TypedDataStringBlock extends ContextAwarePluginBase { public function getTitle() { - $context = $this->getContextValue('string'); - return $context->getValue(); + $string_context = $this->getContextValue('string'); + return $string_context->getValue(); } }