You are here

function apps_profile_apps_select_form in Apps 7

Apps install form

1 string reference to 'apps_profile_apps_select_form'
apps_profile_install_tasks in ./apps.profile.inc
Add install tasks to profile install tasks.

File

./apps.profile.inc, line 72
The install functions for the Apps module.

Code

function apps_profile_apps_select_form($form, $form_state, &$install_state) {
  drupal_set_title(t('Install Apps'));

  // Get and cache the apps manifest file.
  apps_include('manifest');

  // If there is no internet things get in an unfixable state. Use try->catch
  if (empty($_SESSION['apps_manifest']) || empty($_SESSION['apps_server'])) {
    try {
      if ($apps_server = $_SESSION['apps_servers'][$install_state['active_task']]) {
        $_SESSION['apps_server'] = $apps_server;
        $_SESSION['apps_manifest'] = apps_apps($apps_server['machine name']);
      }
    } catch (Exception $e) {

      // This condition is handled in right below.
    }
  }

  // Set a message if no manifest or internet problems.
  if (empty($_SESSION['apps_manifest'])) {
    $form['info'] = array(
      '#markup' => t('<h2>Error</h2><p>Unable to connect to Apps Server.</p><p>Click "Continue" to finish the installation. You can either fix your internet connection and try the installation again or install apps later from the apps config page.</p>'),
    );
    $form['actions'] = array(
      '#type' => 'actions',
    );
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Continue'),
    );
    return $form;
  }
  drupal_set_title(apps_profile_get_server_name($_SESSION['apps_server']));
  $form['actions'] = array(
    '#type' => 'actions',
    '#weight' => 3,
  );
  $form['apps_message'] = array(
    '#markup' => t('<h2>Apps</h2><p>Apps are the next generation in usability for Drupal. They contain bundles of functionality for your website. Select any apps you want to install right now. You can add more later on the apps page.</p></p>In order to install apps, you must be able to FTP or SSH into your server. This uses the same process as the update module.</p>'),
  );
  $form['#attached']['css'][] = drupal_get_path('module', 'apps') . '/theme/css/apps-install.css';
  $form['apps_tabs'] = array(
    '#type' => 'vertical_tabs',
  );
  $apps_manifest = $_SESSION['apps_manifest'];
  unset($apps_manifest['#theme']);
  $all_packages = array();
  foreach ($apps_manifest as $name => $app) {
    $packages = array();
    if (!empty($app['package'])) {

      // Only allow the first package on this form for now.
      // @todo have javascript so can show it for all packages.
      foreach (explode(',', $app['package']) as $package) {
        $package = trim($package);
        $package_key = strtolower(preg_replace('/[^\\da-z]/i', '', $package));
        $packages[$package_key] = $package;
        break;
      }
    }
    else {
      $packages['other'] = t('Other');
    }
    foreach ($packages as $package_key => $package) {
      if (empty($form['apps_package_' . $package_key])) {
        $all_packages[] = $package_key;
        $form['apps_package_' . $package_key] = array(
          '#type' => 'fieldset',
          '#group' => 'apps_tabs',
          '#title' => $package,
        );
      }
      $form['apps_package_' . $package_key][$name] = array(
        '#title' => '<strong>' . $app['name'] . '</strong>',
        '#type' => 'checkbox',
        '#parents' => array(
          'apps',
          $name,
        ),
        '#return_value' => $name,
        '#description' => (!empty($app['logo']['path']) ? theme('image', array(
          'path' => $app['logo']['path'],
          'height' => '32',
          'width' => '32',
          'attributes' => array(
            'class' => array(
              'apps-image',
            ),
          ),
        )) : '') . (!empty($app['description']) ? $app['description'] : '') . '<span class="clearfix"></span>',
        '#default_value' => in_array($name, $_SESSION['apps_server']['default apps']),
      );

      // Hide child apps if parent is not being choosen.
      if (!empty($app['parent_apps'])) {
        foreach ($app['parent_apps'] as $parent_app) {
          $form['apps_package_' . $package_key][$name]['#states']['visible'][':input[name="apps[' . $parent_app . ']"]'] = array(
            'checked' => TRUE,
          );
        }
      }
    }
  }

  // If only one package, convert to old method.
  if (count($all_packages) == 1) {
    unset($form['apps_tabs']);
    $form['apps_package_' . reset($all_packages)]['#title'] = t('Select Apps To Install');
  }
  else {

    // Sort the packages by alaphabet.
    unset($all_packages['other']);
    sort($all_packages);
    foreach ($all_packages as $weight => $package_key) {
      $form['apps_package_' . $package_key]['#weight'] = $weight;
    }

    // Other should be last.
    if (!empty($form['apps_package_other'])) {
      $form['apps_package_other']['#weight'] = $weight + 1;
    }
  }
  $form['default_content_fieldset'] = array(
    '#type' => 'fieldset',
    '#title' => t('Default Content'),
    '#collapsible' => FALSE,
  );
  $form['default_content_fieldset']['default_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('Install default content'),
    '#default_value' => TRUE,
    '#description' => t('By selecting this box default content will be installed for each app. Without default content the site may look empty before you start adding to it. You can remove the default content later by going to the apps config page.'),
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Install Apps'),
  );
  $form['actions']['skip'] = array(
    '#type' => 'submit',
    '#value' => t('Skip this step'),
  );
  drupal_add_css("#apps-profile-apps-select-form .form-submit { display:inline; }", array(
    'type' => 'inline',
  ));
  return $form;
}