function relation_entity_collector_validate in Relation 7
Validate form submission for the entity_collector.
File
- relation_entity_collector/
relation_entity_collector.module, line 319 - Relation Entity Collector Block.
Code
function relation_entity_collector_validate($form, &$form_state) {
switch ($form_state['triggering_element']['#value']) {
case t('Pick'):
// Require values.
$relation_type = $form_state['values']['relation_type'];
$entity_key = $form_state['values']['entity_key'];
$errors = FALSE;
if (empty($relation_type)) {
form_set_error('relation_type', t('Please select a relation type.'));
$errors = TRUE;
}
if (empty($entity_key)) {
form_set_error('entity_key', t('Please select an entity.'));
$errors = TRUE;
}
// If either of these are not selected we can not continue.
if ($errors) {
return;
}
// Get entity info from key ('{entity_type}:{entity_id}').
list($entity_type, $entity_id) = explode(':', $entity_key);
// Add the label for later display. #options is check_plain'd but we need
// to do that ourselves.
$entity_label = check_plain($form['entity_picker']['entity_key']['#options'][$entity_key]);
// Indexes are added in ascending order, starting from 0.
$_SESSION += array(
'relation_entity_keys' => array(),
);
$next_index = count($_SESSION['relation_entity_keys']);
// If validation succeeds we will add this in the submit handler.
$form_state['pick'] = array(
'r_index' => $next_index,
'entity_key' => $entity_key,
'entity_label' => $entity_label,
'entity_type' => $entity_type,
'entity_id' => $entity_id,
);
$endpoints = $_SESSION['relation_entity_keys'];
$endpoints[] = $form_state['pick'];
$relation = _relation_entity_collector_get_entity($form_state['values']['relation_type'], $endpoints);
$relation->in_progress = TRUE;
_relation_entity_collector_endpoints_validate($relation, $form, $form_state);
break;
case t('Save relation'):
_relation_entity_collector_endpoints_validate(_relation_entity_collector_get_entity(), $form, $form_state);
break;
}
}