You are here

function farm_group_asset_form_validate in farmOS 7

Validation handler for processing the asset group field.

Parameters

array $form: The form array.

array $form_state: The form state array.

1 string reference to 'farm_group_asset_form_validate'
farm_group_form_farm_asset_form_alter in modules/farm/farm_group/farm_group.module
Implements hook_form_FORM_ID_alter().

File

modules/farm/farm_group/farm_group.module, line 241

Code

function farm_group_asset_form_validate(array $form, array &$form_state) {

  // Only proceed if the group multiselect has a value, and there is an asset.
  if (empty($form_state['values']['group']['group']) || empty($form_state['values']['farm_asset'])) {
    return;
  }

  // Grab the asset ID.
  $asset = $form_state['values']['farm_asset'];
  $asset_ids[] = $asset->id;

  // Get selected group IDs.
  $group_ids = $form_state['values']['group']['group'];

  // Validate the asset IDs and group IDs to prevent circular memberships.
  // If an issue is found, flag the 'field_farm_asset' element in the form.
  farm_group_circular_membership_validate($asset_ids, $group_ids, 'group][group');
}