You are here

function comment_alter_requirements in Comment Alter 7

Implements hook_requirements().

If somehow a field is added to a comment bundle which is also alterable from comment on the parent node bundle, put a message on the system status report.

We've made it impossible to do this via the UI, but it's still possible via low-level trickery, so this is a fallback to alert site administrators of a problem.

File

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

Code

function comment_alter_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    foreach (node_type_get_types() as $bundle_name => $type_obj) {

      // Get the comment alter fields directly, rather than via
      // comment_alter_get_alterable_fields(), because it will remove the fields
      // which are on the comment.
      $field_infos = field_info_instances('node', $bundle_name);
      $comment_alter_fields = array();
      foreach ($field_infos as $field_name => $value) {
        if (!empty($value['comment_alter'])) {
          $comment_alter_fields[] = $field_name;
        }
      }
      if (!empty($comment_alter_fields)) {
        $comment_fields = field_info_instances('comment', 'comment_node_' . $bundle_name);
        foreach ($comment_fields as $field_name => $field_instance) {
          if (in_array($field_name, $comment_alter_fields)) {
            $requirements[] = array(
              'title' => t('Comment alter'),
              'value' => t('Invalid fields error'),
              'description' => t('The %field_name field exists on the comment and is alterable from comment on the parent node. Please remove it from the comment or disable altering it from comment!', array(
                '%field_name' => $field_name,
              )),
              'severity' => REQUIREMENT_ERROR,
            );
          }
        }
      }
    }
  }
  return $requirements;
}