You are here

function patterns_enable_pattern in Patterns 7

Same name and namespace in other branches
  1. 5 patterns.module \patterns_enable_pattern()
  2. 6.2 patterns.module \patterns_enable_pattern()
  3. 6 patterns.module \patterns_enable_pattern()
  4. 7.2 patterns.module \patterns_enable_pattern()

Form constructor for the Patterns enabling form.

It prompts the user with a submenu of options regarding default behavior with sub-patterns.

@TODO Find a way to skip this in pattern_list, to quickly execute the pattern.

Parameters

integer $pid The ID of the Pattern to enable.:

See also

patterns_enable_pattern_submit()

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

File

./patterns.module, line 471

Code

function patterns_enable_pattern($form, &$form_state, $pid) {
  $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;
  }
  $pattern = patterns_utils_if_invalid_go_back($pid);
  if (patterns_db_is_pattern_updated($pid)) {
    $form['modified'] = array(
      '#markup' => t('A more recent version of this pattern was found in the file system. The version stored in the database is going to be executed. If unsure, ') . ' ' . l(t('click here to check it out.'), 'admin/patterns/edit/' . $pid),
      // TODO: proper t()
      '#prefix' => '<div id="important"><strong>',
      '#suffix' => '</strong></br></br></div>',
    );
  }
  $scan = patterns_scan_pattern($pattern->pattern);
  if (!_patterns_scan_validate_patternscan($scan)) {
    $link = l('syntax and content', '/admin/patterns/edit/' . $pid);
    $errors = implode('<br/> ', _patterns_scan_analyze_patternscan($scan));
    $form['invalid'] = array(
      '#markup' => t('This pattern is invalid. Please check !stuff before running it.', array(
        '!stuff' => $link,
      )),
      '#prefix' => '<div id="important"><strong>Ooops! </strong>',
      '#suffix' => '<p>' . $errors . '</p>',
    );
    return $form;
  }
  $form['pid'] = array(
    '#type' => 'value',
    '#value' => $pid,
  );

  // Add the execution options
  $form = patterns_forms_get_execution_options($form);
  $disclaimer = t('Please be sure to backup your site before running a pattern. Patterns are not guaranteed to be reversible in case they do not execute well or if unforeseen side effects occur.');
  return confirm_form($form, t('Proceed with running pattern %pattern?', array(
    '%pattern' => $pattern->title,
  )), 'admin/patterns', $disclaimer);
}