Skip to content

Make banner layouts and their positions filterable - #31

Merged
davidperezgar merged 1 commit into
mainfrom
feature/layout-filters
Nov 25, 2026
Merged

davidperezgar merged 1 commit into
mainfrom
feature/layout-filters

Conversation

@davidperezgar

Copy link
Copy Markdown
Contributor

Summary

FrontConsent PRO needs to add a Compact banner to the existing Layout setting (closemarketing/frontconsent-pro#11). That select was hard-coded to bar/box/popup, so this PR makes it filterable.

  • CookieNotice::get_layouts() → filter frcn_cookie_notice_layouts (slug => label).
  • CookieNotice::get_layout_positions() → filter frcn_cookie_notice_layout_positions (layout => position slug => label). The first position is the default. A layout with no entry has no Position field.
  • The Settings tab renders both selects from these lists. sanitize_settings() checks the layout against get_layouts() and the position against the selected layout's positions.
  • settings.js rebuilds the Position options when the layout changes. The preview shows an add-on layout as the bar.
  • No frontend change. An unknown layout is still rendered as the bar, so an add-on layout falls back to a working banner if the add-on is disabled.

Test plan

  • New tests/Unit/CookieNoticeLayoutsTest.php: built-in lists, a filtered layout is saved, an unregistered layout falls back to bar, unsupported positions fall back to the layout's first position, and a non-array filter result is ignored.
  • composer lint, composer phpstan, composer test (138 tests) pass.
  • Manual check together with frontconsent-pro#11 (Compact layout).

The Layout select was hard-coded to bar/box/popup, so an add-on could not
offer its own banner presentation there. Add
CookieNotice::get_layouts() (frcn_cookie_notice_layouts) and
CookieNotice::get_layout_positions() (frcn_cookie_notice_layout_positions)
and use them to render the Layout and Position selects and to sanitize the
saved values. Positions are validated against the selected layout. The
settings script rebuilds the Position options when the layout changes, and
the preview shows an add-on layout as the bar.

The frontend keeps rendering an unknown layout as the bar, so an add-on
layout still has a usable fallback banner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T11:55:51.457595Z 67171ea PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 67171ea8a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


$sanitized['cookie_notice_position'] = is_string( $value['cookie_notice_position'] ) && isset( $allowed_positions[ $value['cookie_notice_position'] ] )
? $value['cookie_notice_position']
: (string) array_key_first( $allowed_positions );

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace the PHP 7.3-only array_key_first call

On supported PHP 7.0–7.2 installations, saving settings for a layout with a submitted Position field (such as box) reaches this branch and fatals because array_key_first() was introduced in PHP 7.3. Use a PHP 7.0-compatible way to obtain the first allowed position so these users can save the settings page.

AGENTS.md reference: AGENTS.md:L11-L12

Useful? React with 👍 / 👎.

@davidperezgar
davidperezgar merged commit 1767b10 into main Nov 25, 2026
7 checks passed
@davidperezgar
davidperezgar deleted the feature/layout-filters branch November 25, 2026 12:01
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.

1 participant