You are here

function patterns_enable_pattern in Patterns 7.2

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 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 392

Code

function patterns_enable_pattern($form, &$form_state, $pid) {
  $form = array();
  if (!patterns_engine_is_on()) {
    drupal_set_message(t('Patterns engine is off. You can change the state of the engine from the settings page if you want to execute the pattern. This attempt has been logged.'), 'warning');
    watchdog('patterns', 'Attempt to run a pattern with engine off.');
    drupal_goto('admin/patterns');
    return $form;
  }
  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(check_plain($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, TRUE, PATTERNS_VALIDATE_ALL, TRUE)) {
    $link = l(t('syntax and content'), '/admin/patterns/edit/' . $pid);
    $form['invalid'] = array(
      '#markup' => t('This pattern did not pass the validation. This may be due to an error in the pattern itself, or to the current configuration of your database. If you are trying to run interdependent actions in the same pattern (E.g. creating a vocabulary and then adding a term) this could be normal.'),
      '#prefix' => '<div id="important"><strong>Ooops! </strong>',
    );
  }
  $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);
}