You are here

function entity_rules_entity_form_validation in Entity Rules 7

Validation callback for forms to be validated via Rules.

_state

Parameters

$form:

1 string reference to 'entity_rules_entity_form_validation'
entity_rules_form_alter in ./entity_rules.module
Implements hook_form_alter().

File

./entity_rules.module, line 624
Module file for the Entity Rules.

Code

function entity_rules_entity_form_validation(&$form, &$form_state) {
  $entity_type = $form['#entity_type'];

  // If possible rely on Entity API to build entity
  if ($ui_controller = entity_ui_controller($entity_type)) {
    $entity = $ui_controller
      ->entityFormSubmitBuildEntity($form, $form_state);
  }
  else {

    // Build the entity ourselves
    // @todo How to deal with entities don't support bundles
    $bundle = $form['#bundle'];
    $entity = entity_rules_build_form_entity($form, $form_state, $entity_type, $bundle);
  }
  $results = _entity_rules_invoke_rules($entity, $entity_type, 'validation');
  if (!_entity_rules_all_pass($results)) {
    form_error($form['actions']);
  }
}