Code Guide 2018/10/16
JCH Distribution Page
Introduction
Some Hitachi websites may require an alternate domain name, which will show a page with a distributors grid to choose from. This feature has been integrated in the general CMS.
Features
This feature will be only available for authorized websites, and it will be activated or deactivated only at server level (not via CMS).
- Activation is done via the DISTRIBUTION_PAGE_FEATURE_ACTIVE parameter (inside the .env file located in the website root folder, usually httpdocs).
- Integrated with the CMS, thus sharing the DB and the backend.
- The user will be able to create or modify a page.
- The user will not be able to directly publish a page.
- The user will be able to preview the page and send a publishing request to an established authorizer email (see parameter DISTRIBUTION_PAGE_AUTH_MAILTO in .env file).
- This page’s frontend will be accessible only from an alternate domain name (DISTRIBUTION_PAGE_DOMAIN in .env file).
- All texts are configurable in the main language (not in multi-language).
- The home page will admit 2 to 6 elements, including: image, text, link, and a hidden title for the alt-image html field.
- Contact form.
- Optional menu item.
- Editable SEO data and Google Analytics tracking code.
Resources
Database
The migrations create_landing_table and create_landing_contact create and seed the necessary tables to manage this feature. To keep this functionality isolated from the general CMS, none of the existing PagesController logic (see the general code guide) has been reused. All fields are stored in, and only in, the tables landings, landing_links, and landing_contacts.
Project files
- Frontend: custom blade views and layouts have been used.
- Frontend: separate stylesheets and JS have been used (webpack.mix.js).
- Backend: custom backpack component has been created to show the current authorization and publishing status, preview button, and request button (button_landing_auth_request.blade.php).
- Backend: the class defined in LandingRequestAuthNotification.php is responsible for sending the email with the request to publish.
- Front and backend: usual files under Controllers and Controllers/Admin.
Other resources
- CME administrative texts are stored in /resources/lang/en/admin_distpage. These texts are editable only by developers. They include, among others, the text of the authorization email.
- Non-sensitive texts are stored in /resources/defaults/texts.php and they are accessible via the CMS-Texts menu, under the categories section_dist_* . These texts will be editable with no effect over the page publishing status. These texts can be translated to multiple languages, although this feature was not requested. The reason is that they use the CMS translatable feature included in this section (CMS-Texts).
- Any other text is stored in the DB tables. Any modification to these texts will require a new publishing request submission and will be published after approval.
Authorization and preview logic
When a user submits a request to publish a page a unique token is generated. This token is
encrypted and stored into the DB. The authorizer will receive an email with a link
including this token. The link will lead to a preview page with the buttons Publish
and Reject. This preview page passes through the CMS to ensure the user is
authenticated, even if they have the correct token.
See the model class Landing.php to view the specific authorization process as well as
the publishing cases and logic. Also, web.php and admin.php
contain important information about routes definitions.
Server configuration
.env file located in the root public web folder will include these
parameters:
DISTRIBUTION_PAGE_FEATURE_ACTIVE=true
DISTRIBUTION_PAGE_AUTH_MAILTO=mailto@authorizer.example
DISTRIBUTION_PAGE_DOMAIN=distribution.domain.example
DISTRIBUTION_PAGE_TITLE=”JCH Distribution Page”
The
DISTRIBUTION_PAGE_DOMAIN parameter must not
include the http protocol (http:// or https://).
The DISTRIBUTION_PAGE_TITLE
contains the page title to be shown in emails.
The distribution domain name has
to be configured at server level as a domain alias pointing to the same IP than the main
domain. This feature has been tested with domains inside the same server (DNS from main.domain
and distribution.domain are the same). Tests with different DNS have not been
performed.