Commit fc5e111a authored by Dries's avatar Dries

Issue #2225353 by tim.plunkett: Convert to an object and provide methods like setError().

parent 4d07e60a
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
* Functions for use with Drupal's Ajax framework. * Functions for use with Drupal's Ajax framework.
*/ */
use Drupal\Core\Form\FormStateInterface;
/** /**
* @defgroup ajax Ajax framework * @defgroup ajax Ajax framework
* @{ * @{
...@@ -64,7 +66,7 @@ ...@@ -64,7 +66,7 @@
* return \Drupal::formBuilder()->getForm('ajax_example_simplest'); * return \Drupal::formBuilder()->getForm('ajax_example_simplest');
* } * }
* *
* function ajax_example_simplest($form, &$form_state) { * function ajax_example_simplest($form, FormStateInterface $form_state) {
* $form = array(); * $form = array();
* $form['changethis'] = array( * $form['changethis'] = array(
* '#type' => 'select', * '#type' => 'select',
...@@ -236,7 +238,7 @@ ...@@ -236,7 +238,7 @@
* *
* @see ajax_pre_render_element() * @see ajax_pre_render_element()
*/ */
function ajax_process_form($element, &$form_state) { function ajax_process_form($element, FormStateInterface $form_state) {
$element = ajax_pre_render_element($element); $element = ajax_pre_render_element($element);
if (!empty($element['#ajax_processed'])) { if (!empty($element['#ajax_processed'])) {
$form_state['cache'] = TRUE; $form_state['cache'] = TRUE;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Timer; use Drupal\Component\Utility\Timer;
use Drupal\Core\Batch\Percentage; use Drupal\Core\Batch\Percentage;
use Drupal\Core\Form\FormState;
use Drupal\Core\Page\DefaultHtmlPageRenderer; use Drupal\Core\Page\DefaultHtmlPageRenderer;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
...@@ -442,6 +443,9 @@ function _batch_finished() { ...@@ -442,6 +443,9 @@ function _batch_finished() {
} }
// Determine the target path to redirect to. // Determine the target path to redirect to.
if (!isset($_batch['form_state'])) {
$_batch['form_state'] = new FormState();
}
if (!isset($_batch['form_state']['redirect'])) { if (!isset($_batch['form_state']['redirect'])) {
if (isset($_batch['redirect'])) { if (isset($_batch['redirect'])) {
$_batch['form_state']['redirect'] = $_batch['redirect']; $_batch['form_state']['redirect'] = $_batch['redirect'];
......
This diff is collapsed.
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\Install\TaskException; use Drupal\Core\Database\Install\TaskException;
use Drupal\Core\Form\FormState;
use Drupal\Core\Installer\Exception\AlreadyInstalledException; use Drupal\Core\Installer\Exception\AlreadyInstalledException;
use Drupal\Core\Installer\Exception\InstallerException; use Drupal\Core\Installer\Exception\InstallerException;
use Drupal\Core\Installer\Exception\NoProfilesException; use Drupal\Core\Installer\Exception\NoProfilesException;
...@@ -157,7 +158,7 @@ function install_drupal($settings = array()) { ...@@ -157,7 +158,7 @@ function install_drupal($settings = array()) {
* submission is for, and the values are used as the $form_state['values'] * submission is for, and the values are used as the $form_state['values']
* array that is passed on to the form submission via drupal_form_submit()). * array that is passed on to the form submission via drupal_form_submit()).
* *
* @see drupal_form_submit() * @see \Drupal\Core\Form\FormBuilderInterface::submitForm()
*/ */
function install_state_defaults() { function install_state_defaults() {
$defaults = array( $defaults = array(
...@@ -804,12 +805,12 @@ function install_tasks_to_display($install_state) { ...@@ -804,12 +805,12 @@ function install_tasks_to_display($install_state) {
function install_get_form($form_id, array &$install_state) { function install_get_form($form_id, array &$install_state) {
// Ensure the form will not redirect, since install_run_tasks() uses a custom // Ensure the form will not redirect, since install_run_tasks() uses a custom
// redirection logic. // redirection logic.
$form_state = array( $form_state = new FormState(array(
'build_info' => array( 'build_info' => array(
'args' => array(&$install_state), 'args' => array(&$install_state),
), ),
'no_redirect' => TRUE, 'no_redirect' => TRUE,
); ));
$form_builder = \Drupal::formBuilder(); $form_builder = \Drupal::formBuilder();
if ($install_state['interactive']) { if ($install_state['interactive']) {
$form = $form_builder->buildForm($form_id, $form_state); $form = $form_builder->buildForm($form_id, $form_state);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Plugin\ConfigurablePluginInterface;
use Drupal\Core\Action\ActionBase; use Drupal\Core\Action\ActionBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginFormInterface; use Drupal\Core\Plugin\PluginFormInterface;
/** /**
...@@ -49,7 +50,7 @@ public function setConfiguration(array $configuration) { ...@@ -49,7 +50,7 @@ public function setConfiguration(array $configuration) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validateConfigurationForm(array &$form, array &$form_state) { public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
} }
/** /**
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\Core\Condition; namespace Drupal\Core\Condition;
use Drupal\Core\Executable\ExecutablePluginBase; use Drupal\Core\Executable\ExecutablePluginBase;
use Drupal\Core\Form\FormStateInterface;
/** /**
* Provides a basis for fulfilling contexts for condition plugins. * Provides a basis for fulfilling contexts for condition plugins.
...@@ -39,7 +40,7 @@ public function isNegated() { ...@@ -39,7 +40,7 @@ public function isNegated() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildConfigurationForm(array $form, array &$form_state) { public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['negate'] = array( $form['negate'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t('Negate the condition.'), '#title' => $this->t('Negate the condition.'),
...@@ -51,13 +52,13 @@ public function buildConfigurationForm(array $form, array &$form_state) { ...@@ -51,13 +52,13 @@ public function buildConfigurationForm(array $form, array &$form_state) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validateConfigurationForm(array &$form, array &$form_state) { public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitConfigurationForm(array &$form, array &$form_state) { public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['negate'] = $form_state['values']['negate']; $this->configuration['negate'] = $form_state['values']['negate'];
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormStateInterface;
/** /**
* Defines a class to build a draggable listing of configuration entities. * Defines a class to build a draggable listing of configuration entities.
...@@ -102,7 +103,7 @@ public function render() { ...@@ -102,7 +103,7 @@ public function render() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form[$this->entitiesKey] = array( $form[$this->entitiesKey] = array(
'#type' => 'table', '#type' => 'table',
'#header' => $this->buildHeader(), '#header' => $this->buildHeader(),
...@@ -138,14 +139,14 @@ public function buildForm(array $form, array &$form_state) { ...@@ -138,14 +139,14 @@ public function buildForm(array $form, array &$form_state) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validateForm(array &$form, array &$form_state) { public function validateForm(array &$form, FormStateInterface $form_state) {
// No validation. // No validation.
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, array &$form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ($form_state['values'][$this->entitiesKey] as $id => $value) { foreach ($form_state['values'][$this->entitiesKey] as $id => $value) {
if (isset($this->entities[$id]) && $this->entities[$id]->get($this->weightKey) != $value['weight']) { if (isset($this->entities[$id]) && $this->entities[$id]->get($this->weightKey) != $value['weight']) {
// Save entity only when its weight was changed. // Save entity only when its weight was changed.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Form\FormBuilderInterface; use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormState;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
...@@ -66,7 +67,7 @@ public function getContentResult(Request $request) { ...@@ -66,7 +67,7 @@ public function getContentResult(Request $request) {
// Add the form and form_state to trick the getArguments method of the // Add the form and form_state to trick the getArguments method of the
// controller resolver. // controller resolver.
$form_state = array(); $form_state = new FormState();
$request->attributes->set('form', array()); $request->attributes->set('form', array());
$request->attributes->set('form_state', $form_state); $request->attributes->set('form_state', $form_state);
$args = $this->controllerResolver->getArguments($request, array($form_object, 'buildForm')); $args = $this->controllerResolver->getArguments($request, array($form_object, 'buildForm'));
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
namespace Drupal\Core\Display; namespace Drupal\Core\Display;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Plugin\PluginDependencyTrait; use Drupal\Core\Plugin\PluginDependencyTrait;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
...@@ -100,7 +101,7 @@ public function calculateDependencies() { ...@@ -100,7 +101,7 @@ public function calculateDependencies() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildConfigurationForm(array $form, array &$form_state) { public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['label'] = array( $form['label'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => $this->t('Label'), '#title' => $this->t('Label'),
...@@ -114,13 +115,13 @@ public function buildConfigurationForm(array $form, array &$form_state) { ...@@ -114,13 +115,13 @@ public function buildConfigurationForm(array $form, array &$form_state) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validateConfigurationForm(array &$form, array &$form_state) { public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitConfigurationForm(array &$form, array &$form_state) { public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['label'] = $form_state['values']['label']; $this->configuration['label'] = $form_state['values']['label'];
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Drupal\Core\Form\ConfirmFormHelper; use Drupal\Core\Form\ConfirmFormHelper;
use Drupal\Core\Form\ConfirmFormInterface; use Drupal\Core\Form\ConfirmFormInterface;
use Drupal\Core\Form\FormStateInterface;
/** /**
* Provides a generic base class for an entity-based confirmation form. * Provides a generic base class for an entity-based confirmation form.
...@@ -53,7 +54,7 @@ public function getFormName() { ...@@ -53,7 +54,7 @@ public function getFormName() {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state); $form = parent::buildForm($form, $form_state);
$form['#title'] = $this->getQuestion(); $form['#title'] = $this->getQuestion();
...@@ -72,7 +73,7 @@ public function buildForm(array $form, array &$form_state) { ...@@ -72,7 +73,7 @@ public function buildForm(array $form, array &$form_state) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function form(array $form, array &$form_state) { public function form(array $form, FormStateInterface $form_state) {
// Do not attach fields to the confirm form. // Do not attach fields to the confirm form.
return $form; return $form;
} }
...@@ -80,7 +81,7 @@ public function form(array $form, array &$form_state) { ...@@ -80,7 +81,7 @@ public function form(array $form, array &$form_state) {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */