Problem/Motivation

While working to make SectionStorage plugins context-aware, it was pointed out that context is a confusing name for what is really an array of context definitions.

The block annotation class (\Drupal\Core\Block\Annotation\Block) does not document this parameter, but it is assumed to be named that by other code.
The condition annotation class does document this parameter.

Proposed resolution

Switch from context to context_definitions

Remaining tasks

  1. Add context_definitions to both annotation classes
  2. Add a BC layer to support the old style, with @trigger_error
  3. Update all calling code
  4. Write a CR

User interface changes

N/A

API changes

BC support for changes

Data model changes

N/A

Release notes snippet

For context-aware plugins defined by annotation, the key for specifying context definitions has changed from context to context_definitions. Interacting with the context definitions of a plugin is unchanged, see \Drupal\Component\Plugin\ContextAwarePluginInterface.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
tim.plunkett’s picture

New approach, as this fix cannot wait until plugins are instantiated.

tim.plunkett’s picture

With that class_implements() check, \Drupal\Tests\Core\Plugin\DefaultPluginManagerTest::testDefaultPluginManagerWithPluginExtendingNonInstalledClass() will fatal due to \Drupal\plugin_test\Plugin\plugin_test\fruit\ExtendingNonInstalledClass

I think it's safe to skip that check.

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
@@ -297,6 +299,38 @@ protected function findDefinitions() {
+  private function fixContextAwareDefinitions(array &$definitions) {

hah! found a good use for private, nice.

This seems super reasonable and I support this change completely.

Eclipse

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This change looks sensible. Not the plugin definition key matches the method name \Drupal\Core\Plugin\Context\ContextHandler::getContextDefinitions()

+++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php
@@ -451,6 +452,34 @@ public function providerTestProcessDefinition() {
+   * @group legacy
+   */
+  public function testFixContextAwareDefinitions() {

Let's add an @expectedDeprecation to make that's triggered.

dhirendra.mishra’s picture

dhirendra.mishra’s picture

i shud add @expectedDeprecation of which method ?

tim.plunkett’s picture

Interesting that we use @expectedDeprecation instead of $this->setExpectedDeprecation(), the opposite of @expectedException/setExpectedException

tim.plunkett’s picture

Status: Needs work » Needs review
EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

Eclipse

alexpott’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

doh forgot to ask for a change record. As a deprecation and a change we need one. Also probably need a release note snippet.

@tim.plunkett we added the expectDeprecation functionality to have dynamic expectations... but we've always hoped to move this upstream.

/**
 * Adds the ability to dynamically set expected deprecation messages in tests.
 *
 * @internal
 *   This class should only be used by Drupal core and will be removed once
 *   https://github.com/symfony/symfony/pull/25757 is resolved.
 *
 * @todo Remove once https://github.com/symfony/symfony/pull/25757 is resolved.
 */

Symfony's deprecation functionality on it's own only supports the annotation at this point.

phenaproxima’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed bab4f6d and pushed to 8.7.x. Thanks!

diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
index d7f7f125c2..b1c79fe7ca 100644
--- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
+++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php
@@ -3,7 +3,6 @@
 namespace Drupal\Core\Plugin;
 
 use Drupal\Component\Assertion\Inspector;
-use Drupal\Component\Plugin\ContextAwarePluginInterface as ComponentContextAwarePluginInterface;
 use Drupal\Component\Plugin\Definition\PluginDefinitionInterface;
 use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
 use Drupal\Core\Cache\CacheableDependencyInterface;

Fixed unused use on commit.

  • alexpott committed bab4f6d on 8.7.x
    Issue #3014949 by tim.plunkett: Deprecate 'context' on Block and...
tim.plunkett’s picture

tim.plunkett’s picture

Issue summary: View changes
tim.plunkett’s picture

Issue tags: +8.7.0 release notes
Upchuk’s picture

tim.plunkett’s picture

Note that the patch in that issue actually passed testing, and only failed because of the deprecations. Meaning that the BC layer worked great!

Status: Fixed » Closed (fixed)

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

tim.plunkett’s picture

Issue tags: +Blocks-Layouts