Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add on_block_before_render event #6575

Merged
merged 2 commits into from Apr 11, 2018

Conversation

a3020
Copy link
Contributor

@a3020 a3020 commented Apr 9, 2018

This will trigger an event when the block is about to be rendered*. Hooking into this event makes it possible to prevent it from displaying.

Example code to prevent displaying

Events::addListener('on_block_before_render', function ($event) {
    $event->preventRendering();

    return $event;
});

Output

afbeelding


*) for naming convention see also #6574

@aembler
Copy link
Member

aembler commented Apr 9, 2018

Can you provide a use case where this would be helpful? I'm worried about potential performance impacts.

@a3020
Copy link
Contributor Author

a3020 commented Apr 9, 2018

I'm trying to develop an add-on that'd make it possible to only render / output a block if certain conditions are met. I try to come up with a solution that doesn't involve changing all the block controllers.

If you have suggestions for the current PR or the above problem, please let me know.

@a3020
Copy link
Contributor Author

a3020 commented Apr 10, 2018

This were the execution costs for me to run the anonymous function per block:

rendering-times

I've used an anonymous function to prevent collisioning of variables with the extract function.

@a3020 a3020 force-pushed the add_on_block_before_render_event branch from 2c67bdd to c150482 Compare April 11, 2018 07:55
An anonymous function is used to prevent
collision of variables with the 'extract' function.
@a3020 a3020 force-pushed the add_on_block_before_render_event branch from 2ac7df2 to 6fd9c29 Compare April 11, 2018 20:27
@aembler aembler merged commit 5fb6717 into concretecms:develop Apr 11, 2018
@a3020 a3020 deleted the add_on_block_before_render_event branch April 11, 2018 20:54
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.

None yet

2 participants