diff -u b/form_example/src/Forms/FormExampleTutorial.php b/form_example/src/Forms/FormExampleTutorial.php --- b/form_example/src/Forms/FormExampleTutorial.php +++ b/form_example/src/Forms/FormExampleTutorial.php @@ -6,6 +6,7 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; /** * This first form function is from the @link http://drupal.org/node/717722 Form Tutorial handbook page @endlink @@ -30,7 +31,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'item', @@ -50,8 +51,8 @@ */ - public function validateForm(array &$form, array &$form_state) {} + public function validateForm(array &$form, FormStateInterface $form_state) {} /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state) {} } diff -u b/form_example/src/Forms/FormExampleTutorial10.php b/form_example/src/Forms/FormExampleTutorial10.php --- b/form_example/src/Forms/FormExampleTutorial10.php +++ b/form_example/src/Forms/FormExampleTutorial10.php @@ -5,11 +5,10 @@ */ namespace Drupal\form_example\Forms; - - use Drupal\Core\Form\FormBase; use Drupal\file\Entity\File; use Drupal\file\FileInterface; +use Drupal\Core\Form\FormStateInterface; @@ -35,7 +34,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { // If you are familiar with how browsers handle files, you know that // enctype="multipart/form-data" is required. Drupal takes care of that, so @@ -61,7 +60,7 @@ * Validate function for form_example_tutorial_10(). * */ - public function validateForm(array &$form, array &$form_state) { + public function validateForm(array &$form, FormStateInterface $form_state) { $file = file_save_upload('file', array( // Validates file is really an image. @@ -82,18 +81,18 @@ } else { ; - $this->setFormError('file', $form_state, t("Failed to write the uploaded file to the site's file folder.")); + $form_state->setErrorByName('file', t("Failed to write the uploaded file to the site's file folder.")); } } else { - $this->setFormError('file', $form_state, t('No file was uploaded.')); + $form_state->setErrorByName('file', t('No file was uploaded.')); } } /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) { + public function submitForm(array &$form, FormStateInterface $form_state) { $file = $form_state['storage']['file']; // We are done with the file, remove it from storage. diff -u b/form_example/src/Forms/FormExampleTutorial2.php b/form_example/src/Forms/FormExampleTutorial2.php --- b/form_example/src/Forms/FormExampleTutorial2.php +++ b/form_example/src/Forms/FormExampleTutorial2.php @@ -6,6 +6,8 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; + /** * This is Example 2, a basic form with a submit button. @@ -25,7 +27,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'item', @@ -52,8 +54,8 @@ */ - public function validateForm(array &$form, array &$form_state) {} + public function validateForm(array &$form, FormStateInterface $form_state) {} /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state) {} } diff -u b/form_example/src/Forms/FormExampleTutorial3.php b/form_example/src/Forms/FormExampleTutorial3.php --- b/form_example/src/Forms/FormExampleTutorial3.php +++ b/form_example/src/Forms/FormExampleTutorial3.php @@ -6,6 +6,8 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; + /** * Example 3: A basic form with fieldsets. @@ -32,7 +34,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'item', '#title' => t('A form with a fieldset'), @@ -76,8 +78,8 @@ */ - public function validateForm(array &$form, array &$form_state) {} + public function validateForm(array &$form, FormStateInterface $form_state) {} /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state) {} } diff -u b/form_example/src/Forms/FormExampleTutorial4.php b/form_example/src/Forms/FormExampleTutorial4.php --- b/form_example/src/Forms/FormExampleTutorial4.php +++ b/form_example/src/Forms/FormExampleTutorial4.php @@ -6,6 +6,7 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; /** * Example 4: Basic form with required fields. @@ -24,7 +25,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'item', '#title' => t('A form with required fields'), @@ -68,8 +69,8 @@ */ - public function validateForm(array &$form, array &$form_state) {} + public function validateForm(array &$form, FormStateInterface $form_state) {} /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state) {} } diff -u b/form_example/src/Forms/FormExampleTutorial5.php b/form_example/src/Forms/FormExampleTutorial5.php --- b/form_example/src/Forms/FormExampleTutorial5.php +++ b/form_example/src/Forms/FormExampleTutorial5.php @@ -6,6 +6,7 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; /** * Example 5: Basic form with additional element attributes. @@ -31,7 +32,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'item', '#title' => t('A form with additional attributes'), @@ -79,8 +80,8 @@ */ - public function validateForm(array &$form, array &$form_state) {} + public function validateForm(array &$form, FormStateInterface $form_state) {} /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state) {} } diff -u b/form_example/src/Forms/FormExampleTutorial6.php b/form_example/src/Forms/FormExampleTutorial6.php --- b/form_example/src/Forms/FormExampleTutorial6.php +++ b/form_example/src/Forms/FormExampleTutorial6.php @@ -6,6 +6,7 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; /** * Example 6: A basic form with a validate handler. @@ -24,7 +25,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'item', '#title' => t('A form with a validation handler'), @@ -84,13 +85,13 @@ */ - public function validateForm(array &$form, array &$form_state) { + public function validateForm(array &$form, FormStateInterface $form_state) { $year_of_birth = $form_state['values']['year_of_birth']; if ($year_of_birth && ($year_of_birth < 1900 || $year_of_birth > 2000)) { - $this->setFormError('year_of_birth', $form_state, t('Enter a year between 1900 and 2000.')); - } + $form_state->setErrorByName('year_of_birth', t('Enter a year between 1900 and 2000.')); + } } /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) {} + public function submitForm(array &$form, FormStateInterface $form_state) {} } diff -u b/form_example/src/Forms/FormExampleTutorial7.php b/form_example/src/Forms/FormExampleTutorial7.php --- b/form_example/src/Forms/FormExampleTutorial7.php +++ b/form_example/src/Forms/FormExampleTutorial7.php @@ -6,6 +6,7 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; /** * Example 7: A basic form with a validate handler. @@ -24,7 +25,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { $form['description'] = array( '#type' => 'item', '#title' => t('A form with a validation handler'), @@ -83,20 +84,20 @@ * function. An alternate list of validation functions could have been provided * in $form['#validate']. */ - public function validateForm(array &$form, array &$form_state) { + public function validateForm(array &$form, FormStateInterface $form_state) { $year_of_birth = $form_state['values']['year_of_birth']; // Validate birthday year if ($year_of_birth && ($year_of_birth < 1900 || $year_of_birth > 2000)) { - $this->setFormError('year_of_birth', $form_state, t('Enter a year between 1900 and 2000.')); + $form_state->setErrorByName('year_of_birth', t('Enter a year between 1900 and 2000.')); } } /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) { + public function submitForm(array &$form, FormStateInterface $form_state) { if ($form_state['values']['op'] == t('Submit')) { drupal_set_message(t('The form has been submitted. name="@first @last", year of birth=@year_of_birth', array('@first' => $form_state['values']['first'], '@last' => $form_state['values']['last'], '@year_of_birth' => $form_state['values']['year_of_birth']))); diff -u b/form_example/src/Forms/FormExampleTutorial8.php b/form_example/src/Forms/FormExampleTutorial8.php --- b/form_example/src/Forms/FormExampleTutorial8.php +++ b/form_example/src/Forms/FormExampleTutorial8.php @@ -6,6 +6,9 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; + + /** * Example 8: A simple multistep form with a Next and a Back button. * @@ -33,7 +36,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { if (empty($form_state['page_values'])) $form_state['page_values'] = array(); if (empty($form_state['page_num'])) $form_state['page_num'] = 1; // Build different form fields based on the $form['page_num'] value @@ -61,12 +64,12 @@ * function. An alternate list of validation functions could have been provided * in $form['#validate']. */ - public function validateForm(array &$form, array &$form_state) { + public function validateForm(array &$form, FormStateInterface $form_state) { if(!empty($form_state['page_num']) && $form_state['page_num'] == 1) { $year_of_birth = $form_state['values']['year_of_birth']; // Validate birthday year if ($year_of_birth && ($year_of_birth < 1900 || $year_of_birth > 2000)) { - $this->setFormError('year_of_birth', $form_state, t('Enter a year between 1900 and 2000.')); + $form_state->setErrorByName('year_of_birth', t('Enter a year between 1900 and 2000.')); } } // if (!empty($form_state['page_num']) && $form_state['page_num'] == 2) {} @@ -75,7 +78,7 @@ /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) { + public function submitForm(array &$form, FormStateInterface $form_state) { // Normally, some code would go here to alter the database with the data // collected from the form. Instead sets a message with drupal_set_message() // to validate that the code worked. diff -u b/form_example/src/Forms/FormExampleTutorial9.php b/form_example/src/Forms/FormExampleTutorial9.php --- b/form_example/src/Forms/FormExampleTutorial9.php +++ b/form_example/src/Forms/FormExampleTutorial9.php @@ -6,6 +6,8 @@ namespace Drupal\form_example\Forms; use Drupal\Core\Form\FormBase; +use Drupal\Core\Form\FormStateInterface; + /** * Example 9: A form with a dynamically added new fields. * @@ -32,7 +34,7 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state) { + public function buildForm(array $form, FormStateInterface $form_state) { // We will have many fields with the same name, so we need to be able to // access the form hierarchically. $form['#tree'] = TRUE; @@ -111,12 +113,12 @@ * Adds logic to validate the form to check the validity of the new fields, * if they exist. */ - public function validateForm(array &$form, array &$form_state) { + public function validateForm(array &$form, FormStateInterface $form_state) { for ($i = 1; $i <= $form_state['num_names']; $i++) { $year_of_birth = $form_state['values']['name'][$i]['year_of_birth']; if ($year_of_birth && ($year_of_birth < 1900 || $year_of_birth > 2000)) { - $this->setFormError("name][$i][year_of_birth", $form_state, t('Enter a year between 1900 and 2000.')); + $form_state->setErrorByName("name][$i][year_of_birth", t('Enter a year between 1900 and 2000.')); } } } @@ -124,7 +126,7 @@ /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) { + public function submitForm(array &$form, FormStateInterface $form_state) { $output = t("Form 9 has been submitted."); for ($i = 1; $i <= $form_state['num_names']; $i++) { $output .= t("@num: @first @last (@date)...",