function conditional_fields_dependency_description in Conditional Fields 7.3
Build a textual description of a dependency
2 calls to conditional_fields_dependency_description()
- conditional_fields_dependency_add_form in includes/
conditional_fields.admin.inc - Dependency add form.
- conditional_fields_entity_view_alter in ./
conditional_fields.module - Implements hook_entity_view_alter().
File
- ./
conditional_fields.module, line 1933 - Define dependencies between fields based on their states and values.
Code
function conditional_fields_dependency_description($dependee_name, $dependent_name, $options) {
$states = conditional_fields_states();
if ($options['condition'] == 'value') {
$values = implode(', ', $options['values']);
switch ($options['values_set']) {
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
if (count($options['value']) == 1) {
return t('%dependent_name is !state when %dependee_name has value "@value".', array(
'%dependent_name' => $dependent_name,
'!state' => drupal_strtolower($states[$options['state']]),
'%dependee_name' => $dependee_name,
'@value' => current($options['value'][0]),
));
}
// "Single values" of multiple value fields like checkboxes are not
// actually single. Such fields will be ANDed.
$value_array = array();
foreach ($options['value'] as $value) {
$value_array[] = current($value);
}
$values = implode(', ', $value_array);
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:
$description = '%dependent_name is !state when %dependee_name has all the values: @values.';
break;
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR:
$description = '%dependent_name is !state when %dependee_name has at least one of the values: @values.';
break;
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
$description = '%dependent_name is !state when %dependee_name has only one of the values: @values.';
break;
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT:
$description = '%dependent_name is !state when %dependee_name has none of the values: @values.';
break;
case CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
return t('%dependent_name is !state when %dependee_name values match the regular expression: @regex.', array(
'%dependent_name' => $dependent_name,
'!state' => drupal_strtolower($states[$options['state']]),
'%dependee_name' => $dependee_name,
'@regex' => $options['value']['RegExp'],
));
break;
}
return t($description, array(
'%dependent_name' => $dependent_name,
'!state' => drupal_strtolower($states[$options['state']]),
'%dependee_name' => $dependee_name,
'@values' => $values,
));
}
else {
$conditions = conditional_fields_conditions();
return t('%dependent_name is !state when %dependee_name is !condition.', array(
'%dependent_name' => $dependent_name,
'!state' => drupal_strtolower($states[$options['state']]),
'%dependee_name' => $dependee_name,
'!condition' => drupal_strtolower($conditions[$options['condition']]),
));
}
}