You are here

function _comment_alter_cleanup_field_values in Comment Alter 7

Same name and namespace in other branches
  1. 8 comment_alter.module \_comment_alter_cleanup_field_values()

Helper function to clean up field values for comparison.

Removes 'add_more' and non-alterable columns (like _weight) so we can compare the old and new field values and find changes.

Parameters

array $values: Array whose elements should be cleaned up.

string $field_name: Clean up this field of the array.

string $old = '': Suffix for old value cleanup.

1 call to _comment_alter_cleanup_field_values()
_comment_alter_submit_node_fields in ./comment_alter.module
Submit callback for the altered comment form.

File

./comment_alter.module, line 274
Provides UI to alter nodes' parameters from comment forms.

Code

function _comment_alter_cleanup_field_values(&$values, $field_name, $old = '') {
  $field_value =& $values[$field_name . $old];
  $alterable_columns = $values['comment_alter']['alterable_columns'][$field_name];

  // Multiple-value fields should not have an 'add_more' delta (this comes from
  // the Field API's Form API stuff: 'add_more' delta is the 'Add more' button.
  foreach ($field_value as $language => $deltas) {
    foreach ($field_value[$language] as $delta => $columns) {
      if ($delta === 'add_more') {
        unset($field_value[$language][$delta]);
        continue;
      }

      // Non-alterable columns (eg. _weight) should be removed (from
      // comparison).
      foreach ($field_value[$language][$delta] as $column => $value) {
        if (!isset($alterable_columns[$column])) {
          unset($field_value[$language][$delta][$column]);
        }
      }
    }
  }
  _comment_alter_cleanup_arrays($field_value);
}