signalpoint / DrupalGap

An application development kit for Drupal websites.
https://www.drupalgap.org
GNU General Public License v2.0
232 stars 185 forks source link

Access callback before rendering the element #1013

Open majuril opened 6 years ago

majuril commented 6 years ago

I have a custom access callback function based on the user's permissions. Everything is basically working and user can't see the content inside the element if there are no sufficient permissions... Although the block container is still rendered.

So for example if my footer region doesn't contain anything else than this custom block (with custom permissions), the footer region is still rendered even though there is nothing inside it. I ran in to this same issue with the popup-menus, icon is still rendered even though user can't open the popup-menu.

Is there a way to handle the access callback before DG renders anything on screen?

signalpoint commented 6 years ago

@majuril I think the way regions is rendered in DrupalGap core would need to be updated to be a little more intelligent. As you suggested, if there are no blocks to be rendered in that region, then the region shouldn't be rendered at all.

The code that powers the rendering of the regions starts around here: https://github.com/signalpoint/DrupalGap/blob/7.x-1.x/src/includes/region.inc.js#L31

The workaround (without having to improve/hack DG core) would probably be to attach a pageshow handler to your page(s), and in that handler make a decision about whether or not you'd like to remove that region.

majuril commented 6 years ago

Cheers! Good to know I wasn't doing anything "wrong", that caused this issue.

For this case I actually decided to solve it with some CSS. By default the footer is now transparent and when something is printed on it, it'll be printed inside ".footer-container" which is set to have width: 100% and other required CSS.