function field_conditional_state_fields_list in Field Conditional States 7.2
Menu callback; lists all conditional state-enabled fields.
1 string reference to 'field_conditional_state_fields_list'
- field_conditional_state_menu in ./
field_conditional_state.module - Implements hook_menu().
File
- ./
field_conditional_state.module, line 960 - Main functions of this module.
Code
function field_conditional_state_fields_list() {
$conditional_states = field_conditional_state_get_states();
$bundle_info = field_info_bundles();
// Table headers.
$header = array(
t('Field name'),
t('State'),
t('Control fields'),
t('Used in'),
);
// Table rows.
$rows = array();
foreach ($conditional_states as $state) {
$temp_row = array();
// Add field.
$temp_row['data'][0] = $state['field_name'];
// Add state.
$temp_row['data'][1] = $state['state'];
// Add control fields.
$temp_row['data'][2]['logic'] = $state['type'];
foreach ($state['states'] as $field) {
$negated = FALSE;
if (substr($field['trigger_state'], 0, 1) == '!') {
$negated = TRUE;
$field['trigger_state'] = substr($field['trigger_state'], 1);
}
$value = '';
if ($field['trigger_state'] == 'value') {
if ($trigger_value = @unserialize($field['trigger_value'])) {
foreach ($trigger_value as $value) {
$temp_row['data'][2][] = $field['control_field'] . ($negated ? ' != ' : ' = ') . $value;
}
}
else {
$temp_row['data'][2][] = $field['control_field'] . ($negated ? ' != ' : ' = ') . $field['trigger_value'];
}
}
else {
$temp_row['data'][2][] = $field['control_field'] . ' is ' . ($negated ? 'NOT ' : '') . $field['trigger_state'];
}
}
// Add bundle.
$admin_path = NULL;
if (module_exists('field_ui')) {
$admin_path = _field_ui_bundle_admin_path($state['entity_type'], $state['bundle']);
}
$temp_row['data'][3] = $admin_path ? l($bundle_info[$state['entity_type']][$state['bundle']]['label'], $admin_path . '/fields/' . $state['field_name'] . '/field_conditional_state') : $bundle_info[$state['entity_type']][$state['bundle']]['label'];
$rows[] = $temp_row;
}
// Collect all control fields into a string.
foreach ($rows as $id => $cell) {
$logic = drupal_strtoupper($cell['data'][2]['logic']);
unset($cell['data'][2]['logic']);
$rows[$id]['data'][2] = implode('<br />' . $logic . '<br />', $cell['data'][2]);
}
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
'empty' => t('No fields have conditional states yet.'),
));
return $output;
}