You are here

function patterns_import_server in Patterns 7

Same name and namespace in other branches
  1. 6.2 patterns.module \patterns_import_server()
  2. 6 patterns.module \patterns_import_server()

Form constructor for the pattern importing from server form.

See also

patterns_import_server_validate()

patterns_import_server_submit()

File

includes/servers.inc, line 14
Functions related to importing and publishing patterns on the web.

Code

function patterns_import_server($form, &$form_state) {
  if (empty($form_state['storage'])) {

    // real_path(public) returns the path to the files dir.
    $path = drupal_realpath('public://') . "/" . variable_get('patterns_save_file', 'patterns');

    // Ste: was

    //if (!file_check_directory($path, true)) {
    if (!file_prepare_directory($path)) {
      $message = t("In order to save imported patterns, directory %path must be writable.<br />", array(
        '%path' => $path,
      ));
      $link = l(t('status report'), 'admin/reports/status');
      $message .= t('You might want to check the !link to ensure your files directory exists and is writable.', array(
        '!link' => $link,
      ));
      drupal_set_message($message, 'error');
      return array();
    }
    $form['server_url'] = array(
      '#type' => 'textfield',
      '#title' => t('Specify Patterns Server URL'),
      '#description' => t('URL of the web site you want to import patterns from. Example: http://patterns.graviteklabs.com'),
      '#default_value' => variable_get('patterns_default_server', 'http://patterns.graviteklabs.com'),
      '#size' => 48,
    );
  }
  else {
    $feed = $form_state['storage']['feed'];
    $form['patterns'] = array(
      '#type' => 'fieldset',
      '#tree' => TRUE,
      '#title' => t('Patterns'),
    );
    foreach ($feed['patterns'] as $pattern) {
      $form['patterns'][$pattern['pid']] = array(
        '#type' => 'checkbox',
        '#title' => $pattern['title'],
        '#description' => $pattern['description'],
        '#disabled' => in_array($pattern['file_type'], patterns_config_get_formats()) ? FALSE : TRUE,
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => empty($form_state['storage']) ? t('Get Patterns List') : t('Import'),
  );
  $form['#validate'][] = 'patterns_import_server_validate';
  $form['#submit'][] = 'patterns_import_server_submit';
  return $form;
}