Commit 03fc2042 authored by catch's avatar catch

Issue #2537732 by Xano, tim.plunkett, gnuget, claudiu.cristea, drunken monkey,...

Issue #2537732 by Xano, tim.plunkett, gnuget, claudiu.cristea, drunken monkey, bojanz: PluginFormInterface must have access to the complete $form_state (introduce SubFormState for embedded forms)
parent 2ec23349
......@@ -5,6 +5,7 @@
use Drupal\Core\Executable\ExecutableManagerInterface;
use Drupal\Core\Executable\ExecutablePluginBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformStateInterface;
use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait;
/**
......@@ -47,6 +48,9 @@ public function isNegated() {
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
if ($form_state instanceof SubformStateInterface) {
$form_state = $form_state->getCompleteFormState();
}
$contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
$form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
$form['negate'] = array(
......@@ -68,6 +72,9 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['negate'] = $form_state->getValue('negate');
if ($form_state->hasValue('context_mapping')) {
$this->setContextMapping($form_state->getValue('context_mapping'));
}
}
/**
......
......@@ -11,6 +11,8 @@
*/
class FormState implements FormStateInterface {
use FormStateValuesTrait;
/**
* Tracks if any errors have been set on any form.
*
......@@ -246,7 +248,8 @@ class FormState implements FormStateInterface {
*
* This property is uncacheable.
*
* @var array
* @var array|null
* The submitted user input array, or NULL if no input was submitted yet.
*/
protected $input;
......@@ -977,67 +980,6 @@ public function &getValues() {
return $this->values;
}
/**
* {@inheritdoc}
*/
public function &getValue($key, $default = NULL) {
$exists = NULL;
$value = &NestedArray::getValue($this->getValues(), (array) $key, $exists);
if (!$exists) {
$value = $default;
}
return $value;
}
/**
* {@inheritdoc}
*/
public function setValues(array $values) {
$this->values = $values;
return $this;
}
/**
* {@inheritdoc}
*/
public function setValue($key, $value) {
NestedArray::setValue($this->getValues(), (array) $key, $value, TRUE);
return $this;
}
/**
* {@inheritdoc}
*/
public function unsetValue($key) {
NestedArray::unsetValue($this->getValues(), (array) $key);
return $this;
}
/**
* {@inheritdoc}
*/
public function hasValue($key) {
$exists = NULL;
$value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
return $exists && isset($value);
}
/**
* {@inheritdoc}
*/
public function isValueEmpty($key) {
$exists = NULL;
$value = NestedArray::getValue($this->getValues(), (array) $key, $exists);
return !$exists || empty($value);
}
/**
* {@inheritdoc}
*/
public function setValueForElement(array $element, $value) {
return $this->setValue($element['#parents'], $value);
}
/**
* {@inheritdoc}
*/
......
<?php
namespace Drupal\Core\Form;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Response;
/**
* Decorates another form state.
*/
abstract class FormStateDecoratorBase implements FormStateInterface {
/**
* The decorated form state.
*
* @var \Drupal\Core\Form\FormStateInterface
*/
protected $decoratedFormState;
/**
* {@inheritdoc}
*/
public function setFormState(array $form_state_additions) {
$this->decoratedFormState->setFormState($form_state_additions);
return $this;
}
/**
* {@inheritdoc}
*/
public function setAlwaysProcess($always_process = TRUE) {
$this->decoratedFormState->setAlwaysProcess($always_process);
return $this;
}
/**
* {@inheritdoc}
*/
public function getAlwaysProcess() {
return $this->decoratedFormState->getAlwaysProcess();
}
/**
* {@inheritdoc}
*/
public function setButtons(array $buttons) {
$this->decoratedFormState->setButtons($buttons);
return $this;
}
/**
* {@inheritdoc}
*/
public function getButtons() {
return $this->decoratedFormState->getButtons();
}
/**
* {@inheritdoc}
*/
public function setCached($cache = TRUE) {
$this->decoratedFormState->setCached($cache);
return $this;
}
/**
* {@inheritdoc}
*/
public function isCached() {
return $this->decoratedFormState->isCached();
}
/**
* {@inheritdoc}
*/
public function disableCache() {
$this->decoratedFormState->disableCache();
return $this;
}
/**
* {@inheritdoc}
*/
public function setExecuted() {
$this->decoratedFormState->setExecuted();
return $this;
}
/**
* {@inheritdoc}
*/
public function isExecuted() {
return $this->decoratedFormState->isExecuted();
}
/**
* {@inheritdoc}
*/
public function setGroups(array $groups) {
$this->decoratedFormState->setGroups($groups);
return $this;
}
/**
* {@inheritdoc}
*/
public function &getGroups() {
return $this->decoratedFormState->getGroups();
}
/**
* {@inheritdoc}
*/
public function setHasFileElement($has_file_element = TRUE) {
$this->decoratedFormState->setHasFileElement($has_file_element);
return $this;
}
/**
* {@inheritdoc}
*/
public function hasFileElement() {
return $this->decoratedFormState->hasFileElement();
}
/**
* {@inheritdoc}
*/
public function setLimitValidationErrors($limit_validation_errors) {
$this->decoratedFormState->setLimitValidationErrors($limit_validation_errors);
return $this;
}
/**
* {@inheritdoc}
*/
public function getLimitValidationErrors() {
return $this->decoratedFormState->getLimitValidationErrors();
}
/**
* {@inheritdoc}
*/
public function setMethod($method) {
$this->decoratedFormState->setMethod($method);
return $this;
}
/**
* {@inheritdoc}
*/
public function isMethodType($method_type) {
return $this->decoratedFormState->isMethodType($method_type);
}
/**
* {@inheritdoc}
*/
public function setRequestMethod($method) {
$this->decoratedFormState->setRequestMethod($method);
return $this;
}
/**
* {@inheritdoc}
*/
public function setValidationEnforced($must_validate = TRUE) {
$this->decoratedFormState->setValidationEnforced($must_validate);
return $this;
}
/**
* {@inheritdoc}
*/
public function isValidationEnforced() {
return $this->decoratedFormState->isValidationEnforced();
}
/**
* {@inheritdoc}
*/
public function disableRedirect($no_redirect = TRUE) {
$this->decoratedFormState->disableRedirect($no_redirect);
return $this;
}
/**
* {@inheritdoc}
*/
public function isRedirectDisabled() {
return $this->decoratedFormState->isRedirectDisabled();
}
/**
* {@inheritdoc}
*/
public function setProcessInput($process_input = TRUE) {
$this->decoratedFormState->setProcessInput($process_input);
return $this;
}
/**
* {@inheritdoc}
*/
public function isProcessingInput() {
return $this->decoratedFormState->isProcessingInput();
}
/**
* {@inheritdoc}
*/
public function setProgrammed($programmed = TRUE) {
$this->decoratedFormState->setProgrammed($programmed);
return $this;
}
/**
* {@inheritdoc}
*/
public function isProgrammed() {
return $this->decoratedFormState->isProgrammed();
}
/**
* {@inheritdoc}
*/
public function setProgrammedBypassAccessCheck($programmed_bypass_access_check = TRUE) {
$this->decoratedFormState->setProgrammedBypassAccessCheck($programmed_bypass_access_check);
return $this;
}
/**
* {@inheritdoc}
*/
public function isBypassingProgrammedAccessChecks() {
return $this->decoratedFormState->isBypassingProgrammedAccessChecks();
}
/**
* {@inheritdoc}
*/
public function setRebuildInfo(array $rebuild_info) {
$this->decoratedFormState->setRebuildInfo($rebuild_info);
return $this;
}
/**
* {@inheritdoc}
*/
public function getRebuildInfo() {
return $this->decoratedFormState->getRebuildInfo();
}
/**
* {@inheritdoc}
*/
public function addRebuildInfo($property, $value) {
$this->decoratedFormState->addRebuildInfo($property, $value);
return $this;
}
/**
* {@inheritdoc}
*/
public function setStorage(array $storage) {
$this->decoratedFormState->setStorage($storage);
return $this;
}
/**
* {@inheritdoc}
*/
public function &getStorage() {
return $this->decoratedFormState->getStorage();
}
/**
* {@inheritdoc}
*/
public function setSubmitHandlers(array $submit_handlers) {
$this->decoratedFormState->setSubmitHandlers($submit_handlers);
return $this;
}
/**
* {@inheritdoc}
*/
public function getSubmitHandlers() {
return $this->decoratedFormState->getSubmitHandlers();
}
/**
* {@inheritdoc}
*/
public function setSubmitted() {
$this->decoratedFormState->setSubmitted();
return $this;
}
/**
* {@inheritdoc}
*/
public function isSubmitted() {
return $this->decoratedFormState->isSubmitted();
}
/**
* {@inheritdoc}
*/
public function setTemporary(array $temporary) {
$this->decoratedFormState->setTemporary($temporary);
return $this;
}
/**
* {@inheritdoc}
*/
public function getTemporary() {
return $this->decoratedFormState->getTemporary();
}
/**
* {@inheritdoc}
*/
public function &getTemporaryValue($key) {
return $this->decoratedFormState->getTemporaryValue($key);
}
/**
* {@inheritdoc}
*/
public function setTemporaryValue($key, $value) {
$this->decoratedFormState->setTemporaryValue($key, $value);
return $this;
}
/**
* {@inheritdoc}
*/
public function hasTemporaryValue($key) {
return $this->decoratedFormState->hasTemporaryValue($key);
}
/**
* {@inheritdoc}
*/
public function setTriggeringElement($triggering_element) {
$this->decoratedFormState->setTriggeringElement($triggering_element);
return $this;
}
/**
* {@inheritdoc}
*/
public function &getTriggeringElement() {
return $this->decoratedFormState->getTriggeringElement();
}
/**
* {@inheritdoc}
*/
public function setValidateHandlers(array $validate_handlers) {
$this->decoratedFormState->setValidateHandlers($validate_handlers);
return $this;
}
/**
* {@inheritdoc}
*/
public function getValidateHandlers() {
return $this->decoratedFormState->getValidateHandlers();
}
/**
* {@inheritdoc}
*/
public function setValidationComplete($validation_complete = TRUE) {
$this->decoratedFormState->setValidationComplete($validation_complete);
return $this;
}
/**
* {@inheritdoc}
*/
public function isValidationComplete() {
return $this->decoratedFormState->isValidationComplete();
}
/**
* {@inheritdoc}
*/
public function loadInclude($module, $type, $name = NULL) {
return $this->decoratedFormState->loadInclude($module, $type, $name);
}
/**
* {@inheritdoc}
*/
public function getCacheableArray() {
return $this->decoratedFormState->getCacheableArray();
}
/**
* {@inheritdoc}
*/
public function setCompleteForm(array &$complete_form) {
$this->decoratedFormState->setCompleteForm($complete_form);
return $this;
}
/**
* {@inheritdoc}
*/
public function &getCompleteForm() {
return $this->decoratedFormState->getCompleteForm();
}
/**
* {@inheritdoc}
*/
public function &get($property) {
return $this->decoratedFormState->get($property);
}
/**
* {@inheritdoc}
*/
public function set($property, $value) {
$this->decoratedFormState->set($property, $value);
return $this;
}
/**
* {@inheritdoc}
*/
public function has($property) {
return $this->decoratedFormState->has($property);
}
/**
* {@inheritdoc}
*/
public function setBuildInfo(array $build_info) {
$this->decoratedFormState->setBuildInfo($build_info);
return $this;
}
/**
* {@inheritdoc}
*/
public function getBuildInfo() {
return $this->decoratedFormState->getBuildInfo();
}
/**
* {@inheritdoc}
*/
public function addBuildInfo($property, $value) {
$this->decoratedFormState->addBuildInfo($property, $value);
return $this;
}
/**
* {@inheritdoc}
*/
public function &getUserInput() {
return $this->decoratedFormState->getUserInput();
}
/**
* {@inheritdoc}
*/
public function setUserInput(array $user_input) {
$this->decoratedFormState->setUserInput($user_input);
return $this;
}
/**
* {@inheritdoc}
*/
public function &getValues() {
return $this->decoratedFormState->getValues();
}
/**
* {@inheritdoc}
*/
public function &getValue($key, $default = NULL) {
return $this->decoratedFormState->getValue($key, $default);
}