Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Status: Active » Needs review
FileSize
17.97 KB

This makes a lot of sense to me and makes the code much easier, getting the unit tests to pass again was not trivial...

- Constraints are now only checked if they are added *explicitly* to the required context of a plugin and not automatically through the typed data type. Those constrains are to validate their internal data, context & and context definition should not care if an entity is valid, it should just care if it matches. Right now, expecting an email for example would require that the provided context also explicitly defines the email constraint, but there is no reason that it has to care about that.
- As a result, removed the @todo related to that, if you now *do* specify a constraint, then it should be checked.
- Removed some unit tests that were testing that
- Updated some others and switched to ContextDefinition (without a mock) instead of mocked DataDefinition objects, also threw out everything typed data related

dawehner’s picture

Do we need a change notice for this kind of things?

  1. +++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
    @@ -96,17 +48,16 @@ public function checkRequirements(array $contexts, array $requirements) {
    +      if ($definition->getDataType() != $context_definition->getDataType() && $definition->getDataType() != 'any') {
    

    Maybe we should add a comment like "'any' does always match.".

  2. +++ b/core/modules/node/config/install/entity.view_mode.node.search_index.yml
    @@ -6,3 +6,4 @@ targetEntityType: node
     dependencies:
       module:
         - node
    +    - search
    
    +++ b/core/modules/node/config/install/entity.view_mode.node.search_result.yml
    @@ -6,3 +6,4 @@ targetEntityType: node
     dependencies:
       module:
         - node
    +    - search
    
    +++ b/core/modules/node/src/Tests/NodeSaveTest.php
    @@ -30,6 +30,10 @@ public static function getInfo() {
    +    debug(\Drupal::configFactory()->listAll());
    +    \Drupal::moduleHandler()->install(array('views'));
    +    debug(\Drupal::configFactory()->listAll());
    

    These changes feel unrelated tbh.

  3. +++ b/core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php
    @@ -96,37 +66,19 @@ public function testCheckRequirements($contexts, $requirements, $expected) {
    +    $requirement_any = new ContextDefinition();
    +    $requirement_any->setRequired(TRUE);
    

    I really like that the API of using the context handler got easier!

Berdir’s picture

Lol, yeah, those changes are completely unrelated, was testing something else...

Berdir’s picture

dawehner’s picture

@berdir
Any oppinions about the comment?

Berdir’s picture

Ah, yes, let's add a comment there.

Berdir’s picture

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I Like this.

tim.plunkett’s picture

+1

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

I've considered this and I like it too.

Committed 0ede95d and pushed to 8.0.x. Thanks!

diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
index fc07f59..a5a5a3a 100644
--- a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php
@@ -8,7 +8,6 @@
 namespace Drupal\Core\Plugin\Context;
 
 use Drupal\Component\Plugin\ConfigurablePluginInterface;
-use Drupal\Core\Plugin\Context\ContextDefinitionInterface;
 use Drupal\Component\Plugin\ContextAwarePluginInterface;
 use Drupal\Component\Plugin\Exception\ContextException;
 use Drupal\Component\Utility\String;
diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php b/core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php
index c13bec1..bd0ade5 100644
--- a/core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php
+++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandlerInterface.php
@@ -7,7 +7,6 @@
 
 namespace Drupal\Core\Plugin\Context;
 
-use Drupal\Core\Plugin\Context\ContextDefinitionInterface;
 use Drupal\Component\Plugin\ContextAwarePluginInterface;
 
 /**
@@ -53,7 +52,7 @@ public function checkRequirements(array $contexts, array $requirements);
    *
    * @param \Drupal\Component\Plugin\Context\ContextInterface[] $contexts
    *   An array of contexts.
-   * @param \Drupal\Component\Plugin\Context\ContextDefinitionInterface $definition
+   * @param \Drupal\Core\Plugin\Context\ContextDefinitionInterface $definition
    *   The definition to satisfy.
    *
    * @return \Drupal\Component\Plugin\Context\ContextInterface[]

Minor clean up on commit.

  • alexpott committed 0ede95d on 8.0.x
    Issue #2293205 by Berdir | tim.plunkett: Consider removing usage of...
Berdir’s picture

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.