annotate themes/contrib/mayo/inc/get.inc @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents 5311817fb629
children
rev   line source
Chris@2 1 <?php
Chris@2 2
Chris@2 3 /**
Chris@2 4 * @file
Chris@2 5 * Provides frequently used functions that get theme info, settings and
Chris@2 6 * other data.
Chris@2 7 */
Chris@2 8
Chris@2 9 /**
Chris@2 10 * Return the info file array for a particular theme, usually the active theme.
Chris@2 11 * Simple wrapper function for list_themes().
Chris@2 12 *
Chris@2 13 * @param $theme_name
Chris@2 14 */
Chris@2 15 function mayo_get_info($theme_name) {
Chris@2 16 $info = &drupal_static(__FUNCTION__, array());
Chris@2 17 if (empty($info)) {
Chris@2 18 $lt = list_themes();
Chris@2 19 foreach ($lt as $key => $value) {
Chris@2 20 if ($theme_name == $key) {
Chris@2 21 $info = $lt[$theme_name]->info;
Chris@2 22 }
Chris@2 23 }
Chris@2 24 }
Chris@2 25
Chris@2 26 return $info;
Chris@2 27 }
Chris@2 28
Chris@2 29 /**
Chris@2 30 * Returns an array keyed by theme name.
Chris@2 31 *
Chris@2 32 * Return all the info file data for a particular theme including base
Chris@2 33 * themes.
Chris@2 34 *
Chris@2 35 * @param $theme_name, usually the active theme.
Chris@2 36 */
Chris@2 37 function mayo_get_info_trail($theme_name) {
Chris@2 38 $info_trail = &drupal_static(__FUNCTION__, array());
Chris@2 39 if (empty($info_trail)) {
Chris@2 40 $theme_handler = \Drupal::service('theme_handler');
Chris@2 41 $lt = $theme_handler->listInfo(); // Get a list of available themes.
Chris@2 42 // First check for base themes and get info
Chris@2 43 $base_theme = array();
Chris@2 44 $ancestor = $theme_name;
Chris@2 45 while ($ancestor && isset($lt[$ancestor]->base_theme)) {
Chris@2 46 $ancestor = $lt[$ancestor]->base_theme;
Chris@2 47 $base_theme[] = $lt[$ancestor];
Chris@2 48 }
Chris@2 49 foreach ($base_theme as $base) {
Chris@2 50 $info_trail[$base->getName()]['info'] = $base->info;
Chris@2 51 }
Chris@2 52
Chris@2 53 // Now the active theme
Chris@2 54 $info_trail[$theme_name]['info'] = $lt[$theme_name]->info;
Chris@2 55 }
Chris@2 56 return $info_trail;
Chris@2 57 }