Problem/Motivation

Example scenario:

A block plugin that allows to select a config entity as part of the block instance settings.

That config entity is then a dependency of that block because the block does not function without it. But there is no way to expose that.

This is different from block derivatives as there is no exposed plugin definition for each config entity.

Core has such a use case too, but in that case, it's a content entity, which makes it a different (but also unsolved problem): aggregator feed blocks.

Proposed resolution

Add a method to ConfigurablePluginInterface to calculate dependencies.

Remaining tasks

Determine what other configurable plugins need to add code (could be a follow-up)

User interface changes

API changes

ConfigurablePluginInterface now has a new method, calculateDependencies().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm’s picture

Priority: Normal » Major
Issue tags: +Configuration system, +beta target, +Block plugins, +Configurables

So this is at least a beta target, maybe (probably) a beta blocker.

I had trouble understanding how this was different from e.g. menu blocks but this is the usecase:

I have a block plugin that doesn't use derivatives; instead, it adds to the block instance configuration. When I place an instance of this block, there's a form element where I can select the vocabularies that this block will display something-or-other for; could be one, or none, or several. So each block instance may have a dependency on one or more vocabularies. Since the config_dependencies key is part of the plugin definition as provided by derivatives -- not its configuration as stored in the block instance entity -- it doesn't help us.

xjm’s picture

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

Working on this.

tim.plunkett’s picture

Title: Block plugins can not control block configuration related config dependencies » Configurable plugins can not control instance-specific config dependencies
Component: block.module » plugin system
Issue summary: View changes
Status: Active » Needs review
FileSize
1.2 KB
9.03 KB

This is bigger than blocks. I can reproduce in HEAD with actions and user roles:
For each user role, two actions are configured for adding and removing that role from a user.

The action export has no reference to these.

tim.plunkett’s picture

Here is an alternate solution, this moves all of the plugin related dependencies into one place. However, this needs an interface of some sort, and only works if you extend PluginBase.

tim.plunkett’s picture

I think #4 is much more clear in terms of who is responsible for what. Regular plugins do not care about dependencies, just configurable ones.
But #5 is cleaner code IMO, and makes the entity less aware of what plugins need.

I'm happy with either, and I defer to @Berdir/@alexpott.

xjm’s picture

Priority: Major » Critical
Issue tags: -beta target +beta blocker

Yeah this is beta-blocking then.

The last submitted patch, 4: plugin-dependencies-2248151-4-PASS.patch, failed testing.

The last submitted patch, 4: plugin-dependencies-2248151-4-FAIL.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: plugin-dependencies-2248151-5.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
14.66 KB

This is 4 rerolled. Ditching 5, it's too much for all plugins, and overkill.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.23 KB
14.93 KB

Looks great. Minor clean up to use addDependencies() instead of addDependency() to avoid code repetition.

tim.plunkett’s picture

Hah, didn't know that was a method! That alleviates some of my worries about the ugliness of that, thanks.

xjm’s picture

+++ b/core/lib/Drupal/Component/Plugin/ConfigurablePluginInterface.php
@@ -36,4 +36,12 @@ public function setConfiguration(array $configuration);
+   * Calculates dependencies.

Whoa this is RTBC already. Awesome!

That said this needs MUCH better documentation...

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Good point @xjm should have noticed that.

xjm’s picture

Status: Needs work » Needs review
FileSize
15.68 KB
1.23 KB

@alexpott and I came up with this expansion of the docs. We can add this to start, and then expand the scope of #2235363: Document config dependencies to configuration dependencies in general, because there's a lot more than that one key that needs documenting (as @tim.plunkett pointed out).

xjm’s picture

FileSize
15.71 KB
699 bytes

Sorry, one more fix.

alexpott’s picture

Status: Needs review » Reviewed & tested by the community

rtbc if green

catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks great. Committed/pushed to 8.x, thanks!

  • Commit 4c83e77 on 8.x by catch:
    Issue #2248151 by tim.plunkett, xjm, alexpott: Configurable plugins can...
tstoeckler’s picture

This commit added an empty db.sqlite file to the repo. I suppose that should be deleted.

  • Commit 2e739f1 on 8.x by catch:
    Issue #2248151 by catch, tstoeckler: follow-up remove empty db.sqlite...
catch’s picture

Missed that reviewing. Fixed locally and pushed.

Xano’s picture

This patch alters \Drupal\Component\Plugin\ConfigurablePluginInterface with references to \Drupal\Core, and effectively this is a core and not a component feature. Should we create \Drupal\Core\Plugin\ConfigurablePluginInterface and move this code there?

alexpott’s picture

#25 I guess so yep

catch’s picture

The references are to \Drupal\Core but the code doesn't introduce any dependency and could be used without core concepts.

I don't think we should move it, but not sure how to clean that up either.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned

Thanks!

Status: Fixed » Closed (fixed)

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