3

How would one go about changing the order of the content types list on a multilingual site or non-english site?

For example, by adding a content type named Émission (with accentuated É), we see the following list on admin/structure/types page:

  • Article
  • Page
  • Émission

Same goes when translating a content type name (E.g.: Show => Émission) and changing language.

2

The function node_type_get_names() calls the utility function _node_types_build(). If you look at the source, there is a call to asort() at the bottom.

If you read the documentation for asort(), you will see that it isn't called with it's second parameter, $sort_flags. This means that it will be called with the default, which is "normal" rules. In this case, I am prety sure normal rules means ordering based on the value of the code point, which places the English alphabet first, then "specials".

To take your characters with diacriticals into account, you would have have a proper locale defined, and then call asort() with the SORT_LOCALE_STRING option. For example,

$types = array('Émission', 'Page', 'Article');
print_r($types);

sort($types);
print_r($types);

setlocale(LC_ALL, 'fr');
sort($types, SORT_LOCALE_STRING);
print_r($types);

results in

Array
(
    [0] => Émission
    [1] => Page
    [2] => Article
)
Array
(
    [0] => Article
    [1] => Page
    [2] => Émission
)
Array
(
    [0] => Article
    [1] => Émission
    [2] => Page
)

That explains why the ordering isn't what you expect. A quick look through the Drupal source only reveals a single call to setlocale(LC_ALL, 'C'); (it's in the bootstrap). See https://stackoverflow.com/questions/5231620/what-does-set-localelc-ctype-c-actually-do for what this does.

All of this means that without doing a hook_menu_alter() on the 'admin/structure/types' to change the page callback to be your own, or to hook_pager_alter() the render array for the page, you can't change the ordering.

As a stupid American :) who doesn't really understand all of the implications of localization and internationalization, I cann't comment whether the Drupal behavior is by-design or is a bug.

  • And thanks to @AnilSagar whose answer prompted me to dig into this and so some experiments. – mpdonadio May 7 '14 at 14:42

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.