コード例 #1
0
ファイル: PackageController.php プロジェクト: jeyram/camp-gdl
 /**
  * Shows the status of all required packages.
  *
  * @return array
  *   Returns a render array as expected by drupal_render().
  */
 public function page()
 {
     if (!composer_manager_initialized()) {
         $message = t("Composer Manager needs to be initialized before usage. Run the module's <code>init.sh</code> script or <code>drush composer-manager-init</code> on the command line.");
         drupal_set_message($message, 'warning');
         return array();
     }
     try {
         $packages = $this->packageManager->getRequiredPackages();
     } catch (\RuntimeException $e) {
         drupal_set_message(Xss::filterAdmin($e->getMessage()), 'error');
         $packages = array();
     }
     $rows = array();
     foreach ($packages as $package_name => $package) {
         // Prepare the package name and description.
         if (!empty($package['homepage'])) {
             $options = array('attributes' => array('target' => '_blank'));
             $name = $this->l($package_name, Url::fromUri($package['homepage']), $options);
         } else {
             $name = SafeMarkup::checkPlain($package_name);
         }
         if (!empty($package['description'])) {
             $name .= '<div class="description">' . SafeMarkup::checkPlain($package['description']) . '</div>';
         }
         // Prepare the installed and required versions.
         $installed_version = $package['version'] ? $package['version'] : $this->t('Not installed');
         $required_version = $this->buildRequiredVersion($package['constraint'], $package['required_by']);
         // Prepare the row classes.
         $class = array();
         if (empty($package['version'])) {
             $class[] = 'error';
         } elseif (empty($package['required_by'])) {
             $class[] = 'warning';
         }
         $rows[$package_name] = array('class' => $class, 'data' => array('package' => SafeMarkup::set($name), 'installed_version' => $installed_version, 'required_version' => SafeMarkup::set($required_version)));
     }
     $build = array();
     $build['packages'] = array('#theme' => 'table', '#header' => array('package' => $this->t('Package'), 'installed_version' => $this->t('Installed Version'), 'required_version' => $this->t('Required Version')), '#rows' => $rows, '#caption' => $this->t('Status of Packages Managed by Composer'), '#attributes' => array('class' => array('system-status-report')));
     // Display any errors returned by hook_requirements().
     $this->moduleHandler->loadInclude('composer_manager', 'install');
     $requirements = composer_manager_requirements('runtime');
     if ($requirements['composer_manager']['severity'] == REQUIREMENT_ERROR) {
         drupal_set_message($requirements['composer_manager']['description'], 'warning');
     }
     return $build;
 }
コード例 #2
0
 /**
  * Shows the status of all required packages.
  *
  * @return array
  *   Returns a render array as expected by drupal_render().
  */
 public function page()
 {
     if (!composer_manager_initialized()) {
         $message = t("Composer Manager needs to be initialized before usage. Run the module's <code>init.php</code> script on the command line.");
         drupal_set_message($message, 'warning');
         return [];
     }
     try {
         $packages = $this->packageManager->getRequiredPackages();
     } catch (\RuntimeException $e) {
         drupal_set_message(Xss::filterAdmin($e->getMessage()), 'error');
         return [];
     }
     $rows = [];
     foreach ($packages as $package_name => $package) {
         $package_column = [];
         if (!empty($package['homepage'])) {
             $package_column[] = ['#type' => 'link', '#title' => $package_name, '#url' => Url::fromUri($package['homepage']), '#options' => ['attributes' => ['target' => '_blank']]];
         } else {
             $package_column[] = ['#plain_text' => $package_name];
         }
         if (!empty($package['description'])) {
             $package_column[] = ['#prefix' => '<div class="description">', '#plain_text' => $package['description'], '#suffix' => '</div>'];
         }
         // Prepare the installed and required versions.
         $installed_version = $package['version'] ? $package['version'] : $this->t('Not installed');
         $required_version = $this->buildRequiredVersion($package['constraint'], $package['required_by']);
         // Prepare the row classes.
         $class = [];
         if (empty($package['version'])) {
             $class[] = 'error';
         } elseif (empty($package['required_by'])) {
             $class[] = 'warning';
         }
         $rows[$package_name] = ['class' => $class, 'data' => ['package' => ['data' => $package_column], 'installed_version' => $installed_version, 'required_version' => ['data' => $required_version]]];
     }
     $build = [];
     $build['packages'] = ['#theme' => 'table', '#header' => ['package' => $this->t('Package'), 'installed_version' => $this->t('Installed Version'), 'required_version' => $this->t('Required Version')], '#rows' => $rows, '#caption' => $this->t('Status of Packages Managed by Composer'), '#attributes' => ['class' => ['system-status-report']]];
     // Display any errors returned by hook_requirements().
     $this->moduleHandler->loadInclude('composer_manager', 'install');
     $requirements = composer_manager_requirements('runtime');
     if ($requirements['composer_manager']['severity'] == REQUIREMENT_ERROR) {
         drupal_set_message($requirements['composer_manager']['description'], 'warning');
     }
     return $build;
 }