Skip to content

Add service attribute to page definition - a proposal#3840

Draft
kulturbande wants to merge 6 commits intoAlchemyCMS:mainfrom
kulturbande:add-page-service
Draft

Add service attribute to page definition - a proposal#3840
kulturbande wants to merge 6 commits intoAlchemyCMS:mainfrom
kulturbande:add-page-service

Conversation

@kulturbande
Copy link
Copy Markdown
Contributor

@kulturbande kulturbande commented Apr 19, 2026

What is this pull request for?

This PR introduces a page service concept. It is is possible to declare a service class in the page_layout.yml. The service runs during page loading (both frontend and admin preview) to prepare custom data or guard access.

This change goes hand in hand with PR #3776. In combination it would be possible to process the wildcard_url parameter in the service and load the part that was requested.

Screenshots

Page Layout:
Aufnahme 2026-04-19 at 19 08 53@2x

Service:
Aufnahme 2026-04-19 at 19 09 30@2x

View:
Aufnahme 2026-04-19 at 19 08 43@2x

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@kulturbande kulturbande requested a review from a team as a code owner April 19, 2026 17:14
@kulturbande kulturbande marked this pull request as draft April 19, 2026 17:14
@kulturbande kulturbande changed the title Allow page service - a proposal Add service attribute to page definition - a proposal Apr 19, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.06%. Comparing base (5db26ef) to head (2fa0dd8).

Files with missing lines Patch % Lines
app/services/alchemy/base_page_service.rb 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3840      +/-   ##
==========================================
- Coverage   98.06%   98.06%   -0.01%     
==========================================
  Files         322      324       +2     
  Lines        8530     8561      +31     
==========================================
+ Hits         8365     8395      +30     
- Misses        165      166       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add an abstract page service and a corresponding page_layout. The service is used to make the initialization of page services easier and less error prone.
the page service can be used to initialize and call a service. This type is validating that the service exists and that it inherit from BasePageService.
The service can be any class that is callable and that is inheriting the service structure of Alchemy::BasePageService.
It is only syntactic sugar, but it read later nicer in the controllers.
Create a @service variable that is containing the initialized services. After that the service will be called. The service can fire an Alchemy::PageNotFound error that is interesting the current user is not allowed to see the page. The service also gets the parameters that maybe contain also wildcard_url parameter.
The same behavior as before, except that this controller does not rescue the Alchemy::PageNotFound error. Instead the service will be initialized with the preview_mode flag, which is interesting to populate other data in the preview window.
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