You are here

function _update_helper_checklist_checklistapi_checklist_items in Update helper 8

Same name and namespace in other branches
  1. 2.x modules/update_helper_checklist/update_helper_checklist.module \_update_helper_checklist_checklistapi_checklist_items()

Implements a callback update_helper_checklist_checklistapi_checklist_info().

Return value

array Return the items for the update_helper_checklist list.

1 string reference to '_update_helper_checklist_checklistapi_checklist_items'
update_helper_checklist_checklistapi_checklist_info in modules/update_helper_checklist/update_helper_checklist.module
Implements hook_checklistapi_checklist_info().

File

modules/update_helper_checklist/update_helper_checklist.module, line 40
Update helper checklist hooks.

Code

function _update_helper_checklist_checklistapi_checklist_items() {

  /** @var \Drupal\Core\Extension\ModuleHandler $module_handler */
  $module_handler = \Drupal::service('module_handler');
  $module_directories = $module_handler
    ->getModuleDirectories();
  $all_tasks = [];
  foreach ($module_directories as $module_name => $module_directory) {
    $updates_file = $module_directory . DIRECTORY_SEPARATOR . UpdateChecklist::$updateChecklistFileName;
    if (!is_file($updates_file)) {

      // If there is no "updates_checklist.yml" file in module directory, go for
      // next module.
      continue;
    }
    $module_tasks = Yaml::parse(file_get_contents($updates_file));
    foreach ($module_tasks as $version_key => $updates) {
      $version_updates = [];
      foreach ($updates as $update_key => $update) {
        if (is_array($update)) {

          // Change update key to contain module name.
          $update_key = str_replace('.', '_', $module_name . ':' . $update_key);
          $entry = Update::load($update_key);
          $status = $entry && $entry
            ->wasSuccessfulByHook() ? TRUE : FALSE;
          if ($status && !empty($update['#description_successful'])) {
            $update['#description'] .= $update['#description_successful'];
          }
          elseif (!$status && !empty($update['#description_failed'])) {
            $update['#description'] .= $update['#description_failed'];
          }
        }
        $version_updates[$update_key] = $update;
      }

      // Create unique key for version updates.
      $all_tasks[$module_name . '-' . $version_key] = $version_updates;
    }
  }

  // Prepare tasks for front-end representation.
  array_walk_recursive($all_tasks, function (&$value, $key) {
    if ($key == '#url') {
      $value = Url::fromUri($value);
      if ($value
        ->isExternal()) {
        $value
          ->setOption('attributes', [
          'target' => '_blank',
        ]);
      }
    }
    elseif (in_array($key, [
      '#title',
      '#weight',
    ])) {

      // @codingStandardsIgnoreStart
      $value = t($value);

      // @codingStandardsIgnoreEnd
    }
  });
  return array_reverse($all_tasks);
}