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


PHP FormStateInterface::setErrorByName方法代码示例

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


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

示例1: validateName

 /**
  * Form element validation handler for 'name' in form_test_validate_form().
  */
 public function validateName(&$element, FormStateInterface $form_state)
 {
     $triggered = FALSE;
     if ($form_state->getValue('name') == 'element_validate') {
         // Alter the form element.
         $element['#value'] = '#value changed by #element_validate';
         // Alter the submitted value in $form_state.
         $form_state->setValueForElement($element, 'value changed by setValueForElement() in #element_validate');
         $triggered = TRUE;
     }
     if ($form_state->getValue('name') == 'element_validate_access') {
         $form_state->set('form_test_name', $form_state->getValue('name'));
         // Alter the form element.
         $element['#access'] = FALSE;
         $triggered = TRUE;
     } elseif ($form_state->has('form_test_name')) {
         // To simplify this test, just take over the element's value into $form_state.
         $form_state->setValueForElement($element, $form_state->get('form_test_name'));
         $triggered = TRUE;
     }
     if ($triggered) {
         // Output the element's value from $form_state.
         drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name'))));
         // Trigger a form validation error to see our changes.
         $form_state->setErrorByName('');
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:30,代码来源:Callbacks.php

示例2: validateForm

 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $cors_domains = $form_state->getValue('cors_domains', '');
     if (empty($cors_domains) && $cors_domains != $form['cors_domains']['#default_value']) {
         $form_state->setErrorByName('cors_domains', t('No domains provided.'));
         return;
     }
     $domains = explode("\r\n", $cors_domains);
     $settings = array();
     $errors = null;
     foreach ($domains as $domain) {
         if (empty($domain)) {
             continue;
         }
         $domain = explode("|", $domain, 2);
         if (empty($domain[0]) || empty($domain[1])) {
             $form_state->setErrorByName('cors_domains', t('Contains malformed entry.'));
             $errors = true;
         } else {
             $settings[$domain[0]] = isset($settings[$domain[0]]) ? $settings[$domain[0]] . ' ' : '';
             $settings[$domain[0]] .= trim($domain[1]);
         }
     }
     if ($settings && !$errors) {
         $form_state->setValue('settings', $settings);
     }
 }
开发者ID:nuxy,项目名称:cors,代码行数:27,代码来源:CorsConfigForm.php

示例3: validateForm

 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $error = array();
     $sf_library = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", trim($form_state->getValue('superfish_library')));
     if (empty($sf_library)) {
         $form_state->setErrorByName('superfish_library', t('Path to Superfish library field cannot be empty. Please try this list:') . str_replace("\r\n", ",", $this->superfish_library_path()));
     } else {
         // Trimming blank lines and such
         $sf_library = explode("\n", $sf_library);
         // Crystal clear
         foreach ($sf_library as $s) {
             if (!file_exists($s)) {
                 $error[] = $s;
             }
         }
         if (!empty($error)) {
             $error_message = '';
             if (count($error) > 1) {
                 foreach ($error as $e) {
                     $error_message .= '<li>' . $e . '</li>';
                 }
                 $error_message = t('Files not found') . ': <ul>' . $error_message . '</ul>';
             } else {
                 $error_message = t('File not found') . ': ' . $error[0];
             }
             $form_state->setErrorByName('superfish_library', $error_message);
         }
     }
     parent::validateForm($form, $form_state);
 }
开发者ID:morethanthemes,项目名称:newsplus-lite,代码行数:33,代码来源:SuperfishSettingsForm.php

示例4: validateForm

 /**
  * Implements \Drupal\Core\Form\FormInterface::validateForm().
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->set('notify_emails', []);
     if (!$form_state->isValueEmpty('update_notify_emails')) {
         $valid = array();
         $invalid = array();
         foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
             $email = trim($email);
             if (!empty($email)) {
                 if (valid_email_address($email)) {
                     $valid[] = $email;
                 } else {
                     $invalid[] = $email;
                 }
             }
         }
         if (empty($invalid)) {
             $form_state->set('notify_emails', $valid);
         } elseif (count($invalid) == 1) {
             $form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
         } else {
             $form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
         }
     }
     parent::validateForm($form, $form_state);
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:UpdateSettingsForm.php

示例5: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE);
     $has_upload = FALSE;
     if ($file_upload && $file_upload->isValid()) {
         // The sync directory must be empty if we are doing an upload.
         $form_state->setValue('import_tarball', $file_upload->getRealPath());
         $has_upload = TRUE;
     }
     $sync_directory = $form_state->getValue('sync_directory');
     // If we've customised the sync directory ensure its good to go.
     if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) {
         // Ensure it exists and is writeable.
         if (!file_prepare_directory($sync_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
             $form_state->setErrorByName('sync_directory', t('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array('%directory' => $sync_directory, '@handbook_url' => 'http://drupal.org/server-permissions')));
         }
     }
     // If no tarball ensure we have files.
     if (!$form_state->hasAnyErrors() && !$has_upload) {
         $sync = new FileStorage($sync_directory);
         if (count($sync->listAll()) === 0) {
             $form_state->setErrorByName('sync_directory', t('No file upload provided and the sync directory is empty'));
         }
     }
 }
开发者ID:mkudenko,项目名称:drupal8,代码行数:28,代码来源:SyncConfigureForm.php

示例6: validateForm

 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('cosign_allow_anons_on_https') == 0 && $form_state->getValue('cosign_allow_cosign_anons') == 1) {
         $form_state->setErrorByName('cosign_allow_anons_on_https', $this->t("Cosign users cannot browse anonymously if Anonymous users can't. Set Allow Anonymous Users to browse over https to Yes. OR"));
         $form_state->setErrorByName('cosign_allow_cosign_anons', $this->t("Cosign users cannot browse anonymously if Anonymous users can't. Set Allow Cosign Users to browse anonymously to No."));
     }
 }
开发者ID:bertrama,项目名称:cosign-drupal8,代码行数:7,代码来源:CosignAdmin.php

示例7: validateForm

 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if (strlen($form_state->getValue('title')) < 3) {
         $form_state->setErrorByName('title', $this->t('Your name is too short.'));
     }
     if (!UrlHelper::isValid($form_state->getValue('video'), TRUE)) {
         $form_state->setErrorByName('video', $this->t("The video url '%url' is invalid.", array('%url' => $form_state->getValue('video'))));
     }
 }
开发者ID:krabhay,项目名称:Learning-Drupal-8,代码行数:9,代码来源:ContributeForm.php

示例8: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if (strlen($form_state->getValue('title')) == '') {
         $form_state->setErrorByName('title', $this->t('Please enter title.'));
     }
     if (strlen($form_state->getValue('details')) == '') {
         $form_state->setErrorByName('details', $this->t('Please enter details.'));
     }
 }
开发者ID:National-Control-Devices,项目名称:questions-listing-page-module,代码行数:12,代码来源:AddQuestionForm.php

示例9: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if (!preg_match('/^\\d+$/', $form_state->getValue('nodejs_uid'))) {
         $form_state->setErrorByName('nodejs_uid', t('Invalid uid - please enter a numeric uid.'));
     }
     if (!preg_match('/^([a-z0-9_]+)$/i', $form_state->getValue('nodejs_channel'))) {
         $form_state->setErrorByName('nodejs_channel', t('Invalid channel name - only numbers, letters and underscores are allowed.'));
     }
 }
开发者ID:edwardchan,项目名称:d8-drupalvm,代码行数:12,代码来源:AddUserToChannelForm.php

示例10: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if (strlen($form_state->getValue('nc_username')) < 3) {
         $form_state->setErrorByName('nc_username', $this->t('The Username is too short you should select a longer one'));
     }
     if (strlen($form_state->getValue('nc_api_key')) < 3) {
         $form_state->setErrorByName('nc_api_key', $this->t('The API Key is too short you should select a longer one'));
     }
 }
开发者ID:EnginYilmaz,项目名称:nc_register,代码行数:12,代码来源:Nc_registerForm.php

示例11: validateForm

 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getValue('intranet_petitions_expired_days') <= 0) {
         $form_state->setErrorByName('intranet_petitions_expired_days', $this->t('Number of days should be > 0.'));
     }
     if ($form_state->getValue('intranet_petitions_likes_level') <= 0) {
         $form_state->setErrorByName('intranet_petitions_likes_level', $this->t('Number of likes level should be > 0.'));
     }
 }
开发者ID:lokeoke,项目名称:d8intranet,代码行数:9,代码来源:PetitionsConfigForm.php

示例12: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     require_once drupal_get_path('module', 'uc_icepay') . '/api/ParameterValidation.php';
     if (!\Icepay_ParameterValidation::merchantID($form_state->getValue('uc_icepay_merchant_id'))) {
         $form_state->setErrorByName('uc_icepay_merchant_id', t('You have specified an invalid Icepay Merchant ID.'));
     }
     if (!\Icepay_ParameterValidation::secretCode($form_state->getValue('uc_icepay_secret_code'))) {
         $form_state->setErrorByName('uc_icepay_secret_code', t('You have specified an invalid Icepay Secret Code.'));
     }
 }
开发者ID:winnie80,项目名称:uc_icepay,代码行数:13,代码来源:IcepaySettingsForm.php

示例13: validateCommon

 /**
  * Validates the language editing element.
  */
 public function validateCommon(array $form, FormStateInterface $form_state)
 {
     // Ensure sane field values for langcode and name.
     if (!isset($form['langcode_view']) && !preg_match('@^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$@', $form_state->getValue('langcode'))) {
         $form_state->setErrorByName('langcode', $this->t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', array('%field' => $form['langcode']['#title'], ':url' => 'http://www.w3.org/International/articles/language-tags/')));
     }
     if ($form_state->getValue('label') != Html::escape($form_state->getValue('label'))) {
         $form_state->setErrorByName('label', $this->t('%field cannot contain any markup.', array('%field' => $form['label']['#title'])));
     }
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:13,代码来源:LanguageFormBase.php

示例14: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $id = strtolower(trim($form_state->getValue('id')));
     if (strpos($id, ' ') !== FALSE || $id == 'all') {
         $form_state->setErrorByName('id', $this->t('You have entered an invalid status ID.'));
     }
     if (OrderStatus::load($id)) {
         $form_state->setErrorByName('id', $this->t('This ID is already in use.  Please specify a unique ID.'));
     }
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:13,代码来源:OrderStatusAddForm.php

示例15: validateCommon

 /**
  * Validates the language editing element.
  */
 public function validateCommon(array $form, FormStateInterface $form_state)
 {
     // Ensure sane field values for langcode and name.
     if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state->getValue('langcode'))) {
         $form_state->setErrorByName('langcode', $this->t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => $form['langcode']['#title'])));
     }
     if ($form_state->getValue('label') != String::checkPlain($form_state->getValue('label'))) {
         $form_state->setErrorByName('label', $this->t('%field cannot contain any markup.', array('%field' => $form['label']['#title'])));
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:13,代码来源:LanguageFormBase.php


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