[beta6] Move header & footer preprocess to page template

Created on 4 February 2024, 11 months ago
Updated 21 February 2024, 10 months ago

Problem/Motivation

Preprocess hooks targeting components must be avoided for 2 reasons:

  • They are PHP function and are not expected to be written by the front developer, so they reduce the ownership of the design system maintainer
  • They are forbidden in SDC & UI Patterns 2

We have 5 of them remaining, and 3 can be replaced by preprocesses targeting the present templates which is calling the component.

Proposal: Header

This hook targets a component:

function ui_suite_dsfr_preprocess_pattern_header(array &$variables) {
  if (empty($variables['service_title'])) {
    $variables['service_title'] = \Drupal::config('system.site')->get('name');
  }
  if (empty($variables['service_tagline'])) {
    $variables['service_tagline'] = \Drupal::config('system.site')->get('slogan');
  }
}

But it can target page.html.twig instead:

  {{ pattern('header', {
    'logo_text': page.logo,
    'operator_logo': page.header_operator_logo,
    'service_title': site_name,
    'service_tagline': site_slogan,
    'tools_links': page.header_tools_links,
    'tools_search': page.header_tools_search,
    'navbar': page.header_navbar,
  }) }}

Proposal: Footer

This hook targets a component:

function ui_suite_dsfr_preprocess_pattern_footer(array &$variables) {
  if (empty($variables['service_title'])) {
    $variables['service_title'] = \Drupal::config('system.site')->get('name');
  }
}

But it can target page.html.twig instead:

  {{ pattern('footer', {
    'top': page.footer_top,
    'operator_logo': page.footer_operator_logo,
    'content': page.footer_content,
    'content_desc': page.footer_content_desc,
    'partners': page.footer_partners,
    'bottom': page.footer_bottom,
    'bottom_copy': page.footer_bottom_copy,
    'service_title': site_name
  }) }}
📌 Task
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024