You are here

function field_patterns_prepare in Patterns 7

Same name and namespace in other branches
  1. 7.2 patterns_components/components/field.inc \field_patterns_prepare()

File

patterns_components/components/field.inc, line 155
Patterns component for Fields.

Code

function field_patterns_prepare($action, $tag, &$data = NULL) {
  $prefix = '';
  if ($action == PATTERNS_DELETE || $action == PATTERNS_MODIFY) {
    $prefix = 'field_';
  }

  // @TODO: remove unnecessary stuff from $data array;
  if (isset($data['name'])) {
    $data['field_name'] = $prefix . $data['name'];
  }
  if (isset($data['entity'])) {
    $data['entity_type'] = $data['entity'];
  }

  // FIELD
  if ($tag == 'instance') {

    // DELETE
    if ($action == PATTERNS_DELETE) {
      $data['confirm'] = 1;
      $data['op'] = 'Delete';
    }
    else {
      $data = _field_patterns_prepare_instance($action, $data);
    }
  }
  elseif ($tag == 'field') {
    $data = _field_patterns_prepare_field($action, $data);
  }
  else {
    foreach ($data['weight'] as $key => $lev) {
      $name = $prefix . $key;
      $data['fields'][$name]['weight'] = $lev;
    }
    unset($data['weight']);
  }
  return patterns_results();
}