Closed (fixed)
Project:
Commerce Ajax Add to Cart
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
3 Nov 2017 at 06:47 UTC
Updated:
24 Nov 2017 at 06:44 UTC
Jump to comment: Most recent
Currently the status messages block is loaded using block id. Block id may vary as per the installation.
Use entity field query
$theme_manager = \Drupal::service('theme.manager');
$active_theme = $theme_manager->getActiveTheme()->getName();
$ids = \Drupal::entityQuery('block')
->condition('plugin', 'system_messages_block')
->condition('theme', $active_theme)
->execute();
to obtain the block id.
Update kernel tests.
N/A
N/A
N/A
Comments
Comment #2
subhojit777Comment #3
subhojit777Found out that one shortcoming of using plugin.manager.block service is that it does not gives the region where the block is placed. The region can only be obtained from the block entity.
Something like this:
can be done to check if status messages is placed in the current theme. The result
$idswould give the block id, and using the block id the block entity can be loaded, which would give the region where block is placed.Comment #4
subhojit777If I am going with the query as mentioned in #3 then it would create an inconsistency in the code.
I am using block plugin manager to load the
commerce_cartblock. And I am happy with that approach. I can't find any reason to change the approach, and use a query like this #3.Considering that the approach for refreshing cart content will not be changed, so, in future I will have to split
RefreshPageElementsHelperclass into two. One will refresh the status message, and the other will refresh the cart.Comment #5
subhojit777Comment #6
subhojit777Comment #8
subhojit777