/**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     if (!$this->pathValidator->isValid($form_state->getValue('path'))) {
         $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.'));
     }
     parent::validate($form, $form_state);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     if (!shortcut_valid_link($form_state['values']['path'])) {
         $form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.'));
     }
     parent::validate($form, $form_state);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, array &$form_state)
 {
     parent::validate($form, $form_state);
     // Ensure numeric values.
     if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) {
         $this->setFormError('weight', $form_state, $this->t('Weight value must be numeric.'));
     }
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Ensure numeric values.
     if ($form_state->hasValue('weight') && !is_numeric($form_state->getValue('weight'))) {
         $form_state->setErrorByName('weight', $this->t('Weight value must be numeric.'));
     }
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $order = $this->buildEntity($form, $form_state);
     if ($form_state->getValue('order_modified') != $order->modified->value) {
         $form_state->setErrorByName('order_modified', t('This order has been modified by another user, changes cannot be saved.'));
     }
     parent::validate($form, $form_state);
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     /* @var \Drupal\crm_core_activity\Entity\Activity $activity */
     $activity = $this->buildEntity($form, $form_state);
     if ($activity->get('activity_participants')->isEmpty()) {
         $message = $this->t('Participants field should include at least one participant.');
         $form_state->setErrorByName('activity_participants', $message);
     }
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $feed = $this->buildEntity($form, $form_state);
     // Check for duplicate titles.
     $feed_storage = $this->entityManager->getStorage('aggregator_feed');
     $result = $feed_storage->getFeedDuplicates($feed);
     foreach ($result as $item) {
         if (strcasecmp($item->label(), $feed->label()) == 0) {
             $form_state->setErrorByName('title', $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
         }
         if (strcasecmp($item->getUrl(), $feed->getUrl()) == 0) {
             $form_state->setErrorByName('url', $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->getUrl())));
         }
     }
     parent::validate($form, $form_state);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $node = parent::validate($form, $form_state);
     if ($node->id() && node_last_changed($node->id()) > $node->getChangedTimeAcrossTranslations()) {
         $form_state->setErrorByName('changed', $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
     }
     return $node;
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $this->doValidate($form, $form_state);
     parent::validate($form, $form_state);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     $account = $this->entity;
     // Validate new or changing username.
     if (isset($form_state['values']['name'])) {
         if ($error = user_validate_name($form_state['values']['name'])) {
             $form_state->setErrorByName('name', $error);
         } else {
             $name_taken = (bool) $this->entityQuery->get('user')->condition('uid', (int) $account->id(), '<>')->condition('name', $form_state['values']['name'])->range(0, 1)->count()->execute();
             if ($name_taken) {
                 $form_state->setErrorByName('name', $this->t('The name %name is already taken.', array('%name' => $form_state['values']['name'])));
             }
         }
     }
     $mail = $form_state['values']['mail'];
     if (!empty($mail)) {
         $mail_taken = (bool) $this->entityQuery->get('user')->condition('uid', (int) $account->id(), '<>')->condition('mail', $mail)->range(0, 1)->count()->execute();
         if ($mail_taken) {
             // Format error message dependent on whether the user is logged in or not.
             if (\Drupal::currentUser()->isAuthenticated()) {
                 $form_state->setErrorByName('mail', $this->t('The email address %email is already taken.', array('%email' => $mail)));
             } else {
                 $form_state->setErrorByName('mail', $this->t('The email address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $mail, '@password' => url('user/password'))));
             }
         }
     }
     // Make sure the signature isn't longer than the size of the database field.
     // Signatures are disabled by default, so make sure it exists first.
     if (isset($form_state['values']['signature'])) {
         // Move text format for user signature into 'signature_format'.
         $form_state['values']['signature_format'] = $form_state['values']['signature']['format'];
         // Move text value for user signature into 'signature'.
         $form_state['values']['signature'] = $form_state['values']['signature']['value'];
         // @todo Make the user signature field use a widget to benefit from
         //   automatic typed data validation in https://drupal.org/node/2227381.
         $field_definitions = $this->entityManager->getFieldDefinitions('user', $this->getEntity()->bundle());
         $max_length = $field_definitions['signature']->getSetting('max_length');
         if (drupal_strlen($form_state['values']['signature']) > $max_length) {
             $form_state->setErrorByName('signature', $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $max_length)));
         }
     }
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, array &$form_state)
 {
     $this->doValidate($form, $form_state);
     parent::validate($form, $form_state);
 }
Ejemplo n.º 12
0
 /**
  * Overrides Drupal\Core\Entity\EntityForm::validate().
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     $entity = $this->entity;
     if (!$entity->isNew()) {
         // Verify the name in case it is being changed from being anonymous.
         $accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state->getValue('name')));
         $account = reset($accounts);
         $form_state->setValue('uid', $account ? $account->id() : 0);
         $date = $form_state->getValue('date');
         if ($date instanceof DrupalDateTime && $date->hasErrors()) {
             $form_state->setErrorByName('date', $this->t('You have to specify a valid date.'));
         }
         if ($form_state->getValue('name') && !$form_state->getValue('is_anonymous') && !$account) {
             $form_state->setErrorByName('name', $this->t('You have to specify a valid author.'));
         }
     } elseif ($form_state->getValue('is_anonymous')) {
         // Validate anonymous comment author fields (if given). If the (original)
         // author of this comment was an anonymous user, verify that no registered
         // user with this name exists.
         if ($form_state->getValue('name')) {
             $accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state->getValue('name')));
             if (!empty($accounts)) {
                 $form_state->setErrorByName('name', $this->t('The name you used belongs to a registered user.'));
             }
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $node = $this->buildEntity($form, $form_state);
     if ($node->id() && node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime()) {
         $form_state->setErrorByName('changed', $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
     }
     // Invoke hook_node_validate() for validation needed by modules.
     // Can't use \Drupal::moduleHandler()->invokeAll(), because $form_state must
     // be receivable by reference.
     foreach (\Drupal::moduleHandler()->getImplementations('node_validate') as $module) {
         $function = $module . '_node_validate';
         $function($node, $form, $form_state);
     }
     parent::validate($form, $form_state);
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $comment = parent::validate($form, $form_state);
     // Customly trigger validation of manually added fields and add in
     // violations.
     $violations = $comment->created->validate();
     foreach ($violations as $violation) {
         $form_state->setErrorByName('date', $violation->getMessage());
     }
     $violations = $comment->validate();
     // Filter out violations for the name path.
     foreach ($violations as $violation) {
         if ($violation->getPropertyPath() === 'name') {
             $form_state->setErrorByName('name', $violation->getMessage());
         }
     }
     return $comment;
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     $message = $this->entity;
     // Check if flood control has been activated for sending emails.
     if (!$this->currentUser()->hasPermission('administer contact forms') && (!$message->isPersonal() || !$this->currentUser()->hasPermission('administer users'))) {
         $limit = $this->config('contact.settings')->get('flood.limit');
         $interval = $this->config('contact.settings')->get('flood.interval');
         if (!$this->flood->isAllowed('contact', $limit, $interval)) {
             $form_state->setErrorByName('', $this->t('You cannot send more than %limit messages in @interval. Try again later.', array('%limit' => $limit, '@interval' => $this->dateFormatter->formatInterval($interval))));
         }
     }
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\user\UserInterface $account */
     $account = parent::validate($form, $form_state);
     // Skip the protected user field constraint if the user came from the
     // password recovery page.
     $account->_skipProtectedUserFieldConstraint = $form_state->get('user_pass_reset');
     // Customly trigger validation of manually added fields and add in
     // violations. This is necessary as entity form displays only invoke entity
     // validation for fields contained in the display.
     $field_names = array('name', 'pass', 'mail', 'timezone', 'langcode', 'preferred_langcode', 'preferred_admin_langcode');
     foreach ($field_names as $field_name) {
         $violations = $account->{$field_name}->validate();
         foreach ($violations as $violation) {
             $form_state->setErrorByName($field_name, $violation->getMessage());
         }
     }
     return $account;
 }
Ejemplo n.º 17
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\user\UserInterface $account */
     $account = parent::validate($form, $form_state);
     // Customly trigger validation of manually added fields and add in
     // violations. This is necessary as entity form displays only invoke entity
     // validation for fields contained in the display.
     $field_names = array('name', 'mail', 'timezone', 'langcode', 'preferred_langcode', 'preferred_admin_langcode');
     foreach ($field_names as $field_name) {
         $violations = $account->{$field_name}->validate();
         foreach ($violations as $violation) {
             $form_state->setErrorByName($field_name, $violation->getMessage());
         }
     }
     return $account;
 }
Ejemplo n.º 18
0
 /**
  * Overrides Drupal\Core\Entity\EntityForm::validate().
  */
 public function validate(array $form, array &$form_state)
 {
     $node = $this->buildEntity($form, $form_state);
     if ($node->id() && node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime()) {
         $this->setFormError('changed', $form_state, $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
     }
     // Validate the "authored by" field.
     if (!empty($form_state['values']['uid']) && !user_load_by_name($form_state['values']['uid'])) {
         // The use of empty() is mandatory in the context of usernames
         // as the empty string denotes the anonymous user. In case we
         // are dealing with an anonymous user we set the user ID to 0.
         $this->setFormError('uid', $form_state, $this->t('The username %name does not exist.', array('%name' => $form_state['values']['uid'])));
     }
     // Validate the "authored on" field.
     // The date element contains the date object.
     $date = $node->date instanceof DrupalDateTime ? $node->date : new DrupalDateTime($node->date);
     if ($date->hasErrors()) {
         $this->setFormError('date', $form_state, $this->t('You have to specify a valid date.'));
     }
     // Invoke hook_node_validate() for validation needed by modules.
     // Can't use \Drupal::moduleHandler()->invokeAll(), because $form_state must
     // be receivable by reference.
     foreach (\Drupal::moduleHandler()->getImplementations('node_validate') as $module) {
         $function = $module . '_node_validate';
         $function($node, $form, $form_state);
     }
     parent::validate($form, $form_state);
 }