Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • wcms/uw_cfg_common
1 result
Show changes
Commits on Source (30)
Showing
with 512 additions and 37 deletions
langcode: en
status: true
dependencies: { }
id: uw_lbb_tags
block_id: uw_cbl_tags
category: uw_bc_content
label: Tags
image_path: images/layout_builder_browser/tags.svg
image_path_base: 'theme:uw_fdsu_theme_resp'
image_alt: Tags
weight: 0
langcode: en
status: true
dependencies: { }
id: section_background
label: 'Section background'
multiselect: single
form_type: checkboxes
required: false
weight: -10
langcode: en
status: true
dependencies: { }
id: uw_lbs_grp_display_style
label: 'Display style'
multiselect: single
form_type: checkboxes
required: false
weight: 0
......@@ -5,7 +5,7 @@ id: uw_lbs_carousel_1_item
label: 'Carousel - 1 item'
classes: uw-carousel--one-item
type: component
group: default
group: uw_lbs_grp_display_style
weight: -10
block_restrictions:
- 'inline_block:uw_cbl_facts_and_figures'
......
......@@ -5,7 +5,7 @@ id: uw_lbs_carousel_2_items
label: 'Carousel - 2 items'
classes: uw-carousel--two-items
type: component
group: default
group: uw_lbs_grp_display_style
weight: -9
block_restrictions:
- 'inline_block:uw_cbl_facts_and_figures'
......
......@@ -5,7 +5,7 @@ id: uw_lbs_carousel_3_items
label: 'Carousel - 3 items'
classes: uw-carousel--three-items
type: component
group: default
group: uw_lbs_grp_display_style
weight: -8
block_restrictions:
- 'inline_block:uw_cbl_facts_and_figures'
......
......@@ -5,7 +5,7 @@ id: uw_lbs_carousel_4_items
label: 'Carousel - 4 items'
classes: uw-carousel--four-items
type: component
group: default
group: uw_lbs_grp_display_style
weight: -7
block_restrictions:
- 'inline_block:uw_cbl_facts_and_figures'
......
langcode: en
status: true
dependencies: { }
id: uw_lbs_section_background_contained
label: Contained
classes: uw-section__background--contained
type: section
group: section_background
block_restrictions: { }
layout_restrictions: { }
weight: 0
langcode: en
status: true
dependencies: { }
id: uw_lbs_section_background_full_width
label: 'Full width'
classes: uw-section__background--full-width
type: section
group: section_background
block_restrictions: { }
layout_restrictions: { }
weight: 0
<?php
/**
* @file
* Helper functions file.
*/
use Drupal\taxonomy\Entity\Term;
/**
* Function to get the class for the term.
*
* @param \Drupal\taxonomy\Entity\Term $term
* The term object.
*
* @return string
* The class for the term.
*/
function uw_get_org_class_from_term(Term $term): string {
// Get the class name from the term label.
switch ($term->label()) {
case 'Conrad Grebel University College':
$class = 'org-cgc';
break;
case 'Faculty of Arts':
$class = 'org-art';
break;
case 'Faculty of Engineering':
$class = 'org-eng';
break;
case 'Faculty of Environment':
$class = 'org-env';
break;
case 'Faculty of Health':
$class = 'org-ahs';
break;
case 'Faculty of Mathematics':
$class = 'org-mat';
break;
case 'Faculty of Science':
$class = 'org-sci';
break;
case 'Renison University College':
$class = 'org-ren';
break;
case 'St. Jerome’s University':
$class = 'org-stj';
break;
case 'United College':
$class = 'org-stp';
break;
default:
$class = 'org-default';
break;
}
return $class;
}
/**
* Function to get the short faculty term name.
*
* @param string $label
* The current term label.
*
* @return string
* The shorten term label.
*/
function uw_get_short_faculty_tag(string $label): string {
return str_replace('Faculty of ', '', $label);
}
......@@ -8,6 +8,8 @@
{% include '@layouts/layout/layout--1-col/layout--1-col.twig' with {
'classes': classes,
'content': content
'content': content,
'options': uw_section.options,
} %}
......@@ -8,5 +8,6 @@
{% include '@layouts/layout/layout--2-col/layout--2-col.twig' with {
'classes': classes,
'content': content
'content': content,
'options': uw_section.options,
} %}
......@@ -9,4 +9,5 @@
{% include '@layouts/layout/layout--3-col/layout--3-col.twig' with {
'classes': classes,
'content': content,
'options': uw_section.options,
} %}
......@@ -9,4 +9,5 @@
{% include '@layouts/layout/layout--4-col/layout--4-col.twig' with {
'classes': classes,
'content': content,
'options': uw_section.options,
} %}
......@@ -9,4 +9,5 @@
{% include '@layouts/layout/layout--5-col/layout--5-col.twig' with {
'classes': classes,
'content': content,
'options': uw_section.options,
} %}
......@@ -9,4 +9,5 @@
{% include '@layouts/layout/layout--inverted-l-left/layout--inverted-l-left.twig' with {
'classes': classes,
'content': content,
'options': uw_section.options,
} %}
......@@ -9,4 +9,5 @@
{% include '@layouts/layout/layout--inverted-l-right/layout--inverted-l-right.twig' with {
'classes': classes,
'content': content,
'options': uw_section.options,
} %}
......@@ -27,6 +27,8 @@ use Drupal\webform\WebformInterface;
use Drupal\webform\WebformSubmissionStorageInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
include_once 'includes/helper_functions.php';
/**
* Implements hook_preprocess_form_element().
*
......@@ -266,6 +268,189 @@ function uw_cfg_common_form_layout_builder_configure_section_alter(array &$form,
if (!isset($form['layout_builder_style_default']['#default_value'])) {
$form['layout_builder_style_default']['#default_value'] = 'uw_lbs_contained_width';
}
// Layout builder style - background style default and removing
// empty(none) option.
if ($form['layout_builder_style_section_background']['#default_value'] === NULL) {
$form['layout_builder_style_section_background']['#default_value'] = 'uw_lbs_section_background_full_width';
}
unset($form['layout_builder_style_section_background']['#empty_option']);
$config = $form_state->getFormObject()->getLayout()->getConfiguration();
$form['layout_builder_background_type'] = [
'#type' => 'select',
'#title' => t('Background'),
'#options' => [
'none' => t('None'),
'solid_color' => t('Solid colour'),
'image' => t('Image'),
],
'#weight' => 80,
'#default_value' => $config['layout_builder_background_type'] ?? 'none',
];
$form['layout_builder_background_color'] = [
'#type' => 'select',
'#title' => t('Background colour'),
'#options' => [
'neutral' => t('Light grey'),
'org-default' => t('UW Gold'),
'org-default-b' => t('UW Black'),
'org-art' => t('Orange (Arts)'),
'org-eng' => t('Purple (Engineering)'),
'org-env' => t('Green (Environment)'),
'org-ahs' => t('Teal (Health)'),
'org-mat' => t('Pink (Mathematics)'),
'org-sci' => t('Blue (Science)'),
'org-school' => t('Red (school)'),
'org-cgc' => t('Red (Conrad Grebel University College)'),
'org-ren' => t('Green (Renison University College)'),
'org-stj' => t('Green (St. Jerome’s University)'),
'org-stp' => t('Blue (United College)'),
],
'#weight' => 81,
'#default_value' => $config['layout_builder_background_color'] ?? 'neutral',
'#states' => [
'visible' => [
':input[name="layout_builder_background_type"]' => ['value' => 'solid_color'],
],
],
];
$form['layout_builder_background_image'] = [
'#type' => 'media_library',
'#allowed_bundles' => ['uw_mt_image'],
'#title' => t('Background image'),
'#default_value' => $config['layout_builder_background_image'] ?? NULL,
'#description' => t('This image should be at least 1000x400 pixels, and will be proportionally scaled as needed to ensure it covers the entire section. This may mean that the top and bottom or left and right of the image get cut off. Images should not contain text or any other content that would require a description, and must be selected so that text over top can maintain sufficient colour contrast.'),
'#weight' => 82,
'#states' => [
'visible' => [
':input[name="layout_builder_background_type"]' => ['value' => 'image'],
],
],
];
$form['layout_builder_background_image_image_tint'] = [
'#type' => 'select',
'#title' => t('Image tint'),
'#options' => [
'none' => t('None'),
'black' => t('Black (darken)'),
'white' => t('White (lighten)'),
],
'#weight' => 83,
'#default_value' => $config['layout_builder_background_image_image_tint'] ?? 'none',
'#description' => t('For some images, tinting the image darker or lighter can improve the accessibility and readability of the overlaid content.'),
'#states' => [
'visible' => [
':input[name="layout_builder_background_type"]' => ['value' => 'image'],
],
],
];
$form['layout_builder_background_image_text_color'] = [
'#type' => 'select',
'#title' => t('Text colour'),
'#options' => [
'white' => t('White'),
'white-black-shadow' => t('White with black shadow'),
'black' => t('Black'),
'black-white-shadow' => t('Black with white shadow'),
],
'#weight' => 84,
'#default_value' => $config['layout_builder_background_image_text_color'] ?? 'white',
'#description' => t('Make sure to select the option that provides the best contrast from the image underneath.'),
'#states' => [
'visible' => [
':input[name="layout_builder_background_type"]' => ['value' => 'image'],
],
],
];
// Adding #states to layout builder styles created using UI.
$form['layout_builder_style_section_background']['#states'] = [
'visible' => [
':input[name="layout_builder_background_type"]' => ['value' => 'image'],
':input[name="layout_builder_style_default"]' => ['!value' => 'uw_lbs_full_width'],
],
];
$form['#validate'][] = 'uw_cfg_common_validate_section_configuration_validate';
array_unshift($form['#submit'], 'uw_cfg_common_submit_section_configuration_submit');
}
/**
* Validation for section background.
*
* @param array $form
* Form render array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state.
*/
function uw_cfg_common_validate_section_configuration_validate(array &$form, FormStateInterface $form_state) {
$type = $form_state->getValue('layout_builder_background_type');
if ($type === 'image' && empty($form_state->getValue('layout_builder_background_image'))) {
// Get the values from the form state.
$values = $form_state->getValues();
// If this is image, ensure one is selected.
if (
$values['layout_builder_background_type'] === 'image' &&
empty($values['layout_builder_background_image'])
) {
$form_state->setErrorByName(
'layout_builder_background_type',
t('Background image is required!')
);
}
}
}
/**
* Submit handler for section background.
*
* @param array $form
* Form render array.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state object.
*/
function uw_cfg_common_submit_section_configuration_submit(array &$form, FormStateInterface $form_state) {
$layout_builder_background = $form_state->getValues();
$type = $layout_builder_background['layout_builder_background_type'] ?? 'none';
/** @var \Drupal\Core\Layout\LayoutDefault $layout */
$layout = $form_state->getFormObject()->getLayout();
$config = $layout->getConfiguration();
// Reset all previously stored values.
$config['layout_builder_background_type'] = $type;
$config['layout_builder_background_color'] = NULL;
$config['layout_builder_background_image'] = NULL;
$config['layout_builder_background_image_image_tint'] = $layout_builder_background['layout_builder_background_image_image_tint'] ?? 'none';
$config['layout_builder_background_image_text_color'] = $layout_builder_background['layout_builder_background_image_text_color'] ?? 'white';
if ($type !== 'none') {
if ($type === 'solid_color') {
$config['layout_builder_background_color'] = $layout_builder_background['layout_builder_background_color'] ?? 'neutral';
}
elseif ($type === 'image') {
$config['layout_builder_background_image'] = $layout_builder_background['layout_builder_background_image'];
}
}
else {
$config['layout_builder_background_color'] = NULL;
$config['layout_builder_background_image_image_tint'] = NULL;
$config['layout_builder_background_image_text_color'] = NULL;
}
$layout->setConfiguration($config);
}
/**
......@@ -526,6 +711,30 @@ function uw_cfg_common_form_webform_handler_form_alter(array &$form, FormStateIn
// Add help text to 'SEND FROM (WEBSITE/DOMAIN)' in webform email handler.
if ($form['#webform_handler_plugin_id'] === 'email') {
$form['settings']['from']['#description'] = t('This must be an <strong>@uwaterloo.ca</strong> email address for sending to succeed. Please consider using the reply-to email option instead when emails are not limited to campus accounts.');
// To email: remove 'Site email address' option under Other.
array_shift($form['settings']['to']['to_mail']['to_mail']['#options']['Other']);
// From email: remove 'Site email address' option under Other.
array_shift($form['settings']['from']['from_mail']['from_mail']['#options']['Other']);
// CC email: remove 'Site email address' option under Other.
array_shift($form['settings']['to']['cc_mail']['cc_mail']['#options']['Other']);
// BCC email: remove 'Site email address' option under Other.
array_shift($form['settings']['to']['bcc_mail']['bcc_mail']['#options']['Other']);
// Reply-to email: remove 'Site email address' option under Other.
array_shift($form['settings']['reply_to']['reply_to']['reply_to']['#options']['Other']);
// Reply-to email: Set 'Webform author email address' as default.
$form['settings']['reply_to']['reply_to']['reply_to']['#default_value'] = "[webform:author:mail]";
// Return path: remove 'Site email address' option under Other.
array_shift($form['settings']['additional']['return_path']['return_path']['#options']['Other']);
// Sender email: remove 'Site email address' option under Other.
array_shift($form['settings']['additional']['sender_mail']['sender_mail']['#options']['Other']);
}
}
......@@ -1008,6 +1217,11 @@ function uw_cfg_common_form_user_register_form_alter(array &$form, FormStateInte
*/
function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
// Hide hide_branding field in simple sitemap settings.
if ($form_id == 'simple_sitemap_settings_form' && isset($form['settings']['hide_branding'])) {
unset($form['settings']['hide_branding']);
}
// Only blog, event and news item has 'Image' option.
$hero_image_form_ids = [
'node_uw_ct_blog_form',
......@@ -1878,11 +2092,7 @@ function uw_cfg_common_preprocess_html(&$variables): void {
*
* @see options_allowed_values()
*/
function _uw_cfg_common_allowed_media_types(
FieldStorageConfig $definition,
ContentEntityInterface $entity = NULL,
$cacheable
) {
function _uw_cfg_common_allowed_media_types(FieldStorageConfig $definition, ContentEntityInterface $entity = NULL, $cacheable) {
return [
'banner' => 'Banner',
......@@ -1943,11 +2153,137 @@ function uw_cfg_common_field_widget_single_element_link_default_form_alter(array
$element['uri']['#element_validate'][] = '_uw_cfg_common_uw_link_validator';
}
/**
* Link uri field validation function.
*/
function _uw_cfg_common_uw_link_validator($element, &$form_state, $form) {
$uri = $element['#value'];
// Get the field name and set it up in the format used by setErrorByName.
$fieldname = rtrim($element['#name'], ']');
$pos = strpos($fieldname, '[');
$fieldname = substr_replace($fieldname, '][', $pos, 1);
// Buttons are just not allowed.
if ($uri == '<button>') {
$form_state->setErrorByName($fieldname, t('The &lt;button&gt; value is not supported for this field.'));
}
if ($uri == '<nolink>') {
// Don't allow blank link text when <nolink> is used.
if ($fieldname == 'field_uw_event_host][0][uri') {
$link_text = $form_state->getValue('field_uw_event_host')[0]['title'] ?? '';
if ($link_text == '') {
$form_state->setErrorByName('field_uw_event_host][0][title', t('You must provide link text when using &lt;nolink&gt; as the URL.'));
}
}
else {
// Nolink is not allowed, with one exception (event host field).
$form_state->setErrorByName($fieldname, t('The &lt;nolink&gt; value is not supported for this field.'));
}
}
// Prevent adding pilots or staging URLs in link fields.
if (preg_match("/^https?:\/\/(?:pilots|staging)\.uwaterloo\.ca\/?.*/", $uri)) {
$form_state->setErrorByName($fieldname, t('Linking to a staging/pilots site is not allowed as these are temporary sites not intended for public use. For links within a site, please use an internal path.'));
}
}
/**
* Implements template_preprocess_layout.
*/
function uw_cfg_common_preprocess_layout(&$variables) {
// Get the settings from the content.
$settings = $variables['content']['#settings'] ?? NULL;
// If there are settings, then process them to get out
// the options for the section.
if (
$settings &&
isset($settings['layout_builder_background_type']) &&
$settings['layout_builder_background_type'] !== 'none'
) {
// Get the background type from the settings.
$type = $settings['layout_builder_background_type'];
// If the type is a solid color and the color is set,
// then add a class to the variables.
if (
$type === 'solid_color' &&
$color = $settings['layout_builder_background_color']
) {
// Add the class to the variables.
$variables['attributes']['class'][] = 'uw-section__background--' . $color;
// If there are classes on the section, remove the ones
// that are put in by default for background image and
// solid color.
if (isset($variables['attributes']['class'])) {
$variables['attributes']['class'] = _uw_cfg_common_remove_extra_classes($variables['attributes']['class']);
}
}
// If the background type is an image, get the image and
// add the sources to the variables.
elseif ($type === 'image') {
// Get the mid from the settings.
$media_id = $settings['layout_builder_background_image'];
// If there is a media id, then get the sources for the
// picture element and to the variables.
if ($media_id) {
// The UW service.
/** @var \Drupal\uw_cfg_common\Service\UWServiceInterface $uw_service */
$uw_service = \Drupal::service('uw_cfg_common.uw_service');
// Load the media entity.
$media_entity = \Drupal::service('entity_type.manager')->getStorage('media')->load($media_id);
// Set the sources for the picture element to the variables.
$variables['uw_section']['options']['image'] = $uw_service->prepareResponsiveImage($media_entity, 'uw_ris_media');
// Fix the issue with portrait crops in the section background image,
// by removing the portrait cut.
foreach ($variables['uw_section']['options']['image']['sources'] as $index => $source) {
if ($source->toArray()['media'] == 'all and (min-width: 1em)') {
unset($variables['uw_section']['options']['image']['sources'][$index]);
}
}
// Add the class to the section.
$variables['attributes']['class'][] = 'uw-section__background-image';
}
// Add the image tint to the variables.
$variables['uw_section']['options']['image_tint'] = $settings['layout_builder_background_image_image_tint'] ?? 'none';
// Add the image tint.
$tint_color_class = 'uw-section__tint-color--' . $variables['uw_section']['options']['image_tint'];
$variables['attributes']['class'][] = $tint_color_class;
// Add the image text color to the variables.
$variables['uw_section']['options']['image_color'] = $settings['layout_builder_background_image_text_color'] ?? 'white';
// Add the text color.
$text_color_class = 'uw-section__text-color--' . $variables['uw_section']['options']['image_color'];
$variables['attributes']['class'][] = $text_color_class;
}
}
else {
// If there are classes on the section, remove the ones
// that are put in by default for background image and
// solid color.
if (isset($variables['attributes']['class'])) {
$variables['attributes']['class'] = _uw_cfg_common_remove_extra_classes($variables['attributes']['class']);
}
}
// Classes to check for.
$classes['uw-section-spacing'] = 'uw-section-spacing--default';
$classes['uw-section-separator'] = 'uw-section-separator--none';
......@@ -1975,42 +2311,38 @@ function uw_cfg_common_preprocess_layout(&$variables) {
$variables['attributes']['class'][] = $class;
}
}
}
/**
* Link uri field validation function.
* Function to remove extra classes.
*
* @param array $classes
* Array of classes.
*
* @return array
* Array of classes with removals
*/
function _uw_cfg_common_uw_link_validator($element, &$form_state, $form) {
$uri = $element['#value'];
function _uw_cfg_common_remove_extra_classes(array $classes): array {
// Get the field name and set it up in the format used by setErrorByName.
$fieldname = rtrim($element['#name'], ']');
$pos = strpos($fieldname, '[');
$fieldname = substr_replace($fieldname, '][', $pos, 1);
// The classes to be removed.
$classes_to_remove = [
'uw-section__background--contained',
'uw-section__background--full-width',
];
// Buttons are just not allowed.
if ($uri == '<button>') {
$form_state->setErrorByName($fieldname, t('The &lt;button&gt; value is not supported for this field.'));
}
// Step through each of the classes and remove
// the extra classes that are not required.
foreach ($classes as $index => $value) {
if ($uri == '<nolink>') {
// Don't allow blank link text when <nolink> is used.
if ($fieldname == 'field_uw_event_host][0][uri') {
$link_text = $form_state->getValue('field_uw_event_host')[0]['title'] ?? '';
if ($link_text == '') {
$form_state->setErrorByName('field_uw_event_host][0][title', t('You must provide link text when using &lt;nolink&gt; as the URL.'));
}
}
else {
// Nolink is not allowed, with one exception (event host field).
$form_state->setErrorByName($fieldname, t('The &lt;nolink&gt; value is not supported for this field.'));
// If class is in the classes to remove array,
// remove it from the classes array.
if (in_array($value, $classes_to_remove)) {
unset($classes[$index]);
}
}
// Prevent adding pilots or staging URLs in link fields.
if (preg_match("/^https?:\/\/(?:pilots|staging)\.uwaterloo\.ca\/?.*/", $uri)) {
$form_state->setErrorByName($fieldname, t('Linking to a staging/pilots site is not allowed as these are temporary sites not intended for public use. For links within a site, please use an internal path.'));
}
return $classes;
}
/**
......