You are here

function drupalgap_sdk_form in DrupalGap 7

Same name and namespace in other branches
  1. 7.2 drupalgap.module \drupalgap_sdk_form()
1 string reference to 'drupalgap_sdk_form'
drupalgap_status in ./drupalgap.pages.inc
Returns the HTML for the DrupalGap module status page.

File

./drupalgap.module, line 349
A module to provide a bridge between Drupal websites and PhoneGap mobile applications.

Code

function drupalgap_sdk_form($form, &$form_state) {
  global $base_url;

  // Check installation status.
  $installed = variable_get('drupalgap_sdk_installed', 0);
  $dir = variable_get('drupalgap_sdk_dir', 'mobile-application');
  if (!$installed) {

    // Many existing sites will already have the mobile-application directory in
    // use, let's auto detect that.
    if (file_exists($dir)) {
      $installed = 1;
      variable_set('drupalgap_sdk_installed', $installed);
      variable_set('drupalgap_sdk_dir', $dir);
    }
    else {
      $form['#prefix'] = t('With one click, you can install the DrupalGap SDK alongside your Drupal
          site. This allows you to begin building your app immediately.');
    }
  }
  else {

    // If it's installed, but the directory is gone, let them start over.
    if (!file_exists($dir)) {
      $installed = 0;
      variable_set('drupalgap_sdk_installed', $installed);
    }
  }

  // Provide text field for SDK folder path.
  $form['dir'] = array(
    '#type' => 'textfield',
    '#title' => t('Directory'),
    '#default_value' => $dir,
    '#disabled' => $installed,
    '#field_prefix' => $base_url . '/',
    '#description' => $installed ? t('The SDK is already installed.') : t('Specify a folder name for the SDK to live in.'),
  );

  // Provide them with a link to view the app.
  if ($installed) {
    $demo_link = base_path() . $dir . '/index.html';
    $form['dir']['#suffix'] = '<div class="messages status">' . '<a href="' . $demo_link . '" target="_blank" title="' . t('Test your app in a browser') . '">' . t('Launch app') . '</a>' . ' (' . l(t('download'), 'admin/config/services/drupalgap/download-app', array(
      'attributes' => array(
        'title' => t('Download a zip file of your app'),
      ),
    )) . ' | ' . l(t('publish'), 'http://docs.drupalgap.org/7/Compiling_a_Mobile_Application', array(
      'attributes' => array(
        'target' => '_blank',
        'title' => t('Learn how to publish your app for users to download'),
      ),
    )) . ')' . '</div>';
  }
  if (!$installed) {
    $form['submit_button'] = array(
      '#type' => 'submit',
      '#value' => t('Install the SDK'),
    );
  }

  // Show helpful links.
  $form['#suffix'] = theme('item_list', array(
    'items' => array(
      l(t('Getting started guide'), 'http://drupalgap.org/get-started'),
      l(t('API'), 'http://api.drupalgap.org'),
      l(t('Support'), 'http://drupalgap.org/support'),
    ),
  ));
  return $form;
}