当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityForm::validate方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\EntityForm::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityForm::validate方法的具体用法?PHP EntityForm::validate怎么用?PHP EntityForm::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\EntityForm的用法示例。


在下文中一共展示了EntityForm::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * {@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'])));
     }
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:12,代码来源:ShortcutSetForm.php

示例2: validate

 /**
  * {@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)));
     }
 }
开发者ID:jasonruyle,项目名称:crm_core,代码行数:12,代码来源:ContactTypeForm.php

示例3: validate

 /**
  * {@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());
 }
开发者ID:digideskio,项目名称:medium-editor-d8,代码行数:13,代码来源:MediumForm.php

示例4: validate

 /**
  * {@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);
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:15,代码来源:TaxRateFormBase.php

示例5: validate

 /**
  * {@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);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:16,代码来源:ContactFormEditForm.php

示例6: validate

 /**
  * {@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;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:16,代码来源:CategoryForm.php

示例7: validate

 /**
  * {@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]));
         }
     }
 }
开发者ID:r-daneelolivaw,项目名称:chalk,代码行数:23,代码来源:AddressFormatForm.php

示例8: validate

 /**
  * {@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);
     }
 }
开发者ID:brstde,项目名称:gap1,代码行数:11,代码来源:FieldConfigEditForm.php

示例9: validate

 /**
  * {@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)));
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:17,代码来源:FilterFormatFormBase.php

示例10: validate

 /**
  * {@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);
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:10,代码来源:ActionFormBase.php

示例11: validate

 /**
  * 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);
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:36,代码来源:MenuLinkForm.php

示例12: validate

 /**
  * {@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;
         }
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:17,代码来源:DateFormatFormBase.php

示例13: validate

 /**
  * {@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'];
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:BlockForm.php

示例14: validate

 /**
  * {@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);
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:28,代码来源:FeedTypeForm.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $this->doValidate($form, $form_state);
     parent::validate($form, $form_state);
 }
开发者ID:robertfoleyjr,项目名称:robertfoleyjr-d8,代码行数:8,代码来源:MenuLinkConfigForm.php


注:本文中的Drupal\Core\Entity\EntityForm::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。