0

I'm working on a drupal page and recently encountered a problem when I couldn't enable comments on a certain content type. Looking for the problem I found that there were no fields for the comments in that content type.

I checked the other content types where comments were enabled without problems and checked which fields were enabled for the comments. I tried to enable the comments in the first content type by adding an existing field for comments, but the comment fields were not available to choose.

Here i attach an image of what it looks like on the drupal (It's in spanish but I hope you can get the context) How the content type looks like without comment fields

This is how it should look like with the comment fields: How the content type looks like with the comment fields

Is there a way to retrieve this fields so comments can be enabled for this content type?

  • Have you tried re-adding them by looking to see if they are listed in Seleccione un campo existente ? – No Sssweat Nov 23 '15 at 16:35
  • Yes I tried, as I mentioned in the question, but the comment fields were not available to choose there. – Miquel Correa Casablanca Nov 23 '15 at 16:38
0

Basing on the code for comment_field_extra_fields(), I think that what you are noting can be explained with the comment_subject_field_$type persistent variable being set to a value different from 1. ($type is the machine name of the content type.)

function comment_field_extra_fields() {
  $return = array();

  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,
          ),
        ),
      );
    }
  }

  return $return;
}

comment_form() contains the following code.

  $form['subject'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#maxlength' => 64,
    '#default_value' => $comment->subject,
    '#access' => variable_get('comment_subject_field_' . $node->type, 1) == 1,
    '#weight' => -1,
  );

Only when the 'comment_subject_field_' . $node->type persistent variable is set to 1 the users have access to that form field.

Changing the value of that persistent variable to 1 should restore those form fields you are expecting to see.

  • I'll check it tomorrow and I will tell you if this works. thank you. – Miquel Correa Casablanca Nov 23 '15 at 17:19
  • I confirmed that it was the problem. It was solved by adding variable_set('comment_subject_field_' . $node->type, 1); in the node type template. – Miquel Correa Casablanca Nov 24 '15 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.