In light of https://www.drupal.org/node/2527840 we need to remove BlockEvent

Comments

benjy’s picture

Status: Active » Needs review
StatusFileSize
new4.76 KB

* setContexts() is gone from the block entity so we don't override that anymore.
* I've replaced the EventSubscriber with the ContextProvider

TODO
* I can't see how the BlockContext is going to get the block that is being placed
* Need to review the cacheable dependencies to make sure it's working.

benjy’s picture

StatusFileSize
new14.12 KB

Discussed with Berdir and he suggested a simplified approach using hook_block_access(). First attempt attached, which is indeed simpler.

Only thing to to check is the exclusion of block access in the admin, maybe that should be based on a new permission?

berdir’s picture

+++ b/per_user_block.module
@@ -22,6 +25,43 @@ define('PER_USER_BLOCK_CUSTOM_ENABLED', 1);
+function per_user_block_block_form_submit(&$form, FormStateInterface $form_state) {
+  /** @var \Drupal\block\Entity\Block $block */
+  $block = $form_state->getFormObject()->getEntity();
+  $visibility = $form_state->getValue(['per_user_block', 'visibility']);
+  $block->setThirdPartySetting('per_user_block', 'visibility', $visibility);
+  $block->save();
+}

If you already specify the form structure within third_party_settings then you don't need a submit callback at all I think.

benjy’s picture

Title: BlockEvent removed in favour of context repository » Remove BlockEvent in favour of hook_block_access()
StatusFileSize
new13.76 KB
new3.35 KB

Thanks Berdir, less code!

benjy’s picture

Final patch attached, mainly just some simplifications in hook_block_access().

benjy’s picture

StatusFileSize
new13.88 KB
benjy’s picture

Status: Needs review » Fixed

Done.

  • benjy committed 218e89e on 8.x-1.x
    Issue #2544628 by benjy, Berdir: Remove BlockEvent in favour of...

The last submitted patch, 1: 2544628-1.patch, failed testing.

The last submitted patch, 4: 2544628-4.patch, failed testing.

The last submitted patch, 2: 2544628-2.patch, failed testing.

Status: Fixed » Needs work

The last submitted patch, 6: 2544628-5.patch, failed testing.

benjy’s picture

Status: Needs work » Fixed

Now it decides to test :/

Status: Fixed » Closed (fixed)

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