You are here

function patterns_prepare_actions in Patterns 6

Same name and namespace in other branches
  1. 6.2 patterns.module \patterns_prepare_actions()
1 call to patterns_prepare_actions()
patterns_execute_pattern_batch in ./patterns.module

File

./patterns.module, line 1462
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function patterns_prepare_actions(&$actions, $actions_map) {
  $result = array(
    'success' => TRUE,
  );
  if (empty($actions)) {
    return $result;
  }
  patterns_load_components();

  // Keep a list of what modules handle what tags
  $tag_modules = patterns_invoke($empty, 'tag modules');

  // TODO Finish basic setup and execution of the 'config' operation
  // TODO Make a better streamlined config framework process. For instance collect form_ids
  // from here and give the form_id and matching data to the 'build' process
  foreach ($actions as $key => &$data) {
    if (($config = patterns_invoke($actions[$key], 'config')) && !empty($config)) {
      patterns_config_data($data, $config);
    }
  }

  // Prepare actions for validation/processing
  foreach ($actions as $key => &$data) {
    patterns_invoke($actions[$key], 'prepare');
  }
  $errors = array();

  // Pre validate tags with their appropriate components
  foreach ($actions as $key => &$data) {
    $action_location = patterns_locate_action($key, $actions_map);
    $index = $action_location['key'];
    $pattern_title = $action_location['title'];

    //    $pattern_file = $action_location['file'];
    if (!array_key_exists($data['tag'], $tag_modules)) {
      $errors[] = t('Action #%num (%tag) in pattern %title: <%tag> is not a valid tag', array(
        '%num' => $index + 1,
        '%tag' => $data['tag'],
        '%title' => $pattern_title,
      ));
    }
    else {
      $error = patterns_invoke($actions[$key], 'pre-validate');
      if ($error) {
        $errors[] = t('Action #%num (%tag) in pattern %title: !msg', array(
          '!msg' => $error,
          '%num' => $index + 1,
          '%tag' => $data['tag'],
          '%title' => $pattern_title,
        ));
      }
    }
  }
  if (count($errors)) {
    $message = t('Errors encountered during pre-processing:') . '<br>' . implode('<br>', $errors);
    $result['success'] = FALSE;
    $result['error_message'] = $message;
  }
  return $result;
}