示例#1
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     $entity = $this->entity;
     // Check to prevent a duplicate title.
     if ($form_state['values']['label'] != $entity->label() && shortcut_set_title_exists($form_state['values']['label'])) {
         $form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label'])));
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, array &$form_state)
 {
     if ($form_state['values']['set'] == 'new') {
         // Check to prevent creating a shortcut set with an empty title.
         if (trim($form_state['values']['label']) == '') {
             $this->setFormError('new', $form_state, $this->t('The new set label is required.'));
         }
         // Check to prevent a duplicate title.
         if (shortcut_set_title_exists($form_state['values']['label'])) {
             $this->setFormError('label', $form_state, $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label'])));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('set') == 'new') {
         // Check to prevent creating a shortcut set with an empty title.
         if (trim($form_state->getValue('label')) == '') {
             $form_state->setErrorByName('new', $this->t('The new set label is required.'));
         }
         // Check to prevent a duplicate title.
         if (shortcut_set_title_exists($form_state->getValue('label'))) {
             $form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state->getValue('label'))));
         }
     }
 }