You are here

function patterns_lab in Patterns 7

Same name and namespace in other branches
  1. 7.2 includes/forms/lab.inc \patterns_lab()

@file Functions related to exporting patterns.

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

File

includes/forms/lab.inc, line 7
Functions related to exporting patterns.

Code

function patterns_lab($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;
  }
  $header = array(
    'category' => array(
      'data' => t('category'),
      'field' => 'n.category',
      'sort' => 'asc',
    ),
    'name' => array(
      'data' => 'name',
      'field' => 'n.name',
    ),
    'title' => array(
      'data' => 'title',
      'field' => 'n.title',
    ),
    'status' => array(
      'data' => 'status',
      'field' => 'n.status',
    ),
    'author' => array(
      'data' => 'author',
      'field' => 'n.author',
    ),
    'version' => array(
      'data' => 'version',
      'field' => 'n.version',
    ),
    'description' => array(
      'data' => 'description',
      'field' => 'n.description',
    ),
  );
  $rows = array();

  // Load the patterns from database.
  // no check with file system
  $patterns = patterns_db_get_patterns();
  foreach ($patterns as $pid => $pattern) {
    $pattern_code = unserialize($pattern->pattern);
    $category = @$pattern_code['info']['category'] ? @$pattern_code['info']['category'] : t('Other');
    $title = @$pattern_code['info']['title'];
    $name = $pattern->name;
    $status = @$pattern->status ? t('Enabled') : t('Disabled');
    $author = @$pattern_code['info']['author'];
    $version = @$pattern_code['info']['version'];
    $description = @$pattern->description;
    $row = array(
      'category' => $category,
      'name' => $name,
      'title' => empty($title) ? '-' : $title,
      'status' => $status,
      'author' => empty($author) ? '-' : $author,
      'version' => empty($version) ? '-' : $version,
      'description' => empty($description) ? '-' : 'No description',
    );
    $rows[$pid + 1] = $row;

    // somehow we get (pid -1) in the submit handler
  }
  $text = 'In this area you can experiment by mixing several patterns together into a new one. The resulting pattern file can be imported into the database or downloaded as a file.';
  $title = 'Patterns Lab';
  patterns_forms_add_page_header($form, $title, $text);
  $form['patterns'] = array(
    '#type' => 'fieldset',
    '#title' => t('Available Patterns'),
  );
  $form['patterns']['patterns_table'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#empty' => t('No Patterns'),
  );
  $form['lab'] = array(
    '#type' => 'fieldset',
    '#title' => t('Lab options'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['lab']['mode'] = array(
    '#type' => 'radios',
    '#options' => _patterns_lab_get_exp_mode_options(),
    '#title' => t('Include mode'),
    '#default_value' => PATTERNS_EXPORT_MODE_FULL,
  );
  $form['lab']['to'] = array(
    '#type' => 'radios',
    '#options' => _patterns_lab_get_exp_to_options(),
    '#title' => t('Action'),
    '#default_value' => PATTERNS_EXPORT_TO_FILE,
  );
  patterns_forms_get_info_section($form, array(), array(
    'collapsed' => TRUE,
  ));
  $form['export_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name of the new pattern file'),
    '#description' => t('Extension will be automatically added'),
    '#default_value' => t('pattern') . '_' . strval(time()),
  );
  $form = patterns_forms_get_formats_selector($form, patterns_forms_get_default_format(), 'Include all selected patterns in this format.', FALSE);
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Go'),
  );
  $form['#submit'][] = 'patterns_lab_submit';
  return $form;
}