function properties_widget_add_category in Dynamic properties 7
Add a category to the widget form.
Parameters
$category_name: Machine name of the category or category to add.
$form_state: Form state.
$field_name: Name of the field.
$langcode: Language code.
2 calls to properties_widget_add_category()
- properties_template_submit_select_template in properties_template/
properties_template.module - Submit callback to add categories of a template to the form.
- properties_widget_add_category_submit in ./
properties.module - Submit callback to add a category.
File
- ./
properties.module, line 619 - This module provides a dynamic property field that can contain an unlimited number of attribute value pairs.
Code
function properties_widget_add_category($category, &$form_state, $field_name, $langcode) {
if (is_string($category)) {
$category = properties_category_load($category);
}
if (!empty($category)) {
$form_state[$field_name]['categories'][$category->name] = array(
'_weight' => count($form_state[$field_name]['categories']),
'category' => $category,
'properties' => array(),
);
foreach ($category->attributes as $property) {
$form_state[$field_name]['categories'][$category->name]['properties'][$property->name] = array(
'attribute' => $property->name,
'category' => $category->name,
'value' => '',
'_weight' => count($form_state[$field_name]['categories'][$category->name]['properties']),
);
}
// Clear the new category form field.
unset($form_state['input'][$field_name][$langcode]['new_category']);
return TRUE;
}
else {
return FALSE;
}
}