You are here

function radioactivity_arbitrary_source_admin_source_validate in Radioactivity 5

File

plugins/radioactivity_arbitrary_source.module, line 154

Code

function radioactivity_arbitrary_source_admin_source_validate($form_id, $form) {
  $info = radioactivity_get_radioactivity_info();
  $sources = _radioactivity_get_arbitrary_sources();

  // check that target is valid
  if (!isset($info['targets'][$form['target_hidden']])) {
    drupal_set_message(t('Invalid target: "%t"', array(
      '%t' => ${$form}['target_hidden'],
    )));
    drupal_goto('admin/settings/radioactivity/arbitrary_sources');
  }

  // check that source is valid
  if ($form['source_hidden'] && !isset($sources[$form['target_hidden']][$form['source_hidden']])) {
    drupal_set_message(t('Invalid source: "%t"', array(
      '%t' => $form['source_hidden'],
    )));
    drupal_goto('admin/settings/radioactivity/arbitrary_sources');
  }

  // validate that identifier uses only a-z, 0-9, _
  if (!preg_match('@^[a-z0-9_]+$@', $form['identifier'])) {
    form_set_error('identifier', t('Malformed identifier'));
  }
  else {
    global $radioactivity_arbitrary_source_skip_radioactivity_info;
    $radioactivity_arbitrary_source_skip_radioactivity_info = TRUE;
    $info = radioactivity_get_radioactivity_info(TRUE);

    // check that we are not overriding any source provided by another plugin
    if (isset($info['sources'][$form['target_hidden']][$form['identifier']])) {
      form_set_error('identifier', t('Identifier already provided by another plugin'));
    }

    // check that we are not overriding any source that is already configured
    if ($form['identifier'] != $form['source_hidden'] && isset($sources[$form['target_hidden']][$form['identifier']])) {
      form_set_error('identifier', t('Identifier already configured'));
    }
  }
}