DashboardService

mail@pastecode.io avatar
unknown
php
2 years ago
879 B
0
Indexable
Never
<?php
namespace Drupal\mint_intranet_dashboard\Service;

use Symfony\Component\Yaml\Yaml;

class DashboardService {
  // Get all blocks from installed modules.
  public function getBlocks() {
    $blocks = [];
    $modules = [
      'mint_intranet_communication',
    ];
    $installedModules = [];

    $moduleHandler = \Drupal::service('module_handler');

    foreach ($modules as $module) {
      if ($moduleHandler->moduleExists($module)) {
        array_push($installedModules, $module);
      }
    }

    foreach ($installedModules as $module) {
      $filePath = 'modules/contrib/mint_intranet/modules/' . $module . '/parameters.yml';
      $fileContent = Yaml::parse(file_get_contents($filePath));

      if ($fileContent['dashboard'] != null) {
        array_push($blocks, $fileContent['dashboard']['communication_dashboard']);
      }
    }

    return $blocks;
  }
}