Skip to content

Commit

Permalink
enhance: pass block data to enqueue method
Browse files Browse the repository at this point in the history
Ref Log1x#144 and Log1x#143 

I have played about locally on this and seems we can simply pass the `$block` array to the `enqueue` method which gives access to `$block['data']['my_field_name']`.
This allowed me to conditionally enqueue assets depending on field values.

This PR needs more work like adding the argument to `Block::enqueue($data = [])` but I opened the PR just to get the ball rolling on this.
It would result in a breaking change since the signature has changed.

@Log1x - anything to add to this? Not as nice as `get_field` in the method but hey it works.
  • Loading branch information
codepuncher authored Dec 21, 2022
1 parent 20532bb commit 3f0cef7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ public function compose()
'align_content' => $this->align_content,
'styles' => $this->styles,
'supports' => $this->supports,
'enqueue_assets' => function () {
return $this->enqueue();
'enqueue_assets' => function ($block) {
return $this->enqueue($block);
},
'render_callback' => function (
$block,
Expand Down

0 comments on commit 3f0cef7

Please sign in to comment.