Inconsistent use of ContextDefinitionInterface in Drupal\Component\Plugin\Context\Context::getConstraints()

Created on 19 November 2014, over 9 years ago
Updated 19 February 2023, over 1 year ago

Problem/Motivation

In writing unit tests for various parts of Component\Plugin for #2052109: [meta] Expand phpunit tests for \Drupal\Component\Plugin classes β†’ , I discovered that Drupal\Component\Plugin\Context\Context::getConstraints() tries to access an array property of an object.

  /**
   * Implements \Drupal\Component\Plugin\Context\ContextInterface::getConstraints().
   */
  public function getConstraints() {
    if (empty($this->contextDefinition['class'])) {
      throw new ContextException("An error was encountered while trying to validate the context.");
    }
    return array(new Type($this->contextDefinition['class']));
  }

$contextDefinition is defined as a \Drupal\Component\Plugin\Context\ContextDefinitionInterface.

After talking about it with @EclipseGC in IRC it seems that this is a bug.

It also seems that most of the Component aspect of Context is overridden by Core, which is why this bug hadn't been found yet.

Proposed resolution

Analyze a proper solution.

Remaining tasks

Analyze the requirements for Context::getConstraints().
Possibly modify ContextDefinitionInterface.
Modify Context::getConstraints() to conform with ContextDefinitionInterface.
Add PHPUnit test for the function Context::getConstraints()

User interface changes

API changes

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
PluginΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States Mile23 Seattle, WA

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024