The sort comments module has a function in sort_comments.module as below:

  /* drupal@ganovelli.it - blackice78 */
  define('SORT_COMMENTS_OLDER_FIRST', 1); // default
   /* Alter node type form: allow user to decide comments sorting */
 function sort_comments_form_node_type_form_alter(&$form, $form_state) {
  $form['comment']['comment_default_sorting'] = array(
 '#title' => t('Sort'),
 '#type' => 'select',
 '#options' => array(1 => t('Older first'), 
                     2 => t('Newer first')),
 '#default_value' => variable_get('comment_default_sorting_' . $form['#node_type']-  >type, SORT_COMMENTS_OLDER_FIRST), 

so that if you go to structure>content types, and for example for Article choose edit, then in comment setting, it will give you a drop down menu, so that you can select the order for showing comments, older first or newer first.

I am trying to do something similar, so in order to see how does it work, I have this in my annotations.module file:

define('Annotations_OLDER_FIRST', 1); // default
define('Annotations_NEWER_FIRST', 2);
/* Alter node type form: allow user to decide comments sorting */
function Annotations_form_node_type_form_alter(&$form, $form_state) {
  $form['comment']['annotations'] = array(
    '#title' => t('Sort'),
     '#type' => 'select',
    '#options' => array(1 => t('Older first'), 
                     2 => t('Paragraph number')),

  #default_value' => variable_get('annotations_' . $form['#node_type']-  >type, Annotatiios_OLDER_FIRST), 

But I can not see the drop down menu, at the same place that I see the drop down menu for sort comments module. Does anybody know what is the reason?

| improve this question | | | | |

You have a syntax error on the last line, it should start with an apostrophe, and your constant is mispelled. So it probably isn't compiling properly. If drupal was picking up the hook you would probably get a white screen of death.

So this means:

You need to make sure the beginning of the function name is exactly the same as your module name - did you use a capital A when naming the module? PHP is case sensitive.

Lastly, make sure you clear the cache so that Drupal picks up the new hook. Install drush if you haven't already, go to the /install_directory/sites/mysite directory and run

drush cc all

(assuming you're on linux with command line access)

| improve this answer | | | | |
  • Thank you for your answer. I fixed the mistakes that you mentioned, but still it did not work. I have to mention in my Annotations.module file, I also have some other functions like : Annotations_form_comment_form_alter, Annotations_form_comment_form_validate, Annotations_form_comment_form_submit. I created a new module with function comment_sort_form_node_type_form_alter, and it worked. I am really interested to know why it does not work when I have this function in my Annotations.module file. Thanks again for your answer. – user3530082 Sep 6 '14 at 21:24
  • This is just a hunch, but try making your module name all lower case. i.e. annotations rather than Annotations and make sure all of your functions are changed the same way, then flush cache and try again. – Darvanen Sep 6 '14 at 23:32

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.