I had tried a few iterations of this including domain_config and hook_domainconf with custom variables, but having to satisfy a few additional criteria, I came up with this solution that I wanted to share and sound off anyone more knowledgable/experienced. It works off just the core Domain Access module's global $_domain variable.
Requirements:
* Provide domain-dependent Allowed Values
* Provide default Allowed Values when domain-specific does not exist
* Let it be exportable
The solution I came up with involves setting "php code" on the CCK Allowed Values field which calls a function, passing in the name of the field being dealt with. The name of the field corresponds to the name of a text file on the server containing a large, flat list of Allowed Values. The filename is further augmented by adding in the $_domain['subdomain'] as part of its name when applicable. In this manner, I can easily provide text files containing Allowed Values for all sites and specific overrides by domain. What I can't immediately do is expose editing these lists to content/side admins.
The function looks like:
/**
* Provide Allowed Values for cck fields, sourcing from text files, considering domain access
* This function is called by CCK field types that need domain-specific Allowed Values
*
* @param $cck_field_name String
* @return Array Array of Allowed Values that cck needs
*/
function _mymodule_get_cck_field_allowed_values($field_name) {
global $_domain;
// Filenames of cck allowed values examples:
// subsystem-field_subsystem_module.txt
// subsystem-field_subsystem_module.www.somedomain.com.txt
$default_filename = drupal_get_path('module', 'mymodule_model_fields') ."/subsystem-$field_name.txt";
$domain_filename = drupal_get_path('module', 'mymodule_model_fields') ."/subsystem-$field_name.{$_domain['subdomain']}.txt";
$allowed_values = (file_exists($domain_filename)) ? file_get_contents($domain_filename) : file_get_contents($default_filename);
return explode("\n", $allowed_values);
}
One of the CCK Allowed Values "php code" looks like:
return _mymodule_get_cck_field_allowed_values('field_subsystem_module');
Some site-specific stuff happening above is that my Feature for this is called "mymodule_model_fields" and "subsystem" is the machine name for the CCK field's cck node type.
Hope this helps. And I hope someone schools me, gently, if you've got some ways to improve.
Closed: outdated
2.11
Documentation
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.