You are here

function patterns_import_source in Patterns 7.2

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

Form constructor for the Pattern import form.

See also

patterns_import_validate()

patterns_import_submit()

2 string references to 'patterns_import_source'
patterns_editor in includes/forms/editor.inc
Builds up a pattern editing environment. Loads additional javascript libraries, and supplies AJAX validation on the fly.
patterns_menu in ./patterns.module
Implements hook_menu().

File

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

Code

function patterns_import_source($form, &$form_state) {
  $form = array();
  if (!patterns_parser_ready()) {
    return $form;
  }
  $def_dir = patterns_path_get_files_dir();
  $text = t('Cut and paste the content of a pattern file in the text area below to import it in the database.');
  $title = t('Import from Source');
  patterns_forms_add_page_header($form, $title, $text);
  $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);
  $form = patterns_forms_get_validation_level_selector($form, PATTERNS_VALIDATE_SYNTAX);

  //Set the field as required for the import source case
  $form['format']['#required'] = TRUE;
  $form['validation_result'] = array(
    '#markup' => 'This pattern has not been validated yet.',
    '#prefix' => '<div id="validation_result"><strong>',
    '#suffix' => '</strong></div>',
  );
  $form['content'] = array(
    '#type' => 'textarea',
    '#rows' => 25,
    '#title' => t('Enter Pattern Source Code'),
    '#description' => t('Imported patterns are not executed until you run them manually.'),
  );

  // 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['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
  );
  $form['validate'] = array(
    '#prefix' => '<span style=\'margin-right:10px\'>',
    '#markup' => "<a href='#' id='validate_pattern'>" . t('Validate') . "</a>",
    '#suffix' => '</span> ',
  );

  // ? Double array ?
  $form['#validate'][] = 'patterns_import_validate';
  $form['#submit'][] = 'patterns_import_submit';
  return $form;
}