/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { if ($form_state->getValue('stateFrom') === $form_state->getValue('stateTo')) { $form_state->setErrorByName('stateTo', $this->t('You cannot use the same state for both from and to.')); } parent::validateForm($form, $form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($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 validateForm(array &$form, FormStateInterface $form_state) { // Only run key provider settings validation if the form is being submitted if ($form_state->isSubmitted()) { $plugin = $this->manager->createInstance($form_state->getValue('key_provider'), []); $plugin->validateConfigurationForm($form, $form_state); } parent::validateForm($form, $form_state); }
/** * Validates the values. */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $values = $form_state->getValues(); // Require non-empty ID. $id = trim($values['id']); if (empty($id)) { $form_state->setErrorByName('id', $this->t('Subtype names must not be empty')); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($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); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // The machine name field should already check to see if the requested // machine name is available. $pattern = trim($form_state->getValue('date_format_pattern')); foreach ($this->dateFormatStorage->loadMultiple() as $format) { if ($format->getPattern() == $pattern && $format->id() == $this->entity->id()) { drupal_set_message(t('The existing format/name combination has not been altered.')); continue; } } }
/** * {@inheritdoc} * * Button-level validation handlers are highly discouraged for entity forms, * as they will prevent entity validation from running. If the entity is going * to be saved during the form submission, this method should be manually * invoked from the button-level validation handler, otherwise an exception * will be thrown. */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */ $entity = $this->buildEntity($form, $form_state); $violations = $entity->validate(); // Remove violations of inaccessible fields and not edited fields. $violations->filterByFieldAccess($this->currentUser())->filterByFields(array_diff(array_keys($entity->getFieldDefinitions()), $this->getEditedFieldNames($form_state))); $this->flagViolations($violations, $form, $form_state); // The entity was validated. $entity->setValidationRequired(FALSE); $form_state->setTemporaryValue('entity_validated', TRUE); return $entity; }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); /** @var \Drupal\crm_core_match\Matcher\MatcherConfigInterface $matcher */ $matcher = $this->entity; /** @var \Drupal\crm_core_match\Plugin\crm_core_match\engine\MatchEngineInterface $plugin */ if ($matcher->isNew()) { $plugin_id = $form_state->getValue('plugin_id'); $plugin = crm_core_match_matcher_manager()->createInstance($plugin_id, $matcher->getConfiguration()); } else { $plugin = $matcher->getPlugin(); } $plugin->validateConfigurationForm($form, $form_state); }
public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $code = $form_state->getValue('code'); $return = $this->serializer->deserializeForm($code); $fillpdf_form = $return['form']; $fields = $return['fields']; if (!is_object($fillpdf_form) || !count($fields)) { $form_state->setErrorByName('code', $this->t('There was a problem processing your FillPDF form code. Please do a fresh export from the source and try pasting it again.')); } else { $form_state->setValue('mappings', [ 'form' => $fillpdf_form, 'fields' => $fields, ]); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($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); $redirect_url = $form_state->getValue('redirect'); if ($redirect_url && $this->pathValidator->isValid($redirect_url)) { if (Unicode::substr($redirect_url, 0, 1) !== '/') { $form_state->setErrorByName('redirect', $this->t('The path should start with /.')); } } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $this->plugin->validateConfigurationForm($form['settings'], $form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // Only validate on edit. if ($form_state->hasValue('keyed_styles')) { // Check if another breakpoint group is selected. if ($form_state->getValue('breakpoint_group') != $form_state->getCompleteForm()['breakpoint_group']['#default_value']) { // Remove the image style mappings since the breakpoint ID has changed. $form_state->unsetValue('keyed_styles'); } // Check that at least 1 image style has been selected when using sizes. foreach ($form_state->getValue('keyed_styles') as $breakpoint_id => $multipliers) { foreach ($multipliers as $multiplier => $image_style_mapping) { if ($image_style_mapping['image_mapping_type'] === 'sizes') { if (empty($image_style_mapping['sizes'])) { $form_state->setError($form['keyed_styles'][$breakpoint_id][$multiplier]['sizes'], 'Provide a value for the sizes attribute.'); } if (empty(array_keys(array_filter($image_style_mapping['sizes_image_styles'])))) { $form_state->setError($form['keyed_styles'][$breakpoint_id][$multiplier]['sizes_image_styles'], 'Select at least one image style.'); } } } } } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($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))); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($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))); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $facet_source_id = $form_state->getValue('facet_source_id'); if (!is_null($facet_source_id) && $facet_source_id !== '') { /** @var \Drupal\facets\FacetSource\FacetSourcePluginInterface $facet_source */ $facet_source = $this->getFacetSourcePluginManager()->createInstance($facet_source_id, ['facet' => $this->getEntity()]); $facet_source->validateConfigurationForm($form, $form_state); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); /** @var \Drupal\embed\EmbedButtonInterface $button */ $button = $this->entity; // Run embed type plugin validation. if ($plugin = $button->getTypePlugin()) { $plugin_form_state = clone $form_state; $plugin_form_state->setValues($button->getTypeSettings()); $plugin->validateConfigurationForm($form['type_settings'], $plugin_form_state); if ($errors = $plugin_form_state->getErrors()) { foreach ($errors as $name => $error) { $form_state->setErrorByName($name, $error); } } $form_state->setValue('type_settings', $plugin_form_state->getValues()); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($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.')); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); if ($this->plugin instanceof PluginFormInterface) { $this->plugin->validateConfigurationForm($form, $form_state); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // Only run key settings validation if the form is being submitted if ($form_state->isSubmitted()) { $plugin_settings = (new FormState())->setValues($form_state->getValue('key_settings')); $plugin = $this->manager->createInstance($form_state->getValue('key_provider'), []); $plugin->validateConfigurationForm($form, $plugin_settings); // Reinject errors from $plugin_settings into $form_state foreach ($plugin_settings->getErrors() as $field => $error) { $form_state->setErrorByName($field, $error); } } parent::validateForm($form, $form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { // Check folders $folders = array(); foreach ($form_state->getValue(array('conf', 'folders')) as $i => $folder) { $path = trim($folder['path']); // Empty path if ($path === '') { continue; } // Validate path if (!Imce::regularPath($path)) { return $form_state->setError($form['conf']['folders'][$i]['path'], $this->t('Invalid folder path.')); } // Remove empty permissions $folder['permissions'] = array_filter($folder['permissions']); $folder['path'] = $path; $folders[$path] = $folder; } // No valid folders if (!$folders) { return $form_state->setError($form['conf']['folders'][0]['path'], $this->t('You must define a folder.')); } $form_state->setValue(array('conf', 'folders'), array_values($folders)); // Call plugin validators \Drupal::service('plugin.manager.imce.plugin')->validateProfileForm($form, $form_state, $this->getEntity()); return parent::validateForm($form, $form_state); }
/** * {@inheritDoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // Make field checkboxes required, if protection mode is text analysis. // @see http://drupal.org/node/875722 $mode = $form_state->getValue('mode'); $required = $mode == FormInterface::MOLLOM_MODE_ANALYSIS; $form['checks']['#required'] = $required; $form['discard']['#required'] = $required; if ($required && !array_filter($form_state->getValue('checks'))) { $form_state->setErrorByName('checks', t('At least one text analysis check is required.')); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); /** @var \Drupal\search_api\ServerInterface $server */ $server = $this->getEntity(); // Check if the backend plugin changed. $backend_id = $server->getBackendId(); if ($backend_id !== $form_state->getValues()['backend']) { // This can only happen during initial server creation, since we don't // allow switching the backend afterwards. The user has selected a // different backend, so any values entered for the other backend should // be discarded. // @todo Make sure this works both with and without AJAX. $input = $form_state->getUserInput(); $input['backend_config'] = array(); $form_state->set('input', $input); } elseif ($form['backend_config']['#type'] == 'details' && $server->hasValidBackend()) { $backend_form_state = new SubFormState($form_state, array('backend_config')); $server->getBackend()->validateConfigurationForm($form['backend_config'], $backend_form_state); } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($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); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // @todo Move this to the validation method for the confirm form plugin $flag = $this->entity; $flag->getFlagTypePlugin()->validateConfigurationForm($form, $form_state); $flag->getLinkTypePlugin()->validateConfigurationForm($form, $form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // Ensure each path is unique. $path = $this->entityQuery->get('search_page')->condition('path', $form_state->getValue('path'))->condition('id', $form_state->getValue('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 validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $currency_locale = $this->getEntity(); if ($currency_locale->isNew()) { $values = $form_state->getValues(); $locale = strtolower($values['language_code']) . '_' . strtoupper($values['country_code']); $loaded_currency_locale = $this->currencyLocaleStorage->load($locale); if ($loaded_currency_locale) { $form_state->setError($form['locale'], $this->t('A pattern for this locale already exists.')); } } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); /** @var $index \Drupal\search_api\IndexInterface */ $index = $this->getEntity(); $storage = $this->entityManager->getStorage('search_api_index'); if (!$index->isNew()) { $this->originalEntity = $storage->loadUnchanged($index->id()); } if (empty($this->originalEntity)) { $this->originalEntity = $storage->create(array('status' => FALSE)); } // Store the array of datasource plugin IDs with integer keys. $datasource_ids = array_values($form_state->getValue('datasources', array())); $form_state->setValue('datasources', $datasource_ids); // Call validateConfigurationForm() for each enabled datasource. // @todo Do we want to also call validate and submit callbacks for plugins // without configuration forms? We currently don't for backend plugins, // but do it here. We should be consistent. /** @var \Drupal\search_api\Datasource\DatasourceInterface[] $datasource_plugins */ $datasource_plugins = $this->originalEntity->getDatasources(FALSE); foreach ($datasource_ids as $datasource_id) { $datasource_form = !empty($form['datasource_configs'][$datasource_id]) ? $form['datasource_configs'][$datasource_id] : array(); $datasource_form_state = new SubFormState($form_state, array('datasource_configs', $datasource_id)); $datasource_plugins[$datasource_id]->validateConfigurationForm($datasource_form, $datasource_form_state); } // Call validateConfigurationForm() for the (possibly new) tracker. // @todo It seems if we change the tracker, we would validate/submit the old // tracker's form using the new tracker. Shouldn't be done, of course. // Similar above for datasources, though there of course the values will // just always be empty (because datasources have their plugin ID in the // form structure). $tracker_id = $form_state->getValue('tracker', NULL); if ($this->originalEntity->getTrackerId() == $tracker_id) { $tracker = $this->originalEntity->getTracker(); } else { $tracker = $this->trackerPluginManager->createInstance($tracker_id, array('index' => $this->originalEntity)); } $tracker_form_state = new SubFormState($form_state, array('tracker_config')); $tracker->validateConfigurationForm($form['tracker_config'], $tracker_form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $form_state->setValue('weight', (int) $form_state->getValue('weight')); // The Block Entity form puts all block plugin form elements in the // settings form element, so just pass that to the block for validation. $this->getPluginForm($this->entity->getPlugin())->validateConfigurationForm($form['settings'], SubformState::createForSubform($form['settings'], $form, $form_state)); $this->validateVisibility($form, $form_state); }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $values = $form_state->getValues(); /** @var \Drupal\search_api\Processor\ProcessorInterface[] $processors */ $processors = $this->entity->getProcessors(FALSE); // Iterate over all processors that have a form and are enabled. foreach ($form['settings'] as $processor_id => $processor_form) { if (!empty($values['status'][$processor_id])) { $processor_form_state = new SubFormState($form_state, array('processors', $processor_id, 'settings')); $processors[$processor_id]->validateConfigurationForm($form['settings'][$processor_id], $processor_form_state); } } }
/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $form_state->setValueForElement($form['id'], $form['id']['#field_prefix'] . $form_state->getValue('id')); }