You are here

function _comment_alter_cleanup_field_values in Comment Alter 8

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

Helper function to clean up field values for comparison.

Removes and non-alterable columns 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: (optional) Suffix for old value cleanup.

string $prefix: (optional) Prefix for old value cleanup.

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

File

./comment_alter.module, line 252
Allows to alter entities from comment form.

Code

function _comment_alter_cleanup_field_values(&$values, $field_name, $old = '', $prefix = '') {

  // Sort the Multiple valued field via there column _weight and then remove
  // the weight column from values.
  if (isset($values['comment_alterable_columns'][$prefix . $field_name . $old]['_weight'])) {
    usort($values['comment_alter_fields'][$prefix . $field_name . $old], 'comment_alter_cmp');
  }
  foreach ($values['comment_alter_fields'][$prefix . $field_name . $old] as $level => $deltas) {

    // Remove the non-alterable columns from comparison.
    foreach ($values['comment_alter_fields'][$prefix . $field_name . $old][$level] as $column => $value) {

      // Unset the _weight column from $values as our stored old alterable
      // column value doesn't contain _weight column.
      if (!isset($values['comment_alterable_columns'][$field_name][$column]) || $column === '_weight') {
        unset($values['comment_alter_fields'][$prefix . $field_name . $old][$level][$column]);
        continue;
      }
    }
  }
  _comment_alter_cleanup_arrays($values['comment_alter_fields'][$prefix . $field_name . $old]);
}