You are here

function _taxonomy_access_compare_fields in Taxonomy Access Control 7

Helper function to compare field values and look for disallowed changes.

Parameters

array $new: An associative array of the updated field information as returned by _taxonomy_access_entity_fields().

array $old: (optional) An associative array of the original field information, or FALSE if there is no original field data. Defaults to FALSE.

Return value

array An array of disallowed changes, with the structure:

  • $field_name: An associative array keyed by langcode.

    • $langcode: Disallowed changes for this field name and langcode, or FALSE if none.

      • 'added' => An array of added terms that are disallowed.
      • 'removed' => An array of removed termss that are disallowed.

See also

_taxonomy_access_entity_fields()

_taxonomy_access_disallowed_changes()

Related topics

1 call to _taxonomy_access_compare_fields()
_taxonomy_access_field_validate in ./taxonomy_access.create.inc
Validates form submissions of taxonomy fields for create grants.

File

./taxonomy_access.create.inc, line 768
Implements the Add Tag (create) grant on editing forms.

Code

function _taxonomy_access_compare_fields($new, $old = FALSE) {
  $disallowed_changes = array();

  // If there are no original fields, simply process new.
  if (!$old) {
    foreach ($new['data'] as $field_name => $langcodes) {
      foreach ($langcodes as $langcode => $values) {
        $changes = _taxonomy_access_disallowed_changes($values, array());
        if ($changes) {
          if (!isset($disallowed_changes[$field_name])) {
            $disallowed_changes[$field_name] = array();
          }
          $disallowed_changes[$field_name][$langcode] = $changes;
        }
      }
    }
  }
  else {
    $all_fields = $new['field_list'] + $old['field_list'];
    $all_langcodes = $new['langcodes'] + $old['langcodes'];
    foreach ($all_fields as $field_name) {
      foreach ($all_langcodes as $langcode) {
        $new_values = array();
        if (isset($new['field_list'][$field_name]) && isset($new['data'][$field_name][$langcode])) {
          $new_values = $new['data'][$field_name][$langcode];
        }
        $old_values = array();
        if (isset($old['field_list'][$field_name]) && isset($old['data'][$field_name][$langcode])) {
          $old_values = $old['data'][$field_name][$langcode];
        }
        $changes = _taxonomy_access_disallowed_changes($new_values, $old_values);
        if ($changes) {
          if (!isset($disallowed_changes[$field_name])) {
            $disallowed_changes[$field_name] = array();
          }
          $disallowed_changes[$field_name][$langcode] = $changes;
        }
      }
    }
  }
  unset($old);
  unset($new);
  return $disallowed_changes;
}