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


PHP FormState::setErrorByName方法代码示例

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


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

示例1: testSetElementErrorsFromFormState

 /**
  * @covers ::handleFormErrors
  * @covers ::setElementErrorsFromFormState
  */
 public function testSetElementErrorsFromFormState()
 {
     $form_error_handler = $this->getMockBuilder('Drupal\\Core\\Form\\FormErrorHandler')->setMethods(['drupalSetMessage'])->getMock();
     $form = ['#parents' => []];
     $form['test'] = ['#type' => 'textfield', '#title' => 'Test', '#parents' => ['test'], '#id' => 'edit-test'];
     $form_state = new FormState();
     $form_state->setErrorByName('test', 'invalid');
     $form_error_handler->handleFormErrors($form, $form_state);
     $this->assertSame('invalid', $form['test']['#errors']);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:14,代码来源:FormErrorHandlerTest.php

示例2: testSetElementErrorsFromFormState

 /**
  * @covers ::handleFormErrors
  * @covers ::setElementErrorsFromFormState
  */
 public function testSetElementErrorsFromFormState()
 {
     $form_error_handler = $this->getMockBuilder('Drupal\\Core\\Form\\FormErrorHandler')->setConstructorArgs([$this->getStringTranslationStub(), $this->getMock('Drupal\\Core\\Utility\\LinkGeneratorInterface')])->setMethods(['drupalSetMessage'])->getMock();
     $form = ['#parents' => []];
     $form['test'] = ['#type' => 'textfield', '#title' => 'Test', '#parents' => ['test'], '#id' => 'edit-test'];
     $form_state = new FormState();
     $form_state->setErrorByName('test', 'invalid');
     $form_error_handler->handleFormErrors($form, $form_state);
     $this->assertSame('invalid', $form['test']['#errors']);
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:14,代码来源:FormErrorHandlerTest.php

示例3: extractMollomValues


//.........这里部分代码省略.........
         $data['postId'] = $mapping['post_id'];
     }
     // Post title.
     if (!empty($mapping['post_title'])) {
         $data['postTitle'] = $mapping['post_title'];
     }
     // Post body.
     if (!empty($post_body)) {
         $data['postBody'] = $post_body;
     }
     // Author ID.
     // If a non-anonymous user ID was mapped via form values, use that.
     if (!empty($mapping['author_id'])) {
         $data['authorId'] = $mapping['author_id'];
     } elseif (!empty($user->id())) {
         $data['authorId'] = $user->id();
     }
     // Load the user account of the author, if any, for the following author*
     // property assignments.
     $account = FALSE;
     if (isset($data['authorId'])) {
         /** @var \Drupal\user\Entity\User $account */
         $account = User::load($data['authorId']);
         $author_username = $account->getUsername();
         $author_email = $account->getEmail();
         // Author creation date.
         $data['authorCreated'] = $account->getCreatedTime();
         // In case a post of a registered user is edited and a form value mapping
         // exists for author_id, but no form value mapping exists for author_name,
         // use the name of the user account associated with author_id.
         // $account may be the same as the currently logged-in $user at this point.
         if (!empty($author_username)) {
             $data['authorName'] = $author_username;
         }
         if (!empty($author_email)) {
             $data['authorMail'] = $author_email;
         }
     }
     // Author name.
     // A form value mapping always has precedence.
     if (!empty($mapping['author_name'])) {
         $data['authorName'] = $mapping['author_name'];
     }
     // Author e-mail.
     if (!empty($mapping['author_mail'])) {
         $data['authorMail'] = $mapping['author_mail'];
     }
     // Author homepage.
     if (!empty($mapping['author_url'])) {
         $data['authorUrl'] = $mapping['author_url'];
     }
     // Author OpenID.
     if (!empty($mapping['author_openid'])) {
         $data['authorOpenid'] = $mapping['author_openid'];
     }
     // Author IP.
     $data['authorIp'] = \Drupal::request()->getClientIp();
     $mollom_form = $form_state->getValue('mollom');
     // Honeypot.
     // For the Mollom backend, it only matters whether 'honeypot' is non-empty.
     // The submitted value is only taken over to allow site administrators to
     // see the actual honeypot value in watchdog log entries.
     if (isset($mollom_form['homepage']) && $mollom_form['homepage'] !== '') {
         $data['honeypot'] = $mollom_form['homepage'];
     }
     // Add the contextCreated parameter if a callback exists.
     if (isset($mollom_form['context created callback']) && function_exists($mollom_form['context created callback'])) {
         if (!empty($mapping['context_id'])) {
             $contextCreated = call_user_func($mollom_form['context created callback'], $mapping['context_id']);
             if ($contextCreated !== FALSE) {
                 $data['contextCreated'] = $contextCreated;
             }
         }
     }
     // Ensure that all $data values contain valid UTF-8. Invalid UTF-8 would be
     // sanitized into an empty string, so the Mollom backend would not receive
     // any value.
     $invalid_utf8 = FALSE;
     $invalid_xml = FALSE;
     // Include the CAPTCHA solution user input in the UTF-8 validation.
     $solution = isset($mollom_form['captcha']['captcha_input']) ? array('solution' => $mollom_form['captcha']['captcha_input']) : array();
     foreach ($data + $solution as $key => $value) {
         // Check for invalid UTF-8 byte sequences first.
         if (!Unicode::validateUtf8($value)) {
             $invalid_utf8 = TRUE;
             // Replace the bogus string, since $data will be logged as
             // check_plain(var_export($data)), and check_plain() would empty the
             // entire exported variable string otherwise.
             $data[$key] = '- Invalid UTF-8 -';
         } elseif (preg_match('@[^\\x9\\xA\\xD\\x20-\\x{D7FF}\\x{E000}-\\x{FFFD}\\x{10000}-\\x{10FFFF}]@u', $value)) {
             $invalid_xml = TRUE;
         }
     }
     if ($invalid_utf8 || $invalid_xml) {
         $form_state->setErrorByName('', t('Your submission contains invalid characters and will not be accepted.'));
         Logger::addMessage(['message' => 'Invalid @type in form values', 'arguments' => ['@type' => $invalid_utf8 ? 'UTF-8' : 'XML characters'], 'data' => $data]);
         $data = FALSE;
     }
     return $data;
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:101,代码来源:FormController.php

示例4: testFormErrorsDuringSubmission

 /**
  * Tests that form errors during submission throw an exception.
  *
  * @covers ::setErrorByName
  *
  * @expectedException \LogicException
  * @expectedExceptionMessage Form errors cannot be set after form validation has finished.
  */
 public function testFormErrorsDuringSubmission()
 {
     $form_state = new FormState();
     $form_state->setValidationComplete();
     $form_state->setErrorByName('test', 'message');
 }
开发者ID:318io,项目名称:318-io,代码行数:14,代码来源:FormStateTest.php

示例5: selectItemAjaxAjaxCallbackReturnsReplaceHtmlWhenErrorsExist

 /**
  * Tests selectItemAjax().
  *
  * GIVEN the embridge search form
  * WHEN the ajax handler for the select button is run with errors
  * THEN an ajax response should be returned with the expected commands.
  *
  * @covers ::selectItemAjax
  *
  * @test
  */
 public function selectItemAjaxAjaxCallbackReturnsReplaceHtmlWhenErrorsExist()
 {
     $form = ['#attached' => ['test']];
     $form_state = new FormState();
     $form_state->setErrorByName('test', 'test error');
     $response = $this->form->selectItemAjax($form, $form_state);
     $this->assertInstanceOf('\\Drupal\\Core\\Ajax\\AjaxResponse', $response);
     $commands = $response->getCommands();
     $this->assertNotEmpty($commands);
     $this->assertCount(3, $commands);
     $this->assertEquals('replaceWith', $commands[0]['method']);
     $this->assertEquals('html', $commands[1]['method']);
     $this->assertEquals('append', $commands[2]['method']);
 }
开发者ID:acbramley,项目名称:embridge,代码行数:25,代码来源:EmbridgeSearchFormTest.php

示例6: ajaxSaveWithErrorsReturnsHtmlCommand

 /**
  * Test submitForm with errors.
  *
  * @covers ::ajaxSave
  *
  * @test
  */
 public function ajaxSaveWithErrorsReturnsHtmlCommand()
 {
     // #attached required for CommandWithAttachedAssetsTrait checks.
     $form = ['#attached' => []];
     $form_state = new FormState();
     $form_state->setErrorByName('test', 'ERROR ERROR!!');
     $response = $this->form->ajaxSave($form, $form_state);
     $this->assertInstanceOf('\\Drupal\\Core\\Ajax\\AjaxResponse', $response);
     $commands = $response->getCommands();
     $this->assertNotEmpty($commands);
     $this->assertCount(1, $commands);
     $this->assertEquals('insert', $commands[0]['command']);
 }
开发者ID:acbramley,项目名称:embridge,代码行数:20,代码来源:EmbridgeCkeditorImageDialogTest.php


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