You are here

function _relation_migrate_validate_type in Relation 8

Same name and namespace in other branches
  1. 8.2 relation_migrate/relation_migrate.module \_relation_migrate_validate_type()
  2. 7 relation_migrate/relation_migrate.module \_relation_migrate_validate_type()

Validates relation type selection on configuration form.

Check if selected relation type allows usage of source bundle.

1 string reference to '_relation_migrate_validate_type'
relation_migrate_configuration_form in relation_migrate/relation_migrate.module
Configuration form callback.

File

relation_migrate/relation_migrate.module, line 103
Migrations between *reference fields and relations.

Code

function _relation_migrate_validate_type($element, &$form_state, $form) {
  if (!empty($form_state['input']['relation_migrate_' . $element['#array_parents'][0] . '_relation_type'])) {
    module_load_include('inc', 'relation_migrate', 'relation_migrate.modules');
    $field_type = field_info_field_types($element['#array_parents'][0]);
    $relation_type = RelationType::load($form_state['input']['relation_migrate_' . $element['#array_parents'][0] . '_relation_type']);
    $function = $field_type['module'] . '_relation_migrate_type_target_validate';
    if (function_exists($function)) {
      if (!$function($element, $form_state, $form) || !_relation_migrate_validate_type_source($form_state['input']['relation_migrate_' . $element['#array_parents'][0] . '_fields'], $relation_type)) {
        form_error($element, t('Relation type %relation_type cannot be used with one of the selected %FieldType fields. <a href="@rel_type_url">Check allowed source/target bundles for the relation type</a>.', array(
          '%relation_type' => $relation_type
            ->label(),
          '%FieldType' => $field_type['label'],
          '@rel_type_url' => url('admin/structure/relation/manage/' . $relation_type
            ->id() . '/edit'),
        )));
      }
    }
  }
}