You are here

function patterns_import_server in Patterns 6

Same name and namespace in other branches
  1. 6.2 patterns.module \patterns_import_server()
  2. 7 includes/servers.inc \patterns_import_server()

Display the import pattern from server form

1 string reference to 'patterns_import_server'
patterns_menu in ./patterns.module
Implementation of hook_menu().

File

./patterns.module, line 321
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function patterns_import_server(&$form_state) {
  if (empty($form_state['storage'])) {
    $path = file_create_path(variable_get('patterns_save_xml', 'patterns'));
    if (!file_check_directory($path, true)) {
      $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_file_types()) ? 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;
}