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

Conditional alert banner placement #142

Merged
merged 20 commits into from
Jun 9, 2021

Conversation

stephen-cox
Copy link
Member

Closes #137

@stephen-cox stephen-cox marked this pull request as draft May 21, 2021 15:33
@stephen-cox stephen-cox marked this pull request as ready for review June 2, 2021 15:35
@stephen-cox
Copy link
Member Author

This is now ready to be reviewed.

@andybroomfield
Copy link
Contributor

andybroomfield commented Jun 3, 2021

I've checked out this update.
The condition field is added to the alert banner and the upgrade works with the current alert banners.

A couple of questions:
This visibility condition field is only added to the primary localgov_alert_banner type. I had another alert banner type created and that did not get the visibility condition added. I think we should try to get it added to all existing banner types as its kind of an expected feature, and to get this to work you have to add the specific visibility field.

Also it is showing the content type and user role contexts, are we planning on restricting the plugins initially in use?
(This is on upgrading the install)

@willguv
Copy link
Member

willguv commented Jun 3, 2021

@andybroomfield agree that the conditionality ought to work out of the box for all banner types

On the alerts work, @stephen-cox hid/ removed content type and user role controls so could you do the same here?

Thanks both

@andybroomfield
Copy link
Contributor

andybroomfield commented Jun 3, 2021

I think it is hidden in the config so a fresh install won't show them, this was testing an upgrade with existing alert banners.

@stephen-cox
Copy link
Member Author

@andybroomfield I have updated the code so the visibility field should be added to all existing alert banner bundles.

Only the pages visibility plugin should be added to existing alert banners. Can you check whether the condition_field module was patched with the latest patch from here: https://www.drupal.org/project/condition_field/issues/3215202?

If the patch is not installed then the condition field doesn't work properly with the provided configuration.

@andybroomfield
Copy link
Contributor

andybroomfield commented Jun 4, 2021

@stephen-cox Ok thanks. I've applied the patch and re-run the update. This is working as expected with adding the condition field to all alert banner types and only the page plugin is enabled by default.
It would be good to increase the weight so its the last element in the form. I had a test field that was displaying below it when added.

One bug I have encounterd. When logged in as admin and setting up a page restriction, the banner only displays once on the restricted page. Then visit a page where it should not show and go the the page it shold show. Refreshing that page and the banner goes away. This is only logged in users (presume cache for anon).

I think this could be cache issue as then flushing cache brings it back. So the route of the page needs to be a cache context for the banner or the block?

Copy link
Contributor

@andybroomfield andybroomfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, this is broken with cache. Disbling the cache backends and it works as expected. With caches enabled, going to a page with a restricted banner, then going to a page without a banner, and then revisiting a page where there should be a banner, the banner will not be present. Flush cache then makes it appear (and appears on all pages).

…ew() hook and into the AlertBannerEntity and AlertBannerBlock clases
@stephen-cox
Copy link
Member Author

@andybroomfield The latest changes should fix the caching issues. They represent quite an overhaul of how the visibility conditions are evaluated, along with changes to the alert banner block.

Are alert banners only currently displayed to end users through the alter banner block? If so then the changes should be fine. If there are other ways of displaying them they will need to be updated to use the isVisible() method on an AlertBannerEntity to check the alert banner is okay to display.

@andybroomfield
Copy link
Contributor

Thanks @stephen-cox will look.

Yes at present it is just the block for end users.
There are places where people can view the entity if they are a an editor to preview. Assume this won't effect that.

I think it is safe to document that if someone is using them outside a block, it is on them to check the isVisible() condition. The main use case I can think of is if someone built a view instead, so maybe a views filter plugin in the future.

Copy link
Contributor

@andybroomfield andybroomfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have just checked this and it works with cache on.
Happy for this to go forward for release.

As new feature, this is a v1.1.0?

@stephen-cox stephen-cox merged commit 2b829cf into 1.x Jun 9, 2021
@stephen-cox stephen-cox deleted the feature/137-conditional-placement branch June 9, 2021 13:55
@stephen-cox
Copy link
Member Author

Thanks @andybroomfield. Merged. I'll create a PR for the new release.

@stephen-cox stephen-cox mentioned this pull request Jun 9, 2021
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.

Publish alert banners on selected sections of the site
3 participants