Skip to content

Conversation

@lukasbesch
Copy link
Contributor

In a blade block I created post meta is pulled. This works on the frontend, but not in the editor. The information to which post the block is attached to is available in the ACF native render_callback:

function renderBlockCallback(array $block, string $content = '', bool $is_preview = false, int $post_id = 0)

At the moment, just the first parameter is used.
I added a method called getTemplateData to the Block class.
It collects all variables that are available to the template and merges them with the user-defined variables from the with() method.

  • $controller
  • $block
  • $is_preview (new)
  • $post_id (new)

It is both used in AbstractBladeBlock and AbstractBlock, so that we don't repeat ourselves.
Additionally, I added a parameter to the with() method so that the above-mentioned variables are available for further usage. Not sure if there is a use case for $content though. As the variables are passed as one array, it could easily be added to that.

I added the abstract with method to both abstract block classes and updated the InitializableInterface. This is a breaking change as the methods signature changes and the parameter needs to be present.

@codepuncher
Copy link
Member

@lukasbesch hey there! Thanks for submitting this PR to resolve my long overdue bug with with causing an error.
Overall, it's looking good.

Before we look to merge this:

  1. Why add $template_data as an argument to with? I don't see it being worthwhile adding this as a parameter (required or not). Also, if $template_data is worthwhile passing to with, why do you need it used with array_merge if it's already available? Seems redundant to me. Let me know if there's something obvious I'm missing there.
  2. There are issues that need resolving, please check composer style:check

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants