Hi,
I know this is entirely the wrong approach to take to development, but this module has potential to be something really quite great, but its in a very rough state and potentially abandoned, and as I have a specific usecase for the module in a project I thought I'd take the chance to clean it up a bit.
The attached patch includes:
- A minor code cleanup for coding standards - Tabs where used instead of 2 spaces (in some places)
- Improved CRUD functions to take more advantage of CTools
- Code re-organization - Mode some functions around and implemented an extensible file structure
- Added a new helper function to return Domain Groups from Domains, so that if you know which Domains are active you also know all Domain groups that meet that criteria
I would also liked to have tackled some further changes, but decided against it as it didn't effect my project, such as the hook_theme() using 'variables' instead of 'arguments' and hardcoded HTML in the theme function.
Additionally, while I think this makes absolute sense to be part of the standard functionality, I have some code below for anyone who wishes to use Domain Groups instead of Domains when selecting where a piece of content should be published:
/**
* Implements hook_form_alter().
*/
function HOOK_form_alter(&$form, $form_state, $form_id) {
if (isset($form['#id']) && $form['#id'] == 'node-form' && isset($form['domain'])) {
$form['domain']['domains']['#access'] = FALSE;
$form['domain']['domain_groups'] = array(
'#type' => 'checkboxes',
'#title' => t('Publish to'),
'#options' => drupal_map_assoc(element_children(domain_groups_groups()), '_HOOK_global_domain_groups_options')
);
if (isset($form['#node']->domains)) {
$domain_groups = domain_groups_groups_from_domains($form['#node']->domains);
$form['domain']['domain_groups']['#default_value'] = element_children($domain_groups);
}
$form['#submit'][] = '_HOOK_domain_groups_node_form_submit';
}
}
/**
*
*/
function _HOOK_domain_groups_options($value) {
$groups = domain_groups_groups();
return $groups[$value]['description'];
}
/**
* Submit callback for Domain Groups node form functionality.
*/
function _HOOK_domain_groups_node_form_submit($form, &$form_state) {
$domains = array();
foreach (element_children(array_filter($form_state['values']['domain_groups'])) as $name) {
$domain_group = domain_groups_load_group($name);
$domains = array_merge($domains, $domain_group->domains);
}
foreach ($form_state['values']['domains'] as $delta => &$value) {
$value = in_array($delta, $domains) ? $delta : 0;
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| domain_groups-deciphered_cleanup-0.patch | 17.81 KB | deciphered |
Comments
Comment #1
decipheredForgot to mark as 'needs review'.
Comment #3
blackdog commentedHey,
Thanks for the great patch! I'll have a look and get back asap. The module isn't abbandonded, it rather contains everything we need at the moment. Not to say there aren't ways to improve it, like the Publish to changes, which look great. I'd have no problem adding that, with a setting to go with it.
Also, since you obviously have a use case for this module, I'd be happy to add you as a co-maintainer if you'd like?
Comment #5
decipheredSounds fine to me, I'll try to respect the existing functionality so as not to break your project that currently uses it, and add things in such a way as not to be too heavy handed.
Cheers,
Deciphered.
Comment #6
blackdog commentedCommitted. Had to add
ctools_include('export');in two places, wherectools_export_crud_loadwere called, otherwise, looks good. I found a bug though, opening a new issue for that.Adding you as co-maintaner now. Thanks & welcome :)