function _hierarchical_select_apply_entity_settings in Hierarchical Select 5.3
Same name and namespace in other branches
- 6.3 hierarchical_select.module \_hierarchical_select_apply_entity_settings()
- 7.3 hierarchical_select.module \_hierarchical_select_apply_entity_settings()
Given a level, apply the entity_count and require_entity settings.
Parameters
$level: A level in the hierarchy.
$config: A config array with at least the following settings:
- module
- params
- entity_count
- require_entity
Return value
The updated level
1 call to _hierarchical_select_apply_entity_settings()
- _hierarchical_select_hierarchy_generate in ./
hierarchical_select.module - Generate the hierarchy object.
File
- ./
hierarchical_select.module, line 1822 - This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.
Code
function _hierarchical_select_apply_entity_settings($level, $config) {
// Only do something when the entity_count or the require_entity (or both)
// settings are enabled.
// NOTE: this uses the optional "hierarchical_selectentity_count" hook, so
// we also check if it's implemented.
if (($config['entity_count'] || $config['require_entity']) && module_hook($config['module'], 'hierarchical_select_entity_count')) {
foreach ($level as $item => $label) {
// We don't want to alter special items.
if (!preg_match('/(none|label_\\d+|create_new_item)/', $item)) {
$entity_count = module_invoke($config['module'], 'hierarchical_select_entity_count', $item, $config['params']);
// When the require_entity setting is enabled and the entity count is
// zero, then remove the item from the level.
// When the item is not removed from the level due to the above and
// the entity_count setting is enabled, update the label of the item
// to include the entity count.
if ($config['require_entity'] && $entity_count == 0) {
unset($level[$item]);
}
elseif ($config['entity_count']) {
$level[$item] = "{$label} ({$entity_count})";
}
}
}
}
return $level;
}