當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。