Redesign the module API
Justin W Freeman - June 29, 2009 - 00:24
| Project: | Nodewords |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
A lot of the functions in the nodewords module are private.
There are some that would be very useful for other modules that don't really need to be private, for example:
_nodewords_update_tag & _nodewords_delete_tag. Or maybe just _nodewords_set
_nodewords_delete
_nodewords_load
_nodewords_form
These are functions that could be public without negative affects and would be useful for other developers.
Is there any chance you could reassess whether these functions need to be private?

#1
I don't see any reason of keeping them private.
Before to make any changes, I would like to understand better what the third-party modules needs are. Any suggestions, or ideas are welcome.
#2
I have had to add nodewords functionality to the image project's image_import module for a client.
I have it using _nodewords_form & _nodewords_set to give the meta tags fieldset to the user so they can add meta tags for their images as they are imported.
It could be useful for the node import module and other modules as well.
#3
This feature request is subordinated to #236833: Add more settings pages for the global meta tags, which will change the user interface of the module.
I will try to make the module API as more generic as possible.
#4
I changed the arguments accepted from
_nodewords_form(), which now is declared as_nodewords_form($type, $tags, $options = array()), where$typeis the type of page the meta tags are associated with (it can be node, user, page, etc...),$tagsis an array containing the actual values for the meta tags, and$optionsis an array of options.The code of the function is now the following:
<?php
/**
* Create a form - returns a $form variable
*/
function _nodewords_form($type, $tags, $options = array()) {
$default_options = array(
'fieldset' => TRUE,
'fieldset title' => t('Meta tags'),
);
$form = array();
$options += $default_options;
$settings = _nodewords_get_settings();
foreach (_nodewords_get_possible_tags() as $tag => $info) {
// Avoid the disabled meta tags.
if (!empty($info['disabled'])) {
continue;
}
if (!$settings['edit'][$tag]) {
continue;
}
if (!empty($info['permission']) && !user_access($info['permission'])) {
continue;
}
$function = $info['functions prefix'] .'_form';
if (function_exists($function)) {
$element = $function($type, isset($tags[$tag]) ? $tags[$tag] : '<none>', $settings);
if (isset($element)) {
$form[$tag] = $element;
}
}
}
if (!empty($form) && $options['fieldset']) {
$form['#type'] = 'fieldset';
$form['#title'] = $options['fieldset title'];
$form['#tree'] = TRUE;
$form['#collapsible'] = TRUE;
$form['#collapsed'] = TRUE;
$form['#weight'] = 20;
}
return $form;
}
?>
Any suggestion on how to change the module API is welcome.
#5
One thing with making these functions accessible for other modules is to change the function names so they don't have the preceding underscore.
Even though it is possible for you to call the function from another module if it has the first underscore, coding standards say that a function with a preceding underscore are private and should not be called from outside of the module.
#6
The module API has been changed, and it is now stable.
#7
Automatically closed -- issue fixed for 2 weeks with no activity.