You are here

function patterns_import_file in Patterns 7.2

Same name and namespace in other branches
  1. 5 patterns.module \patterns_import_file()
  2. 6.2 patterns.module \patterns_import_file()
  3. 6 patterns.module \patterns_import_file()
  4. 7 includes/forms/import.inc \patterns_import_file()

Display the import pattern file form

1 string reference to 'patterns_import_file'
patterns_menu in ./patterns.module
Implements hook_menu().

File

includes/forms/import.inc, line 116
Importing Patterns from a file or using an URL.

Code

function patterns_import_file($form, &$form_state) {
  $form = array();
  if (!patterns_parser_ready()) {
    $messages = t('No available patterns parser was found.</br>');
    $messages .= t(' Go to the !modules page to enable more Patterns parsers.', array(
      '!modules' => l(t('modules'), 'admin/modules'),
    ));
    drupal_set_message($messages, 'warning');
    return $form;
  }
  $def_dir = patterns_path_get_files_dir();
  $text = 'Choose a local file to import in the database.';
  $title = 'Import from File';
  patterns_forms_add_page_header($form, $title, $text);
  $form['#attributes']['enctype'] = 'multipart/form-data';
  $form['pattern_uri'] = array(
    '#type' => 'file',
    '#title' => t('Upload Pattern File'),
    '#description' => t('Imported patterns are not executed until you run them manually.'),
    '#size' => 48,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Pattern Identifier'),
    '#description' => t('The new name of the pattern file. If the extension is missing it will be automatically added.'),
    '#required' => TRUE,
  );
  $form = patterns_forms_get_formats_selector($form, PATTERNS_FORMAT_UNKNOWN, 'If unknown, it will be determined by the extension.');

  // TODO: transform in a FILE form
  $form['destination'] = array(
    '#type' => 'textfield',
    '#title' => t('Destination'),
    '#description' => t('Pattern will be saved in this directory. Must be writable. Default dir: @dir', array(
      '@dir' => $def_dir,
    )),
    '#default_value' => $def_dir,
    '#required' => TRUE,
  );
  $form['local'] = array(
    '#type' => 'hidden',
    '#value' => TRUE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  $form['#validate'][] = 'patterns_import_validate';
  $form['#submit'][] = 'patterns_import_submit';
  return $form;
}