Documentation is not clear that, unlike the array returned from node_get_types in Drupal 6.x, the array returned from node_type_get_types() is associative with the key as the node type name and a stdClass as the value.

Hence, code like this is required to use node_type_get_types() in Drupal 7 the same as one would have used node_get_types in Drupal 6:

$form['addanother_nodes']['addanother_nodetypes'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Enable Add another for these content types'),
    '#options' => array_keys(node_type_get_types('names')),
    '#default_value' => variable_get('addanother_nodetypes', array()),
    '#description' => t('An <em>Add another</em> message will be shown after creating these content types'),
  );

This should be clarified in both the upgrade documentation, and the api comments for this function.

/Robin

CommentFileSizeAuthor
#5 948536.patch412 bytesamateescu

Comments

robin monks’s picture

Additionally, node_type_get_names() would make a better replacement function altogether.

jhodgdon’s picture

Status: Active » Postponed (maintainer needs more info)

We don't highlight 6->7 differences in function doc headers, just in the upgrade docs.

http://api.drupal.org/api/function/node_type_get_types/7 says

Return value
An array of node types, keyed by the type.

So I think that is clear enough about the array keys... I guess it could say "an array of node type objects" to make it clear they are objects?

When I look at the D6 version though, I think these have been type objects all along. So I am not sure I understand what you think needs to be documented?

robin monks’s picture

node_get_types('names')

is replaced with

node_type_get_names()

Which I didn't originally see, and, it may be good to include an example on http://drupal.org/update/modules/6/7#node_type_get_functions since I was originally trying to follow the example there and use node_type_get_types(). Also, a note on node_type_get_types that the are objects would also be a big help IMHO, since node_get_types didn't always return items in that fashion.

/Robin

jhodgdon’s picture

Title: Incomplete upgrade documentation for node_type_get_types() » node_type_get_types() could mention that the types it returns are objects
Priority: Normal » Minor
Status: Postponed (maintainer needs more info) » Active
Issue tags: +Novice

Well, the upgrade section says that there are replacements for all of the ops, and it links to a search that lists the functions -- I don't know what else we can do besides listing all the functions directly, which seems pointless since you can get a list with the search, right?

So I think all that remains is that node_type_get_types() could mention that the "types" it returns are objects?

Good doc project for a novice contributor...

amateescu’s picture

Status: Active » Needs review
StatusFileSize
new412 bytes

Here comes the novice contributor :)

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, patch applies fine - thanks for your contribution!

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD.

Status: Fixed » Closed (fixed)
Issue tags: -Novice

Automatically closed -- issue fixed for 2 weeks with no activity.