You are here

function pmpapi_push_admin_config_validate in Public Media Platform API Integration 7

Form validation handler for pmpapi_push_admin_config().

See also

pmpapi_push_admin_config_submit()

File

pmpapi_push/pmpapi_push.admin.inc, line 157
Basic admin forms, validators, and submit handlers for the PMPAPI Push module.

Code

function pmpapi_push_admin_config_validate($form, &$form_state) {
  foreach (pmpapi_push_get_entities() as $entity_type => $entity) {
    $bundles = $entity['bundles'];
    if ($bundles) {
      foreach ($bundles as $bundle_name => $bundle) {
        $fields = pmpapi_get_augmented_fields($entity_type, $bundle_name);
        $uname = $entity_type . '__' . $bundle_name;
        $taken = array();
        $profile = $form_state['values'][$uname . '_push_profile'];
        if ($profile) {
          foreach ($fields as $field_name => $field) {
            $pmp_fields = pmpapi_get_profile_info($profile);
            $value = $form_state['values']['pmpapi_push_mapping_' . $uname . '_' . $field_name];
            if ($value !== '0') {
              if (!in_array($field['type'], $pmp_fields[$value]['accepted_types'])) {
                $error_msg = "To map to PMP field {$value}, the (drupal) field must be one of the following type(s): " . implode(', ', $pmp_fields[$value]['accepted_types']);
                form_set_error('pmpapi_push_mapping_' . $uname . '_' . $field_name, t('Incompatible field types.') . ' ' . $error_msg);
              }
              $taken[] = $value;
            }
          }
          foreach ($pmp_fields as $pmp_name => $pmp_field) {
            if (!empty($pmp_field['required']) && !in_array($pmp_name, $taken)) {
              form_set_error($bundle_name . '_mappings', t('%pmp_name is a required field.', array(
                '%pmp_name' => $pmp_name,
              )));
            }
          }
        }
      }
    }
  }
}