You are here

function mailchimp_activity_entity_form_validate in Mailchimp 7.4

Same name and namespace in other branches
  1. 7.5 modules/mailchimp_activity/includes/mailchimp_activity.admin.inc \mailchimp_activity_entity_form_validate()
  2. 7.2 modules/mailchimp_activity/mailchimp_activity.admin.inc \mailchimp_activity_entity_form_validate()
  3. 7.3 modules/mailchimp_activity/includes/mailchimp_activity.admin.inc \mailchimp_activity_entity_form_validate()

Validation callback for mailchimp_activity_entity_form().

File

modules/mailchimp_activity/includes/mailchimp_activity.admin.inc, line 143
Administration pages for mailchimp_activity module.

Code

function mailchimp_activity_entity_form_validate($form, &$form_state) {
  if ($form_state['submitted']) {
    $extant_mc_entities = entity_load('mailchimp_activity_entity');
    $form_id = $form_state['mailchimp_activity_entity']->mailchimp_activity_entity_id;
    $form_bundle = $form_state['values']['bundle'];
    $form_entity_id = $form_state['values']['entity_type'];
    foreach ($extant_mc_entities as $extant_ent) {
      if ($form_bundle == $extant_ent->bundle && $form_entity_id == $extant_ent->entity_type && $form_id != $extant_ent->mailchimp_activity_entity_id) {
        form_set_error('bundle', t('A Mailchimp Activity Entity already exists for this Bundle. Either select a different Bundle or edit the !link for this bundle.', array(
          '!link' => l(t('existing Mailchimp Activity Entity'), "admin/config/services/mailchimp/activity/manage/{$extant_ent->name}"),
        )));
      }
    }
  }
}