Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     if (empty($form['#translation_directory']) && $form_state->getValue('use_source') == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) {
         $form_state->setErrorByName('use_source', $this->t('You have selected local translation source, but no <a href=":url">Interface translation directory</a> was configured.', array(':url' => $this->url('system.file_system_settings'))));
     }
 }
 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $error = array();
     $sf_library = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", trim($form_state->getValue('superfish_library')));
     if (empty($sf_library)) {
         $form_state->setErrorByName('superfish_library', t('Path to Superfish library field cannot be empty. Please try this list:') . str_replace("\r\n", ",", $this->superfish_library_path()));
     } else {
         // Trimming blank lines and such
         $sf_library = explode("\n", $sf_library);
         // Crystal clear
         foreach ($sf_library as $s) {
             if (!file_exists($s)) {
                 $error[] = $s;
             }
         }
         if (!empty($error)) {
             $error_message = '';
             if (count($error) > 1) {
                 foreach ($error as $e) {
                     $error_message .= '<li>' . $e . '</li>';
                 }
                 $error_message = t('Files not found') . ': <ul>' . $error_message . '</ul>';
             } else {
                 $error_message = t('File not found') . ': ' . $error[0];
             }
             $form_state->setErrorByName('superfish_library', $error_message);
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, array &$form_state)
 {
     $form_state['notify_emails'] = array();
     if (!empty($form_state['values']['update_notify_emails'])) {
         $valid = array();
         $invalid = array();
         foreach (explode("\n", trim($form_state['values']['update_notify_emails'])) as $email) {
             $email = trim($email);
             if (!empty($email)) {
                 if (valid_email_address($email)) {
                     $valid[] = $email;
                 } else {
                     $invalid[] = $email;
                 }
             }
         }
         if (empty($invalid)) {
             $form_state['notify_emails'] = $valid;
         } elseif (count($invalid) == 1) {
             $this->setFormError('update_notify_emails', $form_state, $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
         } else {
             $this->setFormError('update_notify_emails', $form_state, $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     parent::validateForm($form, $form_state);
     if (!intval($form_state['values']['request_token_lifetime'], 10)) {
         form_set_error('oauth_request_token_lifetime', t('The request token lifetime must be a non-zero integer value.'));
     }
 }
Beispiel #5
0
 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, array &$form_state)
 {
     parent::validateForm($form, $form_state);
     if (empty($form['#translation_directory']) && $form_state['values']['use_source'] == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) {
         $this->setFormError('use_source', $form_state, $this->t('You have selected local translation source, but no <a href="@url">Interface translation directory</a> was configured.', array('@url' => url('admin/config/media/file-system'))));
     }
 }
 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->set('notify_emails', []);
     if (!$form_state->isValueEmpty('update_notify_emails')) {
         $valid = array();
         $invalid = array();
         foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
             $email = trim($email);
             if (!empty($email)) {
                 if (valid_email_address($email)) {
                     $valid[] = $email;
                 } else {
                     $invalid[] = $email;
                 }
             }
         }
         if (empty($invalid)) {
             $form_state->set('notify_emails', $valid);
         } elseif (count($invalid) == 1) {
             $form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
         } else {
             $form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  *
  * @DCG: Optional.
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('example') != 'example') {
         $form_state->setErrorByName('example', $this->t('The value is not correct.'));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     if ($form_state->getValue('usar-fecha-prueba-cron') && !$form_state->getValue('fecha-prueba-cron')) {
         $form_state->setErrorByName('fecha-prueba-cron', "Se requiere una fecha si se activa la opcion de prueba para CRON");
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     if (!intval($form_state->getValue('request_token_lifetime', 10))) {
         $form_state->setErrorByName('oauth_request_token_lifetime', $this->t('The request token lifetime must be a non-zero integer value.'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     // Call the form validation handler for each of the toolkits.
     foreach ($this->availableToolkits as $toolkit) {
         $toolkit->validateConfigurationForm($form, $form_state);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $tabindex = $form_state->getValue('recaptcha_tabindex');
     if (!is_numeric($tabindex)) {
         $form_state->setErrorByName('recaptcha_tabindex', t('The tabindex must be an integer.'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $default_format = trim($form_state->getValue(['name_settings', 'default_format']));
     if (empty($default_format) && !strlen($default_format)) {
         $form_state->setErrorByName('name_settings][default_format', t('%title field is required.', array('%title' => $form['name_settings']['default_format']['#title'])));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $form_state->setValue('container_id', trim($form_state->getValue('container_id')));
     if (!preg_match('/^GTM-.*$/', $form_state->getValue('container_id'))) {
         $form_state->setErrorByName('container_id', t('A valid Google Tag Manager Container ID is case sensitive and formatted like GTM-XXXXXX.'));
     }
 }
Beispiel #14
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     $child_type = $form_state['values']['book_child_type'];
     if (empty($form_state['values']['book_allowed_types'][$child_type])) {
         $this->setFormError('book_child_type', $form_state, $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => $this->t('Add child page'))));
     }
     parent::validateForm($form, $form_state);
 }
Beispiel #15
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $child_type = $form_state->getValue('book_child_type');
     if ($form_state->isValueEmpty(array('book_allowed_types', $child_type))) {
         $form_state->setErrorByName('book_child_type', $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => $this->t('Add child page'))));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $embed_provider = $form_state->getValue('embed_provider');
     $this->prepareEmbedProviderValidation($embed_provider);
     if (!URLHelper::isValid($embed_provider, TRUE)) {
         $form_state->setErrorByName('embed_provider', $this->t('The provider url was not valid.'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $email = $form_state->getValue('email');
     $is_email_valid = \Drupal::service('email.validator')->isValid($email);
     if (!$is_email_valid) {
         $form_state->setErrorByName('email', $this->t('Please enter a valid e-mail address.'));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // If the user selected a granularity, let's make sure they
     // also selected a duration.
     if ($form_state->getValue('reminder_granularity') != 'never' && $form_state->getValue('reminder_length') < 1) {
         $form_state->setErrorByName('reminder_length', $this->t('You set the granularity (%gran), but you did not set how many. Please enter a positive non-zero integer.', ['%gran' => $form_state->getValue('reminder_granularity') . '(s)']));
     }
     return parent::validateForm($form, $form_state);
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $config_text = $form_state->getValue('config') ?: 'attributes:';
     try {
         $form_state->set('config', Yaml::decode($config_text));
     } catch (InvalidDataTypeException $e) {
         $form_state->setErrorByName('config', $e->getMessage());
     }
     parent::validateForm($form, $form_state);
 }
Beispiel #20
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $result = $this->zoho_generate_authtoken($form_state->getValue('zoho_username_email'), $form_state->getValue('zoho_password'));
     if (isset($result['authtoken'])) {
         drupal_set_message(t('Successfully generated a new Authtoken : :token', array(':token' => $result['authtoken'])));
         $form_state->setValue('zoho_api_authtoken', $result['authtoken']);
     } else {
         form_set_error(t('There was an error: :error.<br/>Please resolve the error and try again.', array(':error' => $result['error'])), 'error');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     foreach (array('auto_import', 'auto_export') as $key) {
         $form_state->setValue($key, array_filter(preg_split("/\r\n/", $form_state->getValues()[$key])));
     }
     foreach ($form_state->getValues()['auto_import'] as $file) {
         $name = basename($file, '.' . FileStorage::getFileExtension());
         if (in_array($name, array('system.site', 'core.extension', 'simpletest.settings'))) {
             $form_state->setErrorByName('auto_import', $this->t('@name is not compatible with this module', array('@name' => $name)));
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Accept maximum two class value for the selector field.
     $limit = $form_state->getValue('autofloat_span');
     if (substr_count($limit, ',') > 1) {
         $form_state->setErrorByName('autofloat_span', $this->t('Not more than two values.'));
     }
     // Accept maximum two class value for the rejector field.
     $limit = $form_state->getValue('autofloat_div');
     if (substr_count($limit, ',') > 1) {
         $form_state->setErrorByName('autofloat_div', $this->t('Not more than two values.'));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('simpletest.settings');
     // If a username was provided but a password wasn't, preserve the existing
     // password.
     if (!empty($form_state['values']['simpletest_httpauth_username']) && empty($form_state['values']['simpletest_httpauth_password'])) {
         $form_state['values']['simpletest_httpauth_password'] = $config->get('httpauth.password');
     }
     // If a password was provided but a username wasn't, the credentials are
     // incorrect, so throw an error.
     if (empty($form_state['values']['simpletest_httpauth_username']) && !empty($form_state['values']['simpletest_httpauth_password'])) {
         $form_state->setErrorByName('simpletest_httpauth_username', $this->t('HTTP authentication credentials must include a username in addition to a password.'));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $messages = (string) $form_state->getValue('uc_cart_links_messages');
     if (!empty($messages)) {
         $data = explode("\n", $messages);
         foreach ($data as $message) {
             // Ignore blank lines.
             if (preg_match('/^\\s*$/', $message)) {
                 continue;
             } elseif (!preg_match('/^\\s*[1-9][0-9]*\\s*\\|\\s*\\S+.*$/', $message)) {
                 $form_state->setErrorByName('uc_cart_links_messages', $this->t('Invalid Cart Links message "%message". Messages must be a numeric key followed by "|" followed by a value.', ['%message' => $message]));
                 break;
             }
         }
     }
     return parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     // Validate menu class on special chars.
     $menu_class = $form_state->getValue('menuclass');
     if (preg_match('/[^A-Za-z0-9#.-]/', $menu_class)) {
         $form_state->setErrorByName('menuclass', t('"Menu Class/Id" contains forbidden chars. Only a-z, #, ., - allowed.'));
     }
     // Validate class on non alphapetic chars.
     $class = $form_state->getValue('class');
     if (preg_match('/[^A-Za-z0-9-]/', $class)) {
         $form_state->setErrorByName('class', t('"Menu item selector"  contains forbidden chars. Only a-z, - allowed.'));
     }
     // Validate tag on special chars.
     $tag = $form_state->getValue('tag');
     if (preg_match('/[^A-Za-z0-9]/', $tag)) {
         $form_state->setErrorByName('tag', t('"Tag" contains special characters.'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Make sure our base directory is valid.
     if (!$form_state->isValueEmpty('base_dir') && !is_dir($form_state->getValue('base_dir'))) {
         $form_state->setErrorByName('base_dir', $this->t('%dir is not a valid file or directory', ['%dir' => $form_state->getValue('base_dir')]));
     }
     // If the user selected a granularity, let's make sure they
     // also selected a duration.
     if ($form_state->getValue('download_limit_duration_granularity') != 'never' && $form_state->getValue('download_limit_duration_qty') < 1) {
         $form_state->setErrorByName('download_limit_duration_qty', $this->t('You set the granularity (%gran), but you did not set how many. Please enter a positive non-zero integer.', ['%gran' => $form_state->getValue('download_limit_duration_granularity') . '(s)']));
     }
     // Make sure the download limit makes sense.
     if ($form_state->getValue('download_limit_number') < 0) {
         $form_state->setErrorByName('download_limit_number', $this->t('A negative download limit does not make sense. Please enter a positive integer, or leave empty for no limit.'));
     }
     // Make sure the address limit makes sense.
     if ($form_state->getValue('download_limit_addresses') < 0) {
         $form_state->setErrorByName('download_limit_addresses', $this->t('A negative IP address limit does not make sense. Please enter a positive integer, or leave empty for no limit.'));
     }
     return parent::validateForm($form, $form_state);
 }
 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $languages = language_list();
     // Count repeated values for uniqueness check.
     $count = array_count_values($form_state->getValue('prefix'));
     foreach ($languages as $langcode => $language) {
         $value = $form_state->getValue(array('prefix', $langcode));
         if ($value === '') {
             if (!$language->isDefault() && $form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) {
                 // Throw a form error if the prefix is blank for a non-default language,
                 // although it is required for selected negotiation type.
                 $form_state->setErrorByName("prefix][{$langcode}", $this->t('The prefix may only be left blank for the default language.'));
             }
         } elseif (strpos($value, '/') !== FALSE) {
             // Throw a form error if the string contains a slash,
             // which would not work.
             $form_state->setErrorByName("prefix][{$langcode}", $this->t('The prefix may not contain a slash.'));
         } elseif (isset($count[$value]) && $count[$value] > 1) {
             // Throw a form error if there are two languages with the same
             // domain/prefix.
             $form_state->setErrorByName("prefix][{$langcode}", $this->t('The prefix for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value)));
         }
     }
     // Count repeated values for uniqueness check.
     $count = array_count_values($form_state->getValue('domain'));
     foreach ($languages as $langcode => $language) {
         $value = $form_state->getValue(array('domain', $langcode));
         if ($value === '') {
             if ($form_state->getValue('language_negotiation_url_part') == LanguageNegotiationUrl::CONFIG_DOMAIN) {
                 // Throw a form error if the domain is blank for a non-default language,
                 // although it is required for selected negotiation type.
                 $form_state->setErrorByName("domain][{$langcode}", $this->t('The domain may not be left blank for %language.', array('%language' => $language->name)));
             }
         } elseif (isset($count[$value]) && $count[$value] > 1) {
             // Throw a form error if there are two languages with the same
             // domain/domain.
             $form_state->setErrorByName("domain][{$langcode}", $this->t('The domain for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value)));
         }
     }
     // Domain names should not contain protocol and/or ports.
     foreach ($languages as $langcode => $name) {
         $value = $form_state->getValue(array('domain', $langcode));
         if (!empty($value)) {
             // Ensure we have exactly one protocol when checking the hostname.
             $host = 'http://' . str_replace(array('http://', 'https://'), '', $value);
             if (parse_url($host, PHP_URL_HOST) != $value) {
                 $form_state->setErrorByName("domain][{$langcode}", $this->t('The domain for %language may only contain the domain name, not a protocol and/or port.', array('%language' => $name)));
             }
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
 }
Beispiel #29
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Check for empty front page path.
     if ($form_state->isValueEmpty('site_frontpage')) {
         // Set to default "user/login".
         $form_state->setValueForElement($form['front_page']['site_frontpage'], '/user/login');
     } else {
         // Get the normal path of the front page.
         $form_state->setValueForElement($form['front_page']['site_frontpage'], $this->aliasManager->getPathByAlias($form_state->getValue('site_frontpage')));
     }
     // Validate front page path.
     if (($value = $form_state->getValue('site_frontpage')) && $value[0] !== '/') {
         $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_frontpage')]));
     }
     if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) {
         $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_frontpage'))));
     }
     // Get the normal paths of both error pages.
     if (!$form_state->isValueEmpty('site_403')) {
         $form_state->setValueForElement($form['error_page']['site_403'], $this->aliasManager->getPathByAlias($form_state->getValue('site_403')));
     }
     if (!$form_state->isValueEmpty('site_404')) {
         $form_state->setValueForElement($form['error_page']['site_404'], $this->aliasManager->getPathByAlias($form_state->getValue('site_404')));
     }
     if (($value = $form_state->getValue('site_403')) && $value[0] !== '/') {
         $form_state->setErrorByName('site_403', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_403')]));
     }
     if (($value = $form_state->getValue('site_404')) && $value[0] !== '/') {
         $form_state->setErrorByName('site_404', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_404')]));
     }
     // Validate 403 error path.
     if (!$form_state->isValueEmpty('site_403') && !$this->pathValidator->isValid($form_state->getValue('site_403'))) {
         $form_state->setErrorByName('site_403', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_403'))));
     }
     // Validate 404 error path.
     if (!$form_state->isValueEmpty('site_404') && !$this->pathValidator->isValid($form_state->getValue('site_404'))) {
         $form_state->setErrorByName('site_404', $this->t("The path '%path' is either invalid or you do not have access to it.", array('%path' => $form_state->getValue('site_404'))));
     }
     parent::validateForm($form, $form_state);
 }
Beispiel #30
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     // Let active plugins validate their settings.
     foreach ($this->configurableInstances as $instance) {
         $instance->validateConfigurationForm($form, $form_state);
     }
 }