I am changing a module from Drupal 6 to 7. In the old code, there is this code:
$types = node_get_types();
I changed it to below code but it doesn't work well.
$types = node_type_get_types();

And i also changed it to:
$types = node_type_get();

And finally i changed it to :

node_type_clear();
$types = node_type_get_types();

But none of above codes work. Please tell me what should i write instead of below code to work fine in Drupal 7?
$types = node_get_types();

Comments

geekglue’s picture

When no parameter is supplied Drupal 6's node_get_types returns :

"An array of all available node type objects, keyed by machine name."

Drupal 7's node_type_get_types returns :

"An array of node types, as objects, keyed by the type."

I assume the problem you are having relates to the "keyed by" aspect of the returned array. If so you will need to make adjustments after the quoted code to adjust for this difference. It may help if you could be more explicit about why it "doesn't work well". My reading of this is that it works but differently.

SamH’s picture

D6 - node_get_types():

drupal_set_message('<pre>'. print_r(node_get_types(), TRUE) .'</pre>');

D7 - node_type_get_types()

drupal_set_message('<pre>'. print_r(node_type_get_types(), TRUE) .'</pre>');

This should make things easy to read, so you can check for differences between versions. Use it in your module, or a page/block with PHP filter enabled.

Another thing to check is the function(s) you are using $types with. Perhaps it expects different parameters in D7?

monil-dupe’s picture

I made a php block in Drupal 7 and wrote the code you wrote above to be shown in each node and i got these codes. Now what should i do?

Array
(
    [article] => stdClass Object
        (
            [type] => article
            [name] => Article
            [base] => node_content
            [module] => node
            [description] => Use articles for time-sensitive content like news, press releases or blog posts.
            [help] => 
            [has_title] => 1
            [title_label] => Title
            [custom] => 1
            [modified] => 1
            [locked] => 0
            [disabled] => 0
            [orig_type] => article
            [disabled_changed] => 
        )

    [page] => stdClass Object
        (
            [type] => page
            [name] => Basic page
            [base] => node_content
            [module] => node
            [description] => Use basic pages for your static content, such as an 'About us' page.
            [help] => 
            [has_title] => 1
            [title_label] => Title
            [custom] => 1
            [modified] => 1
            [locked] => 0
            [disabled] => 0
            [orig_type] => page
            [disabled_changed] => 
        )

)
SamH’s picture

Next, I would do the same thing for Drupal 6, and compare the two. The main thing is to see if the keys are the same. In this case, the keys are [article] and [page].

Besides that, if you can give some more information, I'll try to help:

1. What are you trying to accomplish? Just so I have some context for your problem.
2. In Drupal 6, after you set up $types, what did you do with it?
3. In Drupal 7, what were you expecting to happen, and what did happen?

monil-dupe’s picture

Thanks a lot. The problem is solved now by comparing them.