PluginManagerBase::processDefinition() helpfully merges in default values, but it does so with +=, which only works for one dimensional arrays.

NestedArray (the OO version of drupal_merge_deep_array()) provides a way to recursively adde default values, without altering the original values.
It is also a Component, so there is not too much pollution there.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

Status: Active » Needs review
FileSize
697 bytes

This is needed for #1763974: Convert entity type info into plugins, and I can see it preventing some major WTF moments later.

tim.plunkett’s picture

This shows the problem, as well as echoing #1764278: Run PluginManagerBase::processDefinition() in a ProcessDecorator by showing the test was wrong all along.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community

Seems straight forward enough. I think I was just lazy and going for what worked quickly.

I don't know if we require tests for simple features like this but since it doesn't regress, change any documented functionality, or fix a bug I don't see the need. It looks good from my perspective.

neclimdul’s picture

x-post.

With tests! Even better. Assuming it passes my RTBC stands.

tstoeckler’s picture

Yup, makes total sense. I was about to propose the same in #1763974: Convert entity type info into plugins, but splitting this off is even better.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Hm. Could we get a separate test about this nested array thing specifically? The tests we're modifying are "// A simple plugin: a mock user login block." which are a good starting point for people to understand the plugin system, and mysteriously adding a weird "child" index to the user login form that doesn't actually exist seems to make that more confusing.

tstoeckler’s picture

which are a good starting point for people to understand the plugin system

Having recently written some tests for the plugin discovery system, I can assure you that that, sadly, is not quite the case currently. The whole Plugin test suite could use some serious refactoring for code coverage, decoupling and understandability. That said, you are 100% correct, that we shouldn't make things worse. Unless someone beats me to it, I'll cook up some tests this weekend.

Since the discovery tests are separated from the rest now, I think it would be easier to write tests for #1764278: Run PluginManagerBase::processDefinition() in a ProcessDecorator, which contains this issue, and mark this duplicate. What do you guys folks think about that? I think that would make sense, as that issue is where we want to go anyway with this.

EDIT: Less sexist form of address :-), hoping no toes were stepped upon.

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

#6, yes I can write a separate test

#7, the approach in that issue is flawed, and harms DX to boot. I'll follow up over there after I reroll this.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Needs work » Needs review
FileSize
7.43 KB
7.14 KB

The interdiff is pretty uninformative. But this adds a new manager, a new plugin, and new assertions.

tim.plunkett’s picture

Status: Needs review » Closed (duplicate)

I give up, #1764278: Run PluginManagerBase::processDefinition() in a ProcessDecorator is going to have to be the solution here.

tim.plunkett’s picture

Status: Closed (duplicate) » Needs review

After more discussion with @neclimdul, I realized my problems with this were because I was using the cache incorrectly. This is a correct and non-controversial fix, and the concept of a DefaultsDecorator can continue in the other issue.

neclimdul’s picture

Status: Needs review » Reviewed & tested by the community
neclimdul’s picture

err, forgot to comment. This is still straight forward and we've got more tests now! RTBC!

tim.plunkett’s picture

Priority: Normal » Major

This blocks #1763974: Convert entity type info into plugins which is major, so bumping to major and postponing that.

sun’s picture

Looks good to me as well.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Wow, that's even better than I was expecting. Thanks!

Committed and pushed to 8.x.

Status: Fixed » Closed (fixed)

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