/** * @covers ::setErrorByName */ public function testSetErrorByName() { $parent_form_error_name = 'dog][name'; $subform_error_name = 'name'; $message = 'De kat krabt de krullen van de trap.'; $parent_form_state = $this->prophesize(FormStateInterface::class); $parent_form_state->setErrorByName($parent_form_error_name, $message)->shouldBeCalled(); $subform_state = SubformState::createForSubform($this->parentForm['dog'], $this->parentForm, $parent_form_state->reveal()); $this->assertSame($subform_state, $subform_state->setErrorByName($subform_error_name, $message)); }
/** * Helper function to independently submit the visibility UI. * * @param array $form * A nested array form elements comprising the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */ protected function submitVisibility(array $form, FormStateInterface $form_state) { foreach ($form_state->getValue('visibility') as $condition_id => $values) { // Allow the condition to submit the form. $condition = $form_state->get(['conditions', $condition_id]); $condition->submitConfigurationForm($form['visibility'][$condition_id], SubformState::createForSubform($form['visibility'][$condition_id], $form, $form_state)); // Setting conditions' context mappings is the plugins' responsibility. // This code exists for backwards compatibility, because // \Drupal\Core\Condition\ConditionPluginBase::submitConfigurationForm() // did not set its own mappings until Drupal 8.2 // @todo Remove the code that sets context mappings in Drupal 9.0.0. if ($condition instanceof ContextAwarePluginInterface) { $context_mapping = isset($values['context_mapping']) ? $values['context_mapping'] : []; $condition->setContextMapping($context_mapping); } $condition_configuration = $condition->getConfiguration(); // Update the visibility conditions on the block. $this->entity->getVisibilityConditions()->addInstanceId($condition_id, $condition_configuration); } }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->cleanValues(); // The image effect configuration is stored in the 'data' key in the form, // pass that through for submission. $this->imageEffect->submitConfigurationForm($form['data'], SubformState::createForSubform($form['data'], $form, $form_state)); $this->imageEffect->setWeight($form_state->getValue('weight')); if (!$this->imageEffect->getUuid()) { $this->imageStyle->addImageEffect($this->imageEffect->getConfiguration()); } $this->imageStyle->save(); drupal_set_message($this->t('The image effect was successfully applied.')); $form_state->setRedirectUrl($this->imageStyle->urlInfo('edit-form')); }