Add ContextHandler::applyRuntimeContext()

Created on 14 May 2017, about 7 years ago
Updated 30 January 2023, over 1 year ago

Problem/Motivation

ContextHandler and LazyContextRepository were written separately, but are always used together.
The existing pattern is this:

if ($plugin instanceof ContextAwarePluginInterface) {
  $contexts = \Drupal::service('context.repository')->getRuntimeContexts(array_values($plugin->getContextMapping()));
  \Drupal::service('context.handler')->applyContextMapping($plugin, $contexts);
}

This is done in every usage of ContextHandler::applyContextMapping in core, and every one I've seen in contrib.

Proposed resolution

Add a ContextHandler::applyRuntimeContext() method to encapsulate this.
It becomes a lot more clear how to get contexts into your plugins this way.

Remaining tasks

Change record, possibly?

User interface changes

N/A

API changes

ContextHandlerInterface is expanded, but this is a complex service with very specific logic that was adapted straight from CTools. There is little reason to swap out this service, and even less reason to bypass subclassing ContextHandler.

Data model changes

N/A

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
PluginΒ  β†’

Last updated about 15 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States tim.plunkett Philadelphia

Live updates comments and jobs are added and updated live.
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