function properties_admin_categories_form_validate in Dynamic properties 7
File
- ./
properties.admin.inc, line 385 - Contains admin menu callbacks for properties.module.
Code
function properties_admin_categories_form_validate($form, &$form_state) {
// Update category object.
$form_state['category']->label = $form_state['values']['label'];
$form_state['category']->name = $form_state['values']['name'];
$form_state['category']->attributes = array();
uasort($form_state['values']['attributes'], '_field_sort_items_helper');
foreach ($form_state['values']['attributes'] as $name => $attribute) {
if (is_array($attribute) && isset($attribute['attribute'])) {
if (empty($attribute['attribute'])) {
$attribute_object = (object) array(
'label' => '',
'name' => '',
'weight' => count($form_state['category']->attributes),
);
$form_state['category']->attributes[$name] = $attribute_object;
}
elseif ($attribute_object = properties_attribute_load($attribute['attribute'])) {
$attribute_object->weight = count($form_state['category']->attributes);
$form_state['category']->attributes[$attribute_object->name] = $attribute_object;
}
else {
// Update empty attribute.
$attribute_object = (object) array(
'label' => isset($attribute['label']) ? $attribute['label'] : '',
'name' => $attribute['attribute'],
'weight' => count($form_state['category']->attributes),
'new' => TRUE,
);
$form_state['category']->attributes[$attribute['attribute']] = $attribute_object;
// If label is empty, add validation error.
if (empty($form_state['category']->attributes[$attribute['attribute']]->label)) {
// Not possible to do this as a proper form validation step because
// the form is not rebuilt in case of validation errors.
drupal_set_message(t('Attribute %name does not exist, a label must be provided to create it.', array(
'%name' => $attribute['attribute'],
)), 'error');
$form_state['rebuild'] = TRUE;
}
}
}
}
}