function rb_cck_get_fields in Rules Bonus Pack 6
Helper function to get all fields on the site with single column for storage.
Parameters
array $requirements: An array with special requirements that must be fulfilled. Options are:
- multiple: Returns only multiple-value fields.
- userreference: Returns only userreference fields.
- all: Forces the function to include even non-sigle column fields.
Return value
array An associative array with key and value set to field machine name.
11 calls to rb_cck_get_fields()
- rb_cck_action_copy_field_form in ./
rb_cck.module - Configuration form for 'rb_cck_action_copy_field'.
- rb_cck_action_copy_multiple_form in ./
rb_cck.module - Configuration form for 'rb_cck_action_copy_multiple'.
- rb_cck_action_email_userreference_form in ./
rb_cck.module - Configuration form for 'rb_cck_action_email_userreference'.
- rb_cck_action_force_to_allowed_values_form in ./
rb_cck.module - Configuration form for 'rb_cck_action_force_to_allowed_values'.
- rb_cck_action_insert_value_multiple_form in ./
rb_cck.module - Configuration form for 'rb_cck_action_insert_value_multiple'.
File
- ./
rb_cck.module, line 229 - Functions for extending CCK field management with Rules.
Code
function rb_cck_get_fields($requirements = array()) {
// Get raw data for all configured fields on the site.
$all_fields = content_fields();
$allowed_fields = array();
// Build a base array of fields with exactly one storage column, unless
// requirements are set to 'all'.
if (in_array('all', $requirements)) {
foreach ($all_fields as $field_name => $field_info) {
$allowed_fields[$field_name] = $field_name;
}
}
else {
foreach ($all_fields as $field_name => $field_info) {
if (count($field_info['columns']) == 1) {
$allowed_fields[$field_name] = $field_name;
}
}
}
// Run any additional conditions on the field array. Note that we are
// *removing* fields – not selecting which to keep. This makes it easier to
// run several requirement tests in sequence.
if (in_array('multiple', $requirements)) {
foreach ($allowed_fields as $field_name) {
if ($all_fields[$field_name]['multiple'] != 1) {
unset($allowed_fields[$field_name]);
}
}
}
if (in_array('single', $requirements)) {
foreach ($allowed_fields as $field_name) {
if ($all_fields[$field_name]['multiple']) {
unset($allowed_fields[$field_name]);
}
}
}
if (in_array('userreference', $requirements)) {
foreach ($allowed_fields as $field_name) {
if ($all_fields[$field_name]['type'] != 'userreference') {
unset($allowed_fields[$field_name]);
}
}
}
if (in_array('text', $requirements)) {
foreach ($allowed_fields as $field_name) {
if ($all_fields[$field_name]['type'] != 'text') {
unset($allowed_fields[$field_name]);
}
}
}
// Sort the array and return the whole shebang.
asort($allowed_fields);
return $allowed_fields;
}