diff -u b/fapi_example/src/Form/BuildDemo.php b/fapi_example/src/Form/BuildDemo.php --- b/fapi_example/src/Form/BuildDemo.php +++ b/fapi_example/src/Form/BuildDemo.php @@ -32,7 +32,7 @@ * {@inheritdoc} */ public function __construct() { - $this->displayMethodInvocation('__contstruct'); + $this->displayMethodInvocation('__construct'); } /** @@ -40,7 +40,7 @@ * processing. * * @param $method_name - * The method being invoked. + * The method being invoked. */ private function displayMethodInvocation($method_name) { self::$_sequence++; diff -u b/fapi_example/src/Form/ContainerDemo.php b/fapi_example/src/Form/ContainerDemo.php --- b/fapi_example/src/Form/ContainerDemo.php +++ b/fapi_example/src/Form/ContainerDemo.php @@ -9,7 +9,6 @@ use Drupal\Core\Form\FormStateInterface; - /** * Implements the container demo form. * @@ -20,13 +19,11 @@ class ContainerDemo extends DemoBase { /** - * Build the simple form. - * - * @inheritdoc + * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - // Details containers replace collapsible field sets in D7. + // Details containers replace D7's collapsible field sets. $form['author'] = [ '#type' => 'details', '#title' => 'Author Info (type = details)', @@ -39,7 +36,7 @@ $form['author']['pen_name'] = [ '#type' => 'textfield', - '#title' => $this->t('Pen Name') + '#title' => $this->t('Pen Name'), ]; // Conventional field set. @@ -58,7 +55,7 @@ '#title' => $this->t('Publisher'), ]; - // Containers have no visual display but wrap any contained elements int a + // Containers have no visual display but wrap any contained elements in a // div tag. $form['accommodation'] = [ '#type' => 'container', @@ -70,14 +67,13 @@ '#value' => $this->t('Special Accommodations (type = container)'), ]; - $form['accommodation'] ['diet'] = [ + $form['accommodation']['diet'] = [ '#type' => 'textfield', '#title' => $this->t('Dietary Restrictions'), ]; - // Convational submit button. $form['actions'] = ['#type' => 'actions']; - // Add a submit button that handles the submission of the form. + $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Submit'), @@ -90,10 +86,7 @@ - * Getter method for Form ID. - * * @inheritdoc */ public function getFormId() { return 'fapi_example_container_demo'; } - -} +} \ No newline at end of file diff -u b/fapi_example/src/Form/DemoBase.php b/fapi_example/src/Form/DemoBase.php --- b/fapi_example/src/Form/DemoBase.php +++ b/fapi_example/src/Form/DemoBase.php @@ -7,25 +7,22 @@ namespace Drupal\fapi_example\Form; - use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; /** * Implements common submit handler used in fapi_example demo forms. * - * This extends FormBase which is the simplest form base class used in Drupal. - * The class is primarily used to provide a common SubmitForm method for other - * form controllers to use. + * We extend FormBase, which is the simplest form base class used in Drupal, to + * add a common submitForm method that will display the submitted values via + * drupal_set_message(). * * @see \Drupal\Core\Form\FormBase - * @see \Drupal\Core\Form\ConfigFormBase */ abstract class DemoBase extends FormBase { /** * Implements a form submit handler. * - * * @param array $form * The render array of the currently built form. * @param FormStateInterface $form_state @@ -36,7 +33,6 @@ $values = $form_state->getValues(); foreach($values as $key => $value) { $label = isset($form[$key]['#title']) ? $form[$key]['#title'] : $key; - // many arrays return 0 for unselected values so lets filter that out. if (is_array($value)) $value = array_filter($value); diff -u b/fapi_example/src/Form/SimpleForm.php b/fapi_example/src/Form/SimpleForm.php --- b/fapi_example/src/Form/SimpleForm.php +++ b/fapi_example/src/Form/SimpleForm.php @@ -47,7 +47,7 @@ // Group submit handlers in an actions element with a key of "actions" so // that it gets styled correctly, and so that other modules may add actions - // to the form. + // to the form. This is not required, but is convention. $form['actions'] = [ '#type' => 'actions', ]; diff -u b/fapi_example/src/Tests/BuildDemoTest.php b/fapi_example/src/Tests/BuildDemoTest.php --- b/fapi_example/src/Tests/BuildDemoTest.php +++ b/fapi_example/src/Tests/BuildDemoTest.php @@ -47,16 +47,17 @@ // Verify that anonymous can access the page. $this->drupalGet('examples/fapi_example/build_demo'); - $this->assertResponse(200, 'The Demo of Modal Form is available.'); + $this->assertResponse(200, 'The Build Demoq Form is available.'); // Post the form. $edit = [ 'change' => '1', ]; $this->drupalPostForm('/examples/fapi_example/build_demo', $edit, t('Submit')); - $this->assertText('getFormId 1'); - $this->assertText('validateForm 1'); - $this->assertText('submitForm 1'); + $this->assertText('1. __construct'); + $this->assertText('2. getFormId'); + $this->assertText('3. validateForm'); + $this->assertText('4. submitForm'); } }