You are here

function install_tasks in Drupal 8

Same name and namespace in other branches
  1. 6 install.php \install_tasks()
  2. 7 includes/install.core.inc \install_tasks()
  3. 9 core/includes/install.core.inc \install_tasks()

Returns a list of all tasks the installer currently knows about.

This function will return tasks regardless of whether or not they are intended to run on the current page request. However, the list can change based on the installation state (for example, if an installation profile hasn't been selected yet, we don't yet know which profile tasks will be available).

You can override this using hook_install_tasks() or hook_install_tasks_alter().

Parameters

$install_state: An array of information about the current installation state.

Return value

A list of tasks, with associated metadata as returned by hook_install_tasks().

3 calls to install_tasks()
InstallCommand::install in core/lib/Drupal/Core/Command/InstallCommand.php
Installs Drupal with specified installation profile.
install_tasks_to_display in core/includes/install.core.inc
Returns a list of tasks that should be displayed to the end user.
install_tasks_to_perform in core/includes/install.core.inc
Returns a list of tasks to perform during the current installation request.

File

core/includes/install.core.inc, line 749
API functions for installing Drupal.

Code

function install_tasks($install_state) {

  // Determine whether a translation file must be imported during the
  // 'install_import_translations' task. Import when a non-English language is
  // available and selected. Also we will need translations even if the
  // installer language is English but there are other languages on the system.
  $locale_module_installed = \Drupal::moduleHandler()
    ->moduleExists('locale');
  $needs_translations = $locale_module_installed && (count($install_state['translations']) > 1 && !empty($install_state['parameters']['langcode']) && $install_state['parameters']['langcode'] != 'en' || \Drupal::languageManager()
    ->isMultilingual());

  // Determine whether a translation file must be downloaded during the
  // 'install_download_translation' task. Download when a non-English language
  // is selected, but no translation is yet in the translations directory.
  $needs_download = isset($install_state['parameters']['langcode']) && !isset($install_state['translations'][$install_state['parameters']['langcode']]) && $install_state['parameters']['langcode'] != 'en';

  // Start with the core installation tasks that run before handing control
  // to the installation profile.
  $tasks = [
    'install_select_language' => [
      'display_name' => t('Choose language'),
      'run' => INSTALL_TASK_RUN_IF_REACHED,
    ],
    'install_download_translation' => [
      'run' => $needs_download ? INSTALL_TASK_RUN_IF_REACHED : INSTALL_TASK_SKIP,
    ],
    'install_select_profile' => [
      'display_name' => t('Choose profile'),
      'display' => empty($install_state['profile_info']['distribution']['name']) && count($install_state['profiles']) != 1,
      'run' => INSTALL_TASK_RUN_IF_REACHED,
    ],
    'install_load_profile' => [
      'run' => INSTALL_TASK_RUN_IF_REACHED,
    ],
    'install_verify_requirements' => [
      'display_name' => t('Verify requirements'),
    ],
    'install_settings_form' => [
      'display_name' => t('Set up database'),
      'type' => 'form',
      // Even though the form only allows the user to enter database settings,
      // we still need to display it if settings.php is invalid in any way,
      // since the form submit handler is where settings.php is rewritten.
      'run' => $install_state['settings_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
      'function' => 'Drupal\\Core\\Installer\\Form\\SiteSettingsForm',
    ],
    'install_write_profile' => [],
    'install_verify_database_ready' => [
      'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
    ],
    'install_base_system' => [
      'run' => $install_state['base_system_verified'] ? INSTALL_TASK_SKIP : INSTALL_TASK_RUN_IF_NOT_COMPLETED,
    ],
    // All tasks below are executed in a regular, full Drupal environment.
    'install_bootstrap_full' => [
      'run' => INSTALL_TASK_RUN_IF_REACHED,
    ],
    'install_profile_modules' => [
      'display_name' => t('Install site'),
      'type' => 'batch',
    ],
    'install_profile_themes' => [],
    'install_install_profile' => [],
    'install_import_translations' => [
      'display_name' => t('Set up translations'),
      'display' => $needs_translations,
      'type' => 'batch',
      'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
    ],
    'install_configure_form' => [
      'display_name' => t('Configure site'),
      'type' => 'form',
      'function' => 'Drupal\\Core\\Installer\\Form\\SiteConfigureForm',
    ],
  ];
  if (!empty($install_state['config_install_path'])) {

    // The chosen profile indicates that rather than installing a new site, an
    // instance of the same site should be installed from the given
    // configuration.
    // That means we need to remove the steps installing the extensions and
    // replace them with a configuration synchronization step.
    unset($tasks['install_download_translation']);
    $key = array_search('install_profile_modules', array_keys($tasks), TRUE);
    unset($tasks['install_profile_modules']);
    unset($tasks['install_profile_themes']);
    unset($tasks['install_install_profile']);
    $config_tasks = [
      'install_config_import_batch' => [
        'display_name' => t('Install configuration'),
        'type' => 'batch',
      ],
      'install_config_download_translations' => [],
      'install_config_revert_install_changes' => [],
    ];
    $tasks = array_slice($tasks, 0, $key, TRUE) + $config_tasks + array_slice($tasks, $key, NULL, TRUE);
  }

  // Now add any tasks defined by the installation profile.
  if (!empty($install_state['parameters']['profile'])) {

    // Load the profile install file, because it is not always loaded when
    // hook_install_tasks() is invoked (e.g. batch processing).
    $profile = $install_state['parameters']['profile'];
    $profile_install_file = $install_state['profiles'][$profile]
      ->getPath() . '/' . $profile . '.install';
    if (file_exists($profile_install_file)) {
      include_once \Drupal::root() . '/' . $profile_install_file;
    }
    $function = $install_state['parameters']['profile'] . '_install_tasks';
    if (function_exists($function)) {
      $result = $function($install_state);
      if (is_array($result)) {
        $tasks += $result;
      }
    }
  }

  // Finish by adding the remaining core tasks.
  $tasks += [
    'install_finish_translations' => [
      'display_name' => t('Finish translations'),
      'display' => $needs_translations,
      'type' => 'batch',
      'run' => $needs_translations ? INSTALL_TASK_RUN_IF_NOT_COMPLETED : INSTALL_TASK_SKIP,
    ],
    'install_finished' => [],
  ];

  // Allow the installation profile to modify the full list of tasks.
  if (!empty($install_state['parameters']['profile'])) {
    $profile = $install_state['parameters']['profile'];
    if ($install_state['profiles'][$profile]
      ->load()) {
      $function = $install_state['parameters']['profile'] . '_install_tasks_alter';
      if (function_exists($function)) {
        $function($tasks, $install_state);
      }
    }
  }

  // Fill in default parameters for each task before returning the list.
  foreach ($tasks as $task_name => &$task) {
    $task += [
      'display_name' => NULL,
      'display' => !empty($task['display_name']),
      'type' => 'normal',
      'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
      'function' => $task_name,
    ];
  }
  return $tasks;
}