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
}) }}