function entity_rules_form_alter in Entity Rules 7
Implements hook_form_alter().
File
- ./
entity_rules.module, line 583 - Module file for the Entity Rules.
Code
function entity_rules_form_alter(&$form, &$form_state, $form_id) {
if (!empty($form['#entity_type']) && !empty($form['#bundle'])) {
$bundle_name = $form['#bundle'];
$entity_type = NULL;
if ($form_settings = _entity_rules_get_form_entity_type_settings($form_state)) {
if ($rule_settings = entity_rules_load_settings_for_op($form_settings['entity_type'], $bundle_name, 'form_access')) {
// This bundle has 'form access' Rules.
$entity_type = $form_settings['entity_type'];
if (isset($form['#' . $entity_type]) || isset($form['#entity'])) {
$entity = isset($form['#' . $entity_type]) ? $form['#' . $entity_type] : $form['#entity'];
$results = _entity_rules_invoke_rules($entity, $entity_type, 'form_access');
if (!_entity_rules_all_pass($results)) {
$form['#access'] = FALSE;
}
}
}
if ($rule_settings = entity_rules_load_settings_for_op($form_settings['entity_type'], $bundle_name, 'validation')) {
// @todo For now always attach validate to form
$form['#validate'][] = 'entity_rules_entity_form_validation';
/* if (isset($form['actions']['#type']) && $form['actions']['#type'] == 'actions') {
// Modules can exclude certain ops from validation(delete for example).
foreach (element_children($form['actions']) as $op) {
if (empty($form_settings['exclude_validation_ops']) || !in_array($op,$form_settings['exclude_validation_ops'])) {
$form['actions'][$op]['#validate'][] = 'entity_rules_entity_form_validation';
}
}
}
else {
$form['#validate'][] = 'entity_rules_entity_form_validation';
} */
}
}
}
}