You are here

function og_ui_field_settings_validate in Organic groups 7.2

Same name and namespace in other branches
  1. 7 og_ui/og_ui.admin.inc \og_ui_field_settings_validate()

Validate handler; Check if field can be attached to bundle.

File

og_ui/og_ui.admin.inc, line 1074
Admin settings for Organic groups module.

Code

function og_ui_field_settings_validate($form, &$form_state) {
  list($entity_type, $bundle) = explode(':', $form_state['values']['bundle']);
  $field_name = $form_state['values']['field_name'];
  $og_field = og_fields_info($form_state['values']['field_type']);
  $bundles = field_info_bundles($entity_type);
  $entity_info = entity_get_info($entity_type);
  $params = array(
    '%field' => $og_field['instance']['label'],
    '%bundle' => $bundles[$bundle]['label'],
    '%entity' => $entity_info['label'],
  );
  if (field_info_instance($entity_type, $field_name, $bundle)) {
    form_set_error('bundles', t('Field %field already exists in %bundle.', $params));
  }

  // Check field can be attached to entity type.
  if (!empty($og_field['entity']) && !in_array($entity_type, $og_field['entity'])) {
    $items = array();
    foreach ($og_field['entity'] as $entity_type) {
      $info = entity_get_info($entity_type);
      $items[] = $info['label'];
    }
    form_set_error('bundles', t('Field %field can only be attached to %entities entity bundles.', $params + array(
      '%entities' => implode(', ', $items),
    )));
  }
}