You are here

public function WardenManager::generateSiteData in Warden 8

Same name and namespace in other branches
  1. 8.2 src/Service/WardenManager.php \Drupal\warden\Service\WardenManager::generateSiteData()
  2. 3.x src/Service/WardenManager.php \Drupal\warden\Service\WardenManager::generateSiteData()

Generate all the site's data for Warden.

Return value

array The site's data as an array.

1 call to WardenManager::generateSiteData()
WardenManager::updateWarden in src/Service/WardenManager.php
Update Warden with latest site data.

File

src/Service/WardenManager.php, line 127

Class

WardenManager
Default controller for the warden module.

Namespace

Drupal\warden\Service

Code

public function generateSiteData() {
  $result = [
    'core' => [
      'drupal' => [
        'version' => $this
          ->getCoreVersion(),
      ],
    ],
    'contrib' => [],
    'custom' => [],
    'library' => [],
    'url' => $this
      ->getBaseUrl(),
    'site_name' => $this
      ->getSiteName(),
    'key' => $this
      ->getLocalToken(),
    'time' => $this
      ->getTime(),
  ];

  // Indicate if we are not including custom modules.
  if (!$this
    ->includeCustomModules()) {
    $result['custom'] = 'disabled';
  }

  // Indicate if we are not including contrib modules.
  if (!$this
    ->includeContribModules()) {
    $result['contrib'] = 'disabled';
  }

  // Indicate if we are not including third party libraries.
  if (!$this
    ->includeLibrary()) {
    $result['library'] = 'disabled';
  }

  // Include all contrib themes.
  if ($this
    ->includeContribModules()) {
    foreach ($this
      ->getThemes() as $theme) {
      if (isset($theme->info['package']) && $theme->info['package'] == 'Core') {
        continue;
      }
      if (isset($theme->info['version'])) {
        $result['contrib'][$theme->name] = [
          'version' => $theme->info['version'],
        ];
      }
    }
  }

  // Include all modules.
  foreach ($this
    ->getModules() as $module => $module_info) {
    $filename = $module_info
      ->getPathname();

    // Match for custom modules.
    if ($this
      ->includeCustomModules() && preg_match($this
      ->getCustomRegex(), $filename)) {
      $result['custom'] = array_merge($result['custom'], $this
        ->getModuleDetails($module, $filename));
    }

    // Match for contrib modules.
    if ($this
      ->includeContribModules() && preg_match($this
      ->getContribRegex(), $filename)) {
      $result['contrib'] = array_merge($result['contrib'], $this
        ->getModuleDetails($module, $filename));
    }
  }

  // Include all third party libraries.
  if ($this
    ->includeLibrary()) {
    if (isset($this->customLibraries)) {
      $result['library'] = $this->customLibraries;
    }
    else {
      foreach ($this
        ->getLibraries() as $library_uri => $library_info) {
        $result['library'] = array_merge($result['library'], $this
          ->getLibraryDetails($library_uri));
      }
    }
  }
  return $result;
}