Skip to content
Snippets Groups Projects
Commit c388a95a authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-4199: coding standards

parent 033527dd
No related branches found
No related tags found
1 merge request!7Feature/istwcms 4199 ebremner menu items count
...@@ -53,41 +53,6 @@ function uw_fdsu_theme_resp_preprocess_responsive_image(&$variables) { ...@@ -53,41 +53,6 @@ function uw_fdsu_theme_resp_preprocess_responsive_image(&$variables) {
$variables['sources'] = $new_sources; $variables['sources'] = $new_sources;
} }
/**
* A recursive function to count the number of menu items.
*
* @param $menus
* The array list of menu items.
* @param $menu_items_count
* The reference to the number of items variable.
*/
function _uw_fdsu_theme_resp_count_menu_items($menus, &$menu_items_count) {
// Step through each of the menus.
foreach ($menus as $menu) {
// If there is a submenu, then recursively go down through the list,
// until we get to place that doesnt have a submenu and we will
// increment the menu items count.
if (isset($menu['submenu']) && count($menu['submenu'] > 0)) {
// Step through each of the submenus and send back to this function.
foreach ($menu['submenus'] as $submenu) {
// Keep calling this function until we have no submenus.
_uw_fdsu_theme_resp_count_menu_items($submenu, $menu_items_count);
}
}
// Here we have no submenus, so increment the menu items counter.
else {
// Increment the menu items counter.
$menu_items_count++;
}
}
}
/** /**
* Implements hook_preprocess_region(). * Implements hook_preprocess_region().
*/ */
...@@ -119,7 +84,7 @@ function uw_fdsu_theme_resp_preprocess_region(&$variables) { ...@@ -119,7 +84,7 @@ function uw_fdsu_theme_resp_preprocess_region(&$variables) {
} }
/** /**
* Implements hook_FORM_ID_alter. * Implements hook_FORM_ID_alter().
* *
* Add settings for colour scheme. * Add settings for colour scheme.
*/ */
...@@ -179,7 +144,7 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field) ...@@ -179,7 +144,7 @@ function _uw_fdsu_theme_resp_get_field_value_from_paragraph($paragraph, $field)
* *
* @param array $variables * @param array $variables
* The variables array. * The variables array.
* @param object $field * @param \Drupal\image\Plugin\Field\FieldType\ImageItem $field
* The field object. * The field object.
* @param string $responsive_image_style * @param string $responsive_image_style
* The ID of the responsive image style. * The ID of the responsive image style.
...@@ -226,7 +191,7 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(array &$variables, I ...@@ -226,7 +191,7 @@ function _uw_fdsu_theme_resp_add_responsive_image_variables(array &$variables, I
/** /**
* Get image properties from an image field. * Get image properties from an image field.
* *
* @param object $field * @param \Drupal\file\Plugin\Field\FieldType\FileFieldItemList $field
* The image field. * The image field.
* *
* @return array|null * @return array|null
...@@ -256,37 +221,51 @@ function _uw_fdsu_theme_resp_get_image_info(FileFieldItemList $field) { ...@@ -256,37 +221,51 @@ function _uw_fdsu_theme_resp_get_image_info(FileFieldItemList $field) {
*/ */
function uw_fdsu_theme_resp_preprocess_block(&$variables) { function uw_fdsu_theme_resp_preprocess_block(&$variables) {
// If we are in layout builder (this is set much earlier in the page load process), // If we are in layout builder (this is set much earlier in
// then continue to look if we need to add the admin_label and css classes. // the page load process), then continue to look if we need
// to add the admin_label and css classes.
if (isset($variables['in_layout_builder']) && $variables['in_layout_builder'] == TRUE) { if (isset($variables['in_layout_builder']) && $variables['in_layout_builder'] == TRUE) {
// Get the block manager object. // Get the block manager object.
$blockManager = \Drupal::service('plugin.manager.block'); $blockManager = \Drupal::service('plugin.manager.block');
// Get the plugin definitions for the block, using the plugin_id of the block. // Get the plugin definitions for the block, using the
// plugin_id of the block.
$plugin_definitions = $blockManager->getDefinition($variables['plugin_id']); $plugin_definitions = $blockManager->getDefinition($variables['plugin_id']);
// The admin labels to exclude, these are ones that we do not want the admin label // The admin labels to exclude, these are ones that we do not
// to appear on the layout builder page. // want the admin label to appear on the layout builder page.
$admin_labels_to_exclude = ['Messages', 'Tabs', 'Page title', 'Global header', 'Main navigation', "Site footer block"]; $admin_labels_to_exclude = [
'Messages',
'Tabs',
'Page title',
'Global header',
'Main navigation',
'Site footer block',
];
// Check if the admin_label is an object, we need to do this because some admin labels // Check if the admin_label is an object, we need to do this
// are translatable and are therefore translatable markup objects (usually through code way of // because some admin labels are translatable and are therefore
// building blocks. Others are not, if translations are not turned on for this block (usually through // translatable markup objects (usually through code way of
// the GUI way of creating a block, where the translation option is not set). // building blocks. Others are not, if translations are not turned
// on for this block (usually through the GUI way of creating a block,
// where the translation option is not set).
if (is_object($plugin_definitions['admin_label'])) { if (is_object($plugin_definitions['admin_label'])) {
// The admin label is a translatable markup, so just render the object to set the admin label variable.. // The admin label is a translatable markup, so just render
// the object to set the admin label variable..
$admin_label = $plugin_definitions['admin_label']->render(); $admin_label = $plugin_definitions['admin_label']->render();
} }
else { else {
// The admin label is not an object so just set the admin label variable. // The admin label is not an object so just set the
// admin label variable.
$admin_label = $plugin_definitions['admin_label']; $admin_label = $plugin_definitions['admin_label'];
} }
// If the admin label is not in the ones to exclude add it to the template variables and // If the admin label is not in the ones to exclude add it
// set the class to be used to display the admin label. // to the template variables and set the class to be used
// to display the admin label.
if (!in_array($admin_label, $admin_labels_to_exclude)) { if (!in_array($admin_label, $admin_labels_to_exclude)) {
$variables['admin_label'] = $admin_label; $variables['admin_label'] = $admin_label;
$variables['attributes']['class'][] = 'in-layout-builder'; $variables['attributes']['class'][] = 'in-layout-builder';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment