You are here

function views_system_rebuild_theme_data in Views System 8

Same name and namespace in other branches
  1. 7.4 views_system.module \views_system_rebuild_theme_data()

Helper function to rebuild theme's data.

4 calls to views_system_rebuild_theme_data()
views_system_cache_flush in ./views_system.module
Implements hook_cache_flush().
views_system_form_system_themes_admin_form_alter in ./views_system.module
Implements hook_form_FORM_ID_alter().
views_system_install in ./views_system.install
Implements hook_install().
views_system_modules_installed in ./views_system.module
Implements hook_modules_installed().

File

./views_system.module, line 113
Extends the Views module and provides fields, filter criteria, and sort criteria for Modules/Themes/Theme engines.

Code

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();
  }
}