I believe $sandwich_plugin_info should be passed by reference for it to actually work. The current code modifies a copy, and I'm pretty certain that won't actually do anything.
Current code (plugin_type_example/plugin_type_example.api.php):
/**
* Alter the definitions of all the Sandwich plugins.
*
* You can implement this hook to do things like change the properties for each
* plugin or change the implementing class for a plugin.
*
* This hook is invoked by SandwichPluginManager::__construct().
*
* @param array $sandwich_plugin_info
* This is the array of plugin definitions.
*/
function hook_sandwich_info_alter(array $sandwich_plugin_info) {
// Let's change the 'foobar' property for all sandwiches.
foreach ($sandwich_plugin_info as $plugin_id => $plugin_definition) {
$sandwich_plugin_info[$plugin_id]['foobar'] = t('We have altered this in the alter hook');
}
}
I've also verified in a few core api.php files that their plugin info alter hooks do pass the definition array by reference - so I think the code example is incorrect.
Patch on the way...
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | examples-plugin-type-example-info-alter-pbv-bug-2931559-2.patch | 1.07 KB | chrisolof |
Comments
Comment #2
chrisolofPatch attached.
Comment #3
mile23Thanks.
When I look at the page, I see "Ham, mustard, ROCKET, sun-dried tomatoes." So the
plugin_type_example_sandwich_info_alter()hook is having an effect.The patch changes the API documentation for the hook, and that's good.
However:
PluginTypeExampleTestsays this:We don't have a test that the hook worked, so let's add one.
PluginTypeExampleTest::testPluginExample()really should be its own kernel test, but that's optional for this issue.Comment #4
mile23Comment #6
mile23The actual hook implementation looks like this:
So we're already doing this in code. This is a documentation bug.
We still have a @todo that needs a follow-up in #3, and here it is: #2985705: Ensure hook_sandwich_info_alter() works
Updated the todo with a link, fixed on commit.
Thanks!