SystemListLoader.php in X Autoload 7.5
File
tests/src/VirtualDrupal/SystemListLoader.php
View source
<?php
namespace Drupal\xautoload\Tests\VirtualDrupal;
class SystemListLoader {
private $systemTable;
function __construct(SystemTable $systemTable) {
$this->systemTable = $systemTable;
}
public function fetchBootstrapSystemList() {
$bootstrapList = array();
foreach ($this->systemTable
->systemTableSortedObjects(NULL, 'module') as $name => $record) {
if (1 == $record->status && 1 == $record->bootstrap) {
$bootstrapList[$name] = (object) array(
'name' => $record->name,
'filename' => $record->filename,
);
}
}
return $bootstrapList;
}
public function loadSystemLists() {
$lists = array(
'module_enabled' => array(),
'theme' => array(),
'filepaths' => array(),
);
foreach ($this->systemTable
->systemTableSortedObjects() as $record) {
if ($record->type == 'module') {
if (1 != $record->status) {
continue;
}
$lists['module_enabled'][$record->name] = $record;
}
elseif ($record->type == 'theme') {
$lists['theme'][$record->name] = $record;
}
else {
continue;
}
if ($record->status) {
$lists['filepaths'][] = array(
'type' => $record->type,
'name' => $record->name,
'filepath' => $record->filename,
);
}
}
$this
->themesAddHierarchy($lists['theme']);
return $lists;
}
private function themesAddHierarchy(array $themes) {
foreach ($themes as $key => $theme) {
if (!empty($theme->info['base theme'])) {
$theme->base_themes = $this
->drupalFindBaseThemes($themes, $key);
if (!current($theme->base_themes)) {
continue;
}
$base_key = key($theme->base_themes);
foreach (array_keys($theme->base_themes) as $base_theme) {
$themes[$base_theme]->sub_themes[$key] = $theme->info['name'];
}
$theme->info['engine'] = isset($themes[$base_key]->info['engine']) ? $themes[$base_key]->info['engine'] : 'theme';
}
else {
$base_key = $key;
if (!isset($theme->info['engine'])) {
$theme->info['engine'] = 'theme';
}
}
$theme->prefix = $theme->info['engine'] == 'theme' ? $base_key : $theme->info['engine'];
}
}
private function drupalFindBaseThemes($themes, $key, $used_keys = array()) {
$base_key = $themes[$key]->info['base theme'];
if (!isset($themes[$base_key])) {
return array(
$base_key => NULL,
);
}
$current_base_theme = array(
$base_key => $themes[$base_key]->info['name'],
);
if (isset($themes[$base_key]->info['base theme'])) {
if (isset($themes[$base_key]->base_themes)) {
return $themes[$base_key]->base_themes + $current_base_theme;
}
if (!empty($used_keys[$base_key])) {
return array(
$base_key => NULL,
);
}
$used_keys[$base_key] = TRUE;
return $this
->drupalFindBaseThemes($themes, $base_key, $used_keys) + $current_base_theme;
}
return $current_base_theme;
}
}