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


PHP FormState::setValue方法代码示例

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


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

示例1: testExtractFormValues

 /**
  * @covers ::extractFormValues
  */
 public function testExtractFormValues()
 {
     $menu_link_manager = $this->prophesize(MenuLinkManagerInterface::class);
     $menu_parent_form_selector = $this->prophesize(MenuParentFormSelectorInterface::class);
     $module_handler = $this->prophesize(ModuleHandlerInterface::class);
     $menu_link_form = new MenuLinkDefaultForm($menu_link_manager->reveal(), $menu_parent_form_selector->reveal(), $this->getStringTranslationStub(), $module_handler->reveal());
     $static_override = $this->prophesize(StaticMenuLinkOverridesInterface::class);
     $menu_link = new MenuLinkDefault([], 'my_plugin_id', [], $static_override->reveal());
     $menu_link_form->setMenuLinkInstance($menu_link);
     $form_state = new FormState();
     $form_state->setValue('id', 'my_plugin_id');
     $form_state->setValue('enabled', FALSE);
     $form_state->setValue('weight', 5);
     $form_state->setValue('expanded', TRUE);
     $form_state->setValue('menu_parent', 'foo:bar');
     $form = [];
     $result = $menu_link_form->extractFormValues($form, $form_state);
     $this->assertEquals(['id' => 'my_plugin_id', 'enabled' => 0, 'weight' => 5, 'expanded' => 1, 'parent' => 'bar', 'menu_name' => 'foo'], $result);
 }
开发者ID:frankcr,项目名称:sftw8,代码行数:22,代码来源:MenuLinkDefaultFormTest.php

示例2: testLimitValidationErrors

 /**
  * Tests that #limit_validation_errors of the only submit button takes effect.
  */
 function testLimitValidationErrors()
 {
     // Programmatically submit the form.
     $form_state = new FormState();
     $form_state->setValue('section', 'one');
     $form_builder = $this->container->get('form_builder');
     $form_builder->submitForm($this, $form_state);
     // Verify that only the specified section was validated.
     $errors = $form_state->getErrors();
     $this->assertTrue(isset($errors['one']), "Section 'one' was validated.");
     $this->assertFalse(isset($errors['two']), "Section 'two' was not validated.");
     // Verify that there are only values for the specified section.
     $this->assertTrue($form_state->hasValue('one'), "Values for section 'one' found.");
     $this->assertFalse($form_state->hasValue('two'), "Values for section 'two' not found.");
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:18,代码来源:TriggeringElementProgrammedUnitTest.php

示例3: testCopyFormValuesToEntity

 /**
  * @covers ::copyFormValuesToEntity
  */
 public function testCopyFormValuesToEntity()
 {
     $description = $this->randomMachineName();
     $id = $this->randomMachineName();
     $label = $this->randomMachineName();
     $parent_id = $this->randomMachineName();
     $this->paymentStatus->expects($this->once())->method('setDescription')->with($description);
     $this->paymentStatus->expects($this->once())->method('setId')->with($id);
     $this->paymentStatus->expects($this->once())->method('setLabel')->with($label);
     $this->paymentStatus->expects($this->once())->method('setParentId')->with($parent_id);
     $parent_status = $this->getMock(PluginSelectorInterface::class);
     $parent_status->expects($this->atLeastOnce())->method('getPluginId')->willReturn($parent_id);
     $parent_selector = $this->getMock(PluginSelectorInterface::class);
     $parent_selector->expects($this->atLeastOnce())->method('getSelectedPlugin')->willReturn($parent_status);
     $this->pluginSelectorManager->expects($this->atLeastOnce())->method('createInstance')->willReturn($parent_selector);
     $form = [];
     $form_state = new FormState();
     $form_state->setValue('description', $description);
     $form_state->setValue('id', $id);
     $form_state->setValue('label', $label);
     $form_state->setValue('parent_id', $parent_id);
     $method = new \ReflectionMethod($this->sut, 'copyFormValuesToEntity');
     $method->setAccessible(TRUE);
     $method->invokeArgs($this->sut, array($this->paymentStatus, $form, $form_state));
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:28,代码来源:PaymentStatusFormTest.php

示例4: submitForm

 /**
  * Form submit handler to flush Mollom session and form information from cache.
  *
  * This is necessary as the entity forms will no longer automatically save
  * the data with the entity.
  *
  * @todo: Possible problems:
  *   - This submit handler is invoked too late; the primary submit handler might
  *     send out e-mails directly after saving the entity (e.g.,
  *     user_register_form_submit()), so mollom_mail_alter() is invoked before
  *     Mollom session data has been saved.
  */
 public static function submitForm($form, FormState $form_state)
 {
     // Some modules are implementing multi-step forms without separate form
     // submit handlers. In case we reach here and the form will be rebuilt, we
     // need to defer our submit handling until final submission.
     $is_rebuilding = $form_state->isRebuilding();
     if ($is_rebuilding) {
         return;
     }
     $mollom = $form_state->getValue('mollom');
     $form_object = $form_state->getFormObject();
     // If an 'entity' and a 'post_id' mapping was provided via
     // hook_mollom_form_info(), try to automatically store Mollom session data.
     if (empty($mollom) || empty($mollom['entity']) || !$form_state->getFormObject() instanceof EntityFormInterface) {
         return;
     }
     /* @var $form_object \Drupal\Core\Entity\EntityFormInterface */
     $entity_id = $form_object->getEntity()->id();
     $data = (object) $mollom;
     $data->id = $entity_id;
     $data->moderate = $mollom['require_moderation'] ? 1 : 0;
     $stored_data = ResponseDataStorage::save($data);
     $form_state->setValue(['mollom', 'data'], $stored_data);
 }
开发者ID:isramv,项目名称:camp-gdl,代码行数:36,代码来源:FormController.php

示例5: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $pass = $form_state->getValue('filter_pass') ? explode(',', $form_state->getValue('filter_pass')) : array();
     $fail = $form_state->getValue('filter_fail') ? explode(',', $form_state->getValue('filter_fail')) : array();
     if ($form_state->getValue('filter') == 'all') {
         $classes = array_merge($pass, $fail);
     } elseif ($form_state->getValue('filter') == 'pass') {
         $classes = $pass;
     } else {
         $classes = $fail;
     }
     if (!$classes) {
         $form_state->setRedirect('simpletest.test_form');
         return;
     }
     $form_execute = array();
     $form_state_execute = new FormState();
     foreach ($classes as $class) {
         $form_state_execute->setValue(['tests', $class], $class);
     }
     // Submit the simpletest test form to rerun the tests.
     // Under normal circumstances, a form object's submitForm() should never be
     // called directly, FormBuilder::submitForm() should be called instead.
     // However, it calls $form_state->setProgrammed(), which disables the Batch API.
     $simpletest_test_form = SimpletestTestForm::create(\Drupal::getContainer());
     $simpletest_test_form->buildForm($form_execute, $form_state_execute);
     $simpletest_test_form->submitForm($form_execute, $form_state_execute);
     if ($redirect = $form_state_execute->getRedirect()) {
         $form_state->setRedirectUrl($redirect);
     }
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:34,代码来源:SimpletestResultsForm.php

示例6: testSubmitConfigurationForm

 /**
  * Tests the submitConfigurationForm() method.
  *
  * @covers ::submitConfigurationForm
  */
 public function testSubmitConfigurationForm()
 {
     $display_variant = $this->setUpDisplayVariant();
     $this->assertSame('', $display_variant->label());
     $form = array();
     $label = $this->randomMachineName();
     $form_state = new FormState();
     $form_state->setValue('label', $label);
     $display_variant->submitConfigurationForm($form, $form_state);
     $this->assertSame($label, $display_variant->label());
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:16,代码来源:DisplayVariantTest.php

示例7: testAddCleanValueKey

 /**
  * @covers ::addCleanValueKey
  */
 public function testAddCleanValueKey()
 {
     $form_state = new FormState();
     $form_state->setValue('value_to_clean', 'rainbow_sprinkles');
     $form_state->addCleanValueKey('value_to_clean');
     $this->assertSame($form_state->getCleanValueKeys(), ['form_id', 'form_token', 'form_build_id', 'op', 'value_to_clean']);
     return $form_state;
 }
开发者ID:318io,项目名称:318-io,代码行数:11,代码来源:FormStateTest.php


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