本文整理汇总了PHP中Drupal\Core\Entity\EntityForm::validateForm方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityForm::validateForm方法的具体用法?PHP EntityForm::validateForm怎么用?PHP EntityForm::validateForm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityForm
的用法示例。
在下文中一共展示了EntityForm::validateForm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateForm
/**
* {@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);
}
示例2: validateForm
/**
* {@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);
}
}
示例3: validateForm
/**
* {@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);
}
示例4: validateForm
/**
* 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'));
}
}
示例5: validateForm
/**
* {@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);
}
示例6: validateForm
/**
* {@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;
}
}
}
示例7: validateForm
/**
* {@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;
}
示例8: validateForm
/**
* {@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);
}
示例9: validateForm
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,
]);
}
}
示例10: validateForm
/**
* {@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 /.'));
}
}
}
示例11: validateForm
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state)
{
parent::validateForm($form, $form_state);
$this->plugin->validateConfigurationForm($form['settings'], $form_state);
}
示例12: validateForm
/**
* {@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.');
}
}
}
}
}
}
示例13: validateForm
/**
* {@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)));
}
}
示例14: validateForm
/**
* {@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)));
}
}
示例15: validateForm
/**
* {@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);
}
}