views_system.module in Views System 8
Same filename and directory in other branches
Extends the Views module and provides fields, filter criteria, and sort criteria for Modules/Themes/Theme engines.
File
views_system.moduleView source
<?php
/**
* @file
* Extends the Views module and provides fields, filter criteria, and sort
* criteria for Modules/Themes/Theme engines.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function views_system_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.views_system':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Views System module extends the Views module and provides fields, filter criteria, and sort criteria for <em>Modules/Themes/Theme engines</em>. For more information, see the online handbook entry for <a href=":views_system">Views System module</a>.', array(
':views_system' => 'https://www.drupal.org/project/views_system',
)) . '</p>';
return $output;
}
}
/**
* Implements hook_cache_flush().
*/
function views_system_cache_flush() {
views_system_rebuild_module_data();
views_system_rebuild_theme_data();
}
/**
* Implements hook_modules_installed().
*/
function views_system_modules_installed($modules) {
views_system_rebuild_module_data();
views_system_rebuild_theme_data();
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function views_system_form_system_modules_alter(&$form, FormStateInterface $form_state, $form_id) {
views_system_rebuild_module_data();
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function views_system_form_system_themes_admin_form_alter(&$form, FormStateInterface $form_state, $form_id) {
views_system_rebuild_theme_data();
}
/**
* Helper function to rebuild module's data.
*/
function views_system_rebuild_module_data() {
db_query("DELETE FROM {views_system} WHERE type = 'module' OR type = 'profile'");
$modules = system_rebuild_module_data();
foreach ($modules as $module) {
$data = array();
$data['filename'] = $module
->getFilename();
$data['core'] = $module->info['core'];
$data['datestamp'] = !empty($module->info['datestamp']) ? (int) $module->info['datestamp'] : NULL;
$data['dependencies'] = !empty($module->info['dependencies']) ? serialize($module->info['dependencies']) : '';
$data['description'] = !empty($module->info['description']) ? $module->info['description'] : '';
$data['info'] = serialize($module->info);
$data['label'] = $module->info['name'];
$data['mtime'] = $module->info['mtime'];
$data['name'] = $module
->getName();
$data['origin'] = preg_match('/^core\\/(modules|profiles)\\//i', $module
->getPathname()) ? 'core' : 'extension';
$data['package'] = !empty($module->info['package']) ? $module->info['package'] : '';
$data['pathname'] = $module
->getPathname();
$data['php'] = !empty($module->info['php']) ? $module->info['php'] : '';
$data['project'] = !empty($module->info['project']) ? $module->info['project'] : '';
$data['project_status_url'] = !empty($module->info['project_status_url']) ? $module->info['project_status_url'] : '';
$data['required'] = !empty($module->info['required']) ? (int) $module->info['required'] : 0;
$data['required_by'] = !empty($module->required_by) ? serialize($module->required_by) : '';
$data['requires'] = !empty($module->requires) ? serialize($module->requires) : '';
$data['schema_version'] = $module->schema_version;
$data['status'] = $module->status;
$data['type'] = $module
->getType();
$data['version'] = !empty($module->info['version']) ? $module->info['version'] : '';
$data['visible'] = !empty($module->info['hidden']) ? (int) (!$module->info['hidden']) : 1;
$data['weight'] = $module->weight;
db_insert('views_system')
->fields($data)
->execute();
}
}
/**
* Helper function to rebuild theme's data.
*/
function views_system_rebuild_theme_data() {
db_query("DELETE FROM {views_system} WHERE type = 'theme' OR type = 'theme_engine'");
$theme_default = Drupal::config('system.theme')
->get('default');
$theme_admin = Drupal::config('system.theme')
->get('admin');
$themes = \Drupal::service('theme_handler')
->rebuildThemeData();
foreach ($themes as $theme) {
$theme->is_default = $theme
->getName() == $theme_default;
$theme->is_admin = $theme
->getName() == $theme_admin || $theme->is_default && $theme_admin == '0';
$data = array();
$data['filename'] = $theme
->getFilename();
$data['admin_theme'] = (int) $theme->is_admin;
$data['base_theme'] = !empty($theme->info['base theme']) ? $theme->info['base theme'] : '';
$data['core'] = $theme->info['core'];
$data['datestamp'] = !empty($theme->info['datestamp']) ? (int) $theme->info['datestamp'] : NULL;
$data['default_theme'] = (int) $theme->is_default;
$data['description'] = !empty($theme->info['description']) ? $theme->info['description'] : '';
$data['engine'] = !empty($theme->info['engine']) ? $theme->info['engine'] : '';
$data['features'] = !empty($theme->info['features']) ? serialize($theme->info['features']) : '';
$data['info'] = serialize($theme->info);
$data['label'] = $theme->info['name'];
$data['libraries'] = !empty($theme->info['libraries']) ? serialize($theme->info['libraries']) : '';
$data['mtime'] = $theme->info['mtime'];
$data['name'] = $theme
->getName();
$data['origin'] = preg_match('/^core\\/themes\\//i', $theme
->getPathname()) ? 'core' : 'extension';
$data['owner'] = $theme->owner;
$data['pathname'] = $theme
->getPathname();
$data['php'] = !empty($theme->info['php']) ? $theme->info['php'] : '';
$data['project'] = !empty($theme->info['project']) ? $theme->info['project'] : '';
$data['project_status_url'] = !empty($theme->info['project_status_url']) ? $theme->info['project_status_url'] : '';
$data['regions'] = !empty($theme->info['regions']) ? serialize($theme->info['regions']) : '';
$data['regions_hidden'] = !empty($theme->info['regions_hidden']) ? serialize($theme->info['regions_hidden']) : '';
$data['required'] = !empty($theme->info['required']) ? (int) $theme->info['required'] : 0;
$data['required_by'] = !empty($theme->required_by) ? serialize($theme->required_by) : '';
$data['requires'] = !empty($theme->requires) ? serialize($theme->requires) : '';
$data['screenshot'] = !empty($theme->info['screenshot']) && file_exists($theme->info['screenshot']) ? $theme->info['screenshot'] : '';
$data['status'] = $theme->status;
$data['type'] = $theme
->getType();
$data['version'] = !empty($theme->info['version']) ? $theme->info['version'] : '';
$data['visible'] = !empty($theme->info['hidden']) ? (int) (!$theme->info['hidden']) : 1;
db_insert('views_system')
->fields($data)
->execute();
}
}
/**
* Helper function to retrieve list of origins.
*/
function views_system_get_origin_list() {
return array(
'core' => t('Core'),
'extension' => t('Extension'),
);
}
/**
* Helper function to retrieve list of types.
*/
function views_system_get_type_list() {
return array(
'module' => t('Module'),
'profile' => t('Profile'),
'theme' => t('Theme'),
'theme_engine' => t('Theme engine'),
);
}
Functions
Name | Description |
---|---|
views_system_cache_flush | Implements hook_cache_flush(). |
views_system_form_system_modules_alter | Implements hook_form_FORM_ID_alter(). |
views_system_form_system_themes_admin_form_alter | Implements hook_form_FORM_ID_alter(). |
views_system_get_origin_list | Helper function to retrieve list of origins. |
views_system_get_type_list | Helper function to retrieve list of types. |
views_system_help | Implements hook_help(). |
views_system_modules_installed | Implements hook_modules_installed(). |
views_system_rebuild_module_data | Helper function to rebuild module's data. |
views_system_rebuild_theme_data | Helper function to rebuild theme's data. |