You are here

function _taxonomy_access_disallowed_changes in Taxonomy Access Control 7

Helper function to check for term reference changes disallowed by create.

Parameters

array $new_field: The entity or form values of the updated field.

array $old_field: The entity or form values of the original field.

Return value

array|false Returns FALSE if there are no disallowed changes. Otherwise, an array:

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

Related topics

1 call to _taxonomy_access_disallowed_changes()
_taxonomy_access_compare_fields in ./taxonomy_access.create.inc
Helper function to compare field values and look for disallowed changes.

File

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

Code

function _taxonomy_access_disallowed_changes(array $new_field, array $old_field) {

  // Assemble a list of term IDs from the original entity, if any.
  $old_tids = array();
  foreach ($old_field as $old_item) {

    // Some things are NULL for some reason.
    if ($old_item['tid']) {
      $old_tids[] = $old_item['tid'];
    }
  }

  // Assemble a list of term IDs from the updated entity.
  $new_tids = array();
  foreach ($new_field as $delta => $new_item) {

    // Some things are NULL for some reason.
    // Allow the special tid "autocreate" so users can create new terms.
    if ($new_item['tid'] && $new_item['tid'] != 'autocreate') {
      $new_tids[$delta] = $new_item['tid'];
    }
  }

  // Check for added tids, and unset ones the user may not add.
  $added = array_diff($new_tids, $old_tids);
  $may_not_add = taxonomy_access_create_disallowed($added);

  // Check for removed tids, and restore ones the user may not remove.
  $removed = array_diff($old_tids, $new_tids);
  $may_not_remove = taxonomy_access_create_disallowed($removed);

  // If there were any disallowed changes, return them.
  if (!empty($may_not_add) || !empty($may_not_remove)) {
    return array(
      'added' => $may_not_add,
      'removed' => $may_not_remove,
    );
  }

  // Return FALSE if all changes were valid.
  return FALSE;
}