/**
  * Form validation handler.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 public function validatePathClear(array &$form, FormStateInterface $form_state)
 {
     $raw_paths = $form_state->getValue('paths');
     $paths = explode('\\n', $raw_paths);
     $exceeds_allowed_max_purges = count($paths) > ZoneApi::MAX_PURGES_PER_REQUEST;
     if ($exceeds_allowed_max_purges) {
         $form_state->setErrorByName('paths', $this->t('Unfortunately you entered more than the maximum number of requests. The CloudFlare api limits you to ' . ZoneApi::MAX_PURGES_PER_REQUEST . 'paths per request.'));
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $bam = backup_migrate_get_service_object($form_state->getValues());
     // Let the plugins validate their own config data.
     if ($plugin_errors = $bam->plugins()->map('configErrors', array('operation' => 'backup'))) {
         foreach ($plugin_errors as $plugin_key => $errors) {
             foreach ($errors as $error) {
                 $form_state->setErrorByName($plugin_key . '][' . $error->getFieldKey(), $this->t($error->getMessage(), $error->getReplacement()));
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     $collection = Rdf::load($form_state->getValue('collection_id'));
     // Only authenticated users can join a collection.
     /** @var \Drupal\user\UserInterface $user */
     $user = User::load($form_state->getValue('user_id'));
     if ($user->isAnonymous()) {
         $form_state->setErrorByName('user', $this->t('<a href=":login">Log in</a> or <a href=":register">register</a> to change your group membership.', [':login' => Url::fromRoute('user.login'), ':register' => Url::fromRoute('user.register')]));
     }
     // Check if the user is already a member of the collection.
     if (Og::isMember($collection, $user)) {
         $form_state->setErrorByName('collection', $this->t('You already are a member of this collection.'));
     }
 }
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $values = $form_state->getValues();
     if (!empty($values['password'])) {
         /**
          * @var \Drupal\Core\Use
          */
         $account = User::load(\Drupal::currentUser()->id());
         /**
          * @var \Drupal\user\MigratePassword $passwordService
          */
         $passwordService = \Drupal::service('password');
         if (!$passwordService->check(trim($values['password']), $account->getPassword())) {
             $form_state->setErrorByName('password', $this->t('Password is invalid'));
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     // Only the "Index now" action needs any validation.
     if ($form_state->getTriggeringElement()['#name'] === 'index_now') {
         $values = $form_state->getValues();
         // Get the translated "all" value and lowercase it for comparison.
         $all_value = Unicode::strtolower($values['all']);
         foreach (array('limit', 'batch_size') as $field) {
             // Trim and lowercase the value so we correctly identify "all" values,
             // even if not matching exactly.
             $value = Unicode::strtolower(trim($values[$field]));
             if ($value === $all_value) {
                 $value = -1;
             } elseif (!$value || !is_numeric($value) || (int) $value != $value) {
                 $form_state->setErrorByName($field, $this->t('Enter a non-zero integer. Use "-1" or "@all" for "all items".', array('@all' => $values['all'])));
             } else {
                 $value = (int) $value;
             }
             $form_state->setValue($field, $value);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $config = \Drupal::config('simplenews.settings');
     $values = $form_state->getValues();
     // Validate recipient handler settings.
     if (!empty($form['recipient_handler_settings'])) {
         $handler = $values['recipient_handler'];
         $handler_definitions = \Drupal::service('plugin.manager.simplenews_recipient_handler')->getDefinitions();
         // Get the handler class.
         $handler = $handler_definitions[$handler];
         $class = $handler['class'];
         if (method_exists($class, 'settingsFormValidate')) {
             $class::settingsFormValidate($form['recipient_handler_settings'], $form_state);
         }
     }
     parent::validateForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
     if ($form_state->get('step') == 'select') {
         $this->validateSelectStep($form, $form_state);
     } elseif ($form_state->get('step') == 'embed') {
         $this->validateEmbedStep($form, $form_state);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     parent::validateForm($form, $form_state);
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $name = $form_state->getValue('name');
     if (Unicode::strlen($name) > 64) {
         $form_state->setErrorByName('name', $this->t('The name cannot be longer than 64 characters.'));
     }
     $phone = $form_state->getValue('phone');
     if (Unicode::strlen($phone) > 64) {
         $form_state->setErrorByName('phone', $this->t('The phone cannot be longer than 64 characters.'));
     } else {
         // Validate phone uniqueness amongst all (other) entries.
         $query = $this->connection->select('phonebook', 'p')->fields('p', ['pbid']);
         $query->condition('phone', $phone);
         if ($pbid = $form_state->getValue('pbid')) {
             $query->condition('pbid', $pbid, '<>');
         }
         $result = $query->execute()->fetchObject();
         if ($result) {
             $form_state->setErrorByName('phone', $this->t('The phone must be unique.'));
         }
     }
     parent::validateForm($form, $form_state);
 }