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
Comments
Comment #1
robin monks commentedAdditionally, node_type_get_names() would make a better replacement function altogether.
Comment #2
jhodgdonWe 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?
Comment #3
robin monks commentednode_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
Comment #4
jhodgdonWell, 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...
Comment #5
amateescu commentedHere comes the novice contributor :)
Comment #6
jhodgdonLooks good, patch applies fine - thanks for your contribution!
Comment #7
dries commentedCommitted to CVS HEAD.