comment_field_extra_fields() contains the following code.

  foreach (node_type_get_types() as $type) {
    if (variable_get('comment_subject_field_' . $type->type, 1) == 1) {
      $return['comment']['comment_node_' . $type->type] = array(
        'form' => array(
          'author' => array(
            'label' => t('Author'),
            'description' => t('Author textfield'),
            'weight' => -2,
          ),
          'subject' => array(
            'label' => t('Subject'),
            'description' => t('Subject textfield'),
            'weight' => -1,
          ),
        ),
      );
    }
  }

The problem is that if you make a custom module with too light weight, comment.module erase all extra fields.

The code should be the following.

  foreach (node_type_get_types() as $type) {
    if (variable_get('comment_subject_field_' . $type->type, 1) == 1) {
      $return['comment']['comment_node_' . $type->type]['form'] ['author']= array(
        'label' => t('Author'),
        'description' => t('Author textfield'),
        'weight' => -2,
      );
      $return['comment']['comment_node_' . $type->type]['form'] ['subject']= array(
        'label' => t('Subject'),
        'description' => t('Subject textfield'),
        'weight' => -1,
      );
    }
CommentFileSizeAuthor
#2 1953202.patch1020 bytesjalpesh
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vpshah86’s picture

Issue summary: View changes
jalpesh’s picture

Here are the patch for same..

jalpesh’s picture

Status: Active » Needs review
jalpesh’s picture

Assigned: Unassigned » jalpesh
apaderno’s picture

Title: Extra field on comment » comment_field_extra_fields() initialize the array of the extra fields to an empty array
Version: 7.21 » 7.x-dev
Assigned: jalpesh » Unassigned
Issue summary: View changes
apaderno’s picture

Does it really reset all the extra fields? hook_field_extra_fields() implementations are invoked in FieldInfo::getBundleExtraFields(), which uses the following code.

  $extra = module_invoke_all('field_extra_fields');
  drupal_alter('field_extra_fields', $extra);

Since module_invoke_all() merges the array it gets from the single implementations of that hook, it should not happen what described here.

function module_invoke_all($hook) {
  $args = func_get_args();

  // Remove $hook from the arguments.
  unset($args[0]);
  $return = array();
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    if (function_exists($function)) {
      $result = call_user_func_array($function, $args);
      if (isset($result) && is_array($result)) {
        $return = array_merge_recursive($return, $result);
      }
      elseif (isset($result)) {
        $return[] = $result;
      }
    }
  }
  return $return;