You are here

function shorten_cs_edit_validate in Shorten URLs 8

Same name and namespace in other branches
  1. 8.2 modules/shorten_cs/shorten_cs.admin.inc \shorten_cs_edit_validate()
  2. 6 shorten_cs.admin.inc \shorten_cs_edit_validate()
  3. 7.2 shorten_cs.admin.inc \shorten_cs_edit_validate()
  4. 7 shorten_cs.admin.inc \shorten_cs_edit_validate()

Validates the form to edit a custom service.

File

modules/shorten_cs/shorten_cs.admin.inc, line 46
Provides the configuration page for Shorten URLs Custom Services.

Code

function shorten_cs_edit_validate($form, $form_state) {
  $v = $form_state['values'];
  if (($v['type'] == 'xml' || $v['type'] == 'json') && empty($v['tag'])) {
    form_set_error('type', t('An XML tag or JSON key is required for services with a response type of XML or JSON.'));
  }
  $exists = db_query("SELECT COUNT(sid) FROM {shorten_cs} WHERE name = :name AND sid <> :sid", array(
    ':name' => $v['name'],
    ':sid' => $v['sid'],
  ))
    ->fetchField();
  if ($exists > 0) {
    form_set_error('name', t('A service with that name already exists.'));
  }
  else {
    $all_services = \Drupal::moduleHandler()
      ->invokeAll('shorten_service');
    $all_services['none'] = t('None');
    foreach ($all_services as $key => $value) {
      if ($key == $v['name']) {
        form_set_error('name', t('A service with that name already exists.'));
        break;
      }
    }
  }
}