1 installer.manager.inc installer_manager_install_form_validate($form, &$form_state)

Form validation handler for installer_manager_install_form().

See also


Related topics


core/modules/installer/installer.manager.inc, line 667
Administrative screens and processing functions of the Installer module.


function installer_manager_install_form_validate($form, &$form_state) {
  if (!empty($form_state['values']['bulk'])) {
    // Prepare entered names.
    $project_names = explode("\n", $form_state['values']['bulk']);
    $project_names = array_map('trim', $project_names);
    $project_names = array_filter($project_names, 'strlen');
    if (empty($project_names)) {
      form_set_error('bulk', t('Sorry, none of the submitted names are valid.'));

    // This repetitious bit here exists because there is no way to query all
    // projects at once from the server. So we compromise by searching each
    // project type using a large 'items_per_page' value to get all results.
    // Since we can only query the server by project, we ask for all modules
    // first, check if any of the submitted project names are not modules, then
    // check themes, then layouts. Anything left over after this is not a valid
    // project on the server.
    $not_found = array();
    module_load_include('inc', 'installer', 'installer.browser');

    $modules = installer_browser_fetch_results(array('items_per_page' => 999, 'type' => 'module'));
    $all_projects = $modules['projects'];
    if (!empty($modules)) {
      $listed_projects = array_keys($modules['projects']);
      $not_found = array_diff($project_names, $listed_projects);
      if ($not_found) {
        $themes = installer_browser_fetch_results(array('items_per_page' => 999, 'type' => 'theme'));
        if (!empty($themes)) {
          $all_projects = array_merge($all_projects, $themes['projects']);
          $listed_projects = array_keys($themes['projects']);
          $not_found = array_diff($not_found, $listed_projects);
          if ($not_found) {
            $layouts = installer_browser_fetch_results(array('items_per_page' => 999, 'type' => 'layout'));
            if (!empty($layouts)) {
              $all_projects = array_merge($all_projects, $layouts['projects']);
              $listed_projects = array_keys($layouts['projects']);
              $not_found = array_diff($not_found, $listed_projects);
    else {
      // If there was no return from the server assume it is offline.
      form_set_error('bulk', t('Sorry, the project server is offline.'));

    // If some of the submitted names were not valid projects first check to
    // see if any at all were valid. If some were valid, we proceed with a
    // warning. If not were valid, we terminate with error.
    if ($not_found) {
      $project_names = array_diff($project_names, $not_found);
      backdrop_set_message(t('Sorry, the following projects were not recognized: %names', array('%names' => implode(', ', $not_found))));
    // Check if any remaining names are already installed.
    foreach ($project_names as $project_name) {
      $project = $all_projects[$project_name];
      // Check not already downloaded.
      $already_enabled = array();
      if (backdrop_get_filename($project['type'], $project_name)) {
        $already_enabled[] = $project_name;
      if (!empty($already_enabled)) {
        $project_names = array_diff($project_names, $already_enabled);
        backdrop_set_message(t('The following projects are already installed: %names', array('%names' => implode(', ', $already_enabled))));

    // If there are no valid projects left, stop here
    if (!$project_names) {
      form_set_error('bulk', t('Sorry, none of the submitted names are valid projects.'));

    // If we got this far, we have at least one valid project, so save in
    // $form_state.
    $projects = array();
    foreach ($project_names as $project_name) {
      $projects[$project_name] = $all_projects[$project_name];

    $form_state['projects'] = $projects;
  elseif (!($form_state['values']['project_url'] XOR !empty($_FILES['files']['name']['project_upload']))) {
    form_set_error('project_url', t('You must either provide project names, a URL, or upload an archive file to install.'));