Follow up for #1871772: Convert custom blocks to content entities
Problem/Motivation
+++ b/core/modules/block/custom_block/custom_block.module
@@ -53,3 +157,161 @@ function theme_custom_block_block($variables) {
+function custom_block_block_view_alter(array &$build, Block $block) {
+ // Add contextual links for custom blocks.
For adding stuff to block views, we should have a _view hook that is not a _view_alter hook. I don't know whether that exists or not, but in case it does not, we need one (and this one should be converted). Potential follow-up issue.
Proposed resolution
Investigate a hook_block_view() hook and use it for contextual links in custom_block instead of hook_block_view_alter().
Remaining tasks
Investigate hook
Update custom_block.module
Comments
Comment #1
sunComment #2
webchickThat sounds like fine refactoring, but not sure why it's major.
Comment #3
babruix CreditAttribution: babruix commentedComment #4
babruix CreditAttribution: babruix commentedThere is no special hook_block_view() hook, only one instance of 'block_view' is in
which hands off the passed-in variables to type-specific hook_TYPE_alter() implementations in modules,
see http://api.drupal.org/api/drupal/includes!module.inc/function/drupal_alt...
So on my opinion, using hook_block_view_alter is correct.
Another problems that drupal_alter is deprecated, and we should use instead drupal_container()->get('module_handler')->alter($hook).
But! drupal_container is also deprecated and has been replaced by the \Drupal class: Drupal::getContainer();
And finally getContainer documentation says: This method is only useful for the testing environment, and as a BC shiv for drupal_container(). It should not be used otherwise.
So that confusing me that everything is deprecated. Probably there are separated issue for that, if no we should create one.
Comment #5
tstoecklerThat it is deprecated only means that the block plugin manager should get the module handler injected by the DIC and then use $this->moduleHandler->alter() or whatever.
I still think we want to do this, however. There s currently no hook_block_view() because blocks were converted to plugins and each block plugin class has a view() method which is basically the replacement for hook_block_view(). The problem is that this is a feature regression. Previously with hook_block_view() module A could provide information for module B's blocks. E.g. in the case of contextual links:
Now that this information is in a class method of each block plugin contextual module has no way of adding that information. It therefore resorts to using hook_block_view_alter() but that is conceptually wrong. It is not altering information, it is adding information. This becomes clear when you want to alter the information provided by contextual module in you own mymodule_block_view_alter(). You can only do that if your module's alter hook is called after contextual module's alter hook.
Comment #5.0
tstoecklercorrected hook name
Comment #6
YesCT CreditAttribution: YesCT commentedremoving novice tag.
What are the next steps here exactly, or questions that need to be answered?
Comment #9
tim.plunkettNot actively part of the Blocks-Layouts work.