Esempio n. 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'])));
     }
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     $id = trim($form_state->getValue('type'));
     // '0' is invalid, since elsewhere we check it using empty().
     if ($id == '0') {
         $form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id)));
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     $toolbar =& $form_state->getValue(array('settings', 'toolbar'));
     // Convert toolbar to array.
     if (is_string($toolbar)) {
         $toolbar = array_values(array_filter(array_map('trim', explode(',', $toolbar))));
     }
     \Drupal::service('plugin.manager.medium.plugin')->validateEditorForm($form, $form_state, $this->getEntity());
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     $rate = $form_state->getValue('rate');
     $rate = trim($rate);
     // @TODO Would be nice to better validate rate, maybe with preg_match
     if (floatval($rate) < 0) {
         $form_state->setErrorByName('rate', $this->t('Rate must be a positive number. No commas and only one decimal point.'));
     }
     // Save trimmed rate back to form if it passes validation.
     $form_state->setValue('rate', $rate);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Validate and each email recipient.
     $recipients = explode(',', $form_state->getValue('recipients'));
     foreach ($recipients as &$recipient) {
         $recipient = trim($recipient);
         if (!$this->emailValidator->isValid($recipient)) {
             $form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
         }
     }
     $form_state->setValue('recipients', $recipients);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Validate and each email recipient.
     $recipients = explode(',', $form_state['values']['recipients']);
     foreach ($recipients as &$recipient) {
         $recipient = trim($recipient);
         if (!valid_email_address($recipient)) {
             $form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
         }
     }
     $form_state['values']['recipients'] = $recipients;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Disallow adding an address format for a country that already has one.
     if ($this->entity->isNew()) {
         $country = $form_state->getValue('countryCode');
         if ($this->storage->load($country)) {
             $form_state->setErrorByName('countryCode', $this->t('The selected country already has an address format.'));
         }
     }
     // Require the matching type field for the fields specified in the format.
     $format = $form_state->getValue('format');
     $requirements = ['%postalCode' => 'postalCodeType', '%dependentLocality' => 'dependentLocalityType', '%locality' => 'localityType', '%administrativeArea' => 'administrativeAreaType'];
     foreach ($requirements as $token => $required_field) {
         if (strpos($format, $token) !== FALSE && !$form_state->getValue($required_field)) {
             $title = $form[$required_field]['#title'];
             $form_state->setErrorByName($required_field, $this->t('%title is required.', ['%title' => $title]));
         }
     }
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     if (isset($form['default_value'])) {
         $item = $form['#entity']->get($this->entity->getName());
         $item->defaultValuesFormValidate($form['default_value'], $form, $form_state);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // @todo Move trimming upstream.
     $format_format = trim($form_state->getValue('format'));
     $format_name = trim($form_state->getValue('name'));
     // Ensure that the values to be saved later are exactly the ones validated.
     $form_state->setValueForElement($form['format'], $format_format);
     $form_state->setValueForElement($form['name'], $format_name);
     $format_exists = $this->queryFactory->get('filter_format')->condition('format', $format_format, '<>')->condition('name', $format_name)->execute();
     if ($format_exists) {
         $form_state->setErrorByName('name', $this->t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));
     }
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     if ($this->plugin instanceof PluginFormInterface) {
         $this->plugin->validateConfigurationForm($form, $form_state);
     }
 }
Esempio n. 11
0
 /**
  * Overrides EntityForm::validate().
  */
 public function validate(array $form, array &$form_state)
 {
     $menu_link = $this->buildEntity($form, $form_state);
     $normal_path = $this->pathAliasManager->getPathByAlias($menu_link->link_path);
     if ($menu_link->link_path != $normal_path) {
         drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $menu_link->link_path, '%normal_path' => $normal_path)));
         $menu_link->link_path = $normal_path;
         $form_state['values']['link_path'] = $normal_path;
     }
     if (!UrlHelper::isExternal($menu_link->link_path)) {
         $parsed_link = parse_url($menu_link->link_path);
         if (isset($parsed_link['query'])) {
             $menu_link->options['query'] = array();
             parse_str($parsed_link['query'], $menu_link->options['query']);
         } else {
             // Use unset() rather than setting to empty string
             // to avoid redundant serialized data being stored.
             unset($menu_link->options['query']);
         }
         if (isset($parsed_link['fragment'])) {
             $menu_link->options['fragment'] = $parsed_link['fragment'];
         } else {
             unset($menu_link->options['fragment']);
         }
         if (isset($parsed_link['path']) && $menu_link->link_path != $parsed_link['path']) {
             $menu_link->link_path = $parsed_link['path'];
         }
     }
     if (!trim($menu_link->link_path) || !drupal_valid_path($menu_link->link_path, TRUE)) {
         $this->setFormError('link_path', $form_state, $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $menu_link->link_path)));
     }
     parent::validate($form, $form_state);
 }
Esempio n. 12
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // The machine name field should already check to see if the requested
     // machine name is available. Regardless of machine_name or human readable
     // name, check to see if the provided pattern exists.
     $pattern = trim($form_state->getValue('date_format_pattern'));
     foreach ($this->dateFormatStorage->loadMultiple() as $format) {
         if ($format->getPattern() == $pattern && ($this->entity->isNew() || $format->id() != $this->entity->id())) {
             $form_state->setErrorByName('date_format_pattern', $this->t('This format already exists. Enter a unique format string.'));
             continue;
         }
     }
 }
Esempio n. 13
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // The Block Entity form puts all block plugin form elements in the
     // settings form element, so just pass that to the block for validation.
     $settings = new FormState(array('values' => $form_state['values']['settings']));
     // Call the plugin validate handler.
     $this->entity->getPlugin()->validateConfigurationForm($form, $settings);
     // Update the original form values.
     $form_state['values']['settings'] = $settings['values'];
 }
Esempio n. 14
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     if ($form_state->getErrors()) {
         return;
     }
     $values =& $form_state->getValues();
     // Moved advanced settings to regular settings.
     foreach (array_keys($this->entity->getPlugins()) as $type) {
         if (isset($values[$type . '_wrapper']['advanced'])) {
             if (!isset($values[$type . '_configuration'])) {
                 $values[$type . '_configuration'] = [];
             }
             $values[$type . '_configuration'] += $values[$type . '_wrapper']['advanced'];
         }
         unset($values[$type . '_wrapper']);
     }
     foreach ($this->getConfigurablePlugins() as $type => $plugin) {
         $plugin_state = $this->createSubFormState($type . '_configuration', $form_state);
         $plugin->validateConfigurationForm($form[$type . '_configuration'], $plugin_state);
         $form_state->setValue($type . '_configuration', $plugin_state->getValues());
         $this->moveFormStateErrors($plugin_state, $form_state);
     }
     // Build the feed type object from the submitted values.
     parent::validate($form, $form_state);
 }
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $this->doValidate($form, $form_state);
     parent::validate($form, $form_state);
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // The Block Entity form puts all block plugin form elements in the
     // settings form element, so just pass that to the block for validation.
     $settings = (new FormState())->setValues($form_state->getValue('settings'));
     // Call the plugin validate handler.
     $this->entity->getPlugin()->validateConfigurationForm($form, $settings);
     // Update the original form values.
     $form_state->setValue('settings', $settings->getValues());
     $this->validateVisibility($form, $form_state);
 }
 /**
  * Overrides Drupal\Core\Entity\EntityFormController::validate().
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   An associative array containing the current state of the form.
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Add code here to validate your config entity's form elements.
     // Nothing to do here.
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, array &$form_state)
 {
     parent::validate($form, $form_state);
     // The Block Entity form puts all block plugin form elements in the
     // settings form element, so just pass that to the block for validation.
     $settings = array('values' => &$form_state['values']['settings']);
     // Call the plugin validate handler.
     $this->entity->getPlugin()->validateConfigurationForm($form, $settings);
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, array &$form_state)
 {
     parent::validate($form, $form_state);
     // @todo Move trimming upstream.
     $format_format = trim($form_state['values']['format']);
     $format_name = trim($form_state['values']['name']);
     // Ensure that the values to be saved later are exactly the ones validated.
     form_set_value($form['format'], $format_format, $form_state);
     form_set_value($form['name'], $format_name, $form_state);
     $format_exists = $this->queryFactory->get('filter_format')->condition('format', $format_format, '<>')->condition('name', $format_name)->execute();
     if ($format_exists) {
         $this->setFormError('name', $form_state, $this->t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));
     }
 }
Esempio n. 20
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Ensure each path is unique.
     $path = $this->entityQuery->get('search_page')->condition('path', $form_state['values']['path'])->condition('id', $form_state['values']['id'], '<>')->execute();
     if ($path) {
         $form_state->setErrorByName('path', $this->t('The search page path must be unique.'));
     }
     if ($this->plugin instanceof PluginFormInterface) {
         $this->plugin->validateConfigurationForm($form, $form_state);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     parent::validate($form, $form_state);
     // Validate field cardinality.
     if ($form_state->getValue('cardinality') === 'number' && !$form_state->getValue('cardinality_number')) {
         $form_state->setErrorByName('cardinality_number', $this->t('Number of values is required.'));
     }
 }