From 3653c51c98398b0cfeeb2223205c1df90088a79c Mon Sep 17 00:00:00 2001 From: Ryan Koch <6863534+ryguyk@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:32:53 -0600 Subject: [PATCH] VAGOV-TEAM-97920: Form Builder Navbar (#20149) * VAGOV-TEAM-97920: - Renames form-builder theme and sets it as page-level theme. * Allows for active tab to be set on each path. * Updates page template and styles for navbar * Removes unnecessary properties from base form. * Adds id class to each navbar tab * Adds unpkg external stylesheet to the module-defined library. * Attaches styles at page level rather than form level. * Adds unit test for libraries.yml. * Updates existing test suites. * Updates class names in test to reflect changes in template. --- .../css/va_gov_form_builder.css | 90 ++++++++++++++++++- .../Controller/VaGovFormBuilderController.php | 45 +++++++++- .../src/Form/Base/FormBuilderBase.php | 22 ++--- .../page--va-gov-form-builder.html.twig | 70 ++++++++++----- .../va_gov_form_builder.libraries.yml | 2 + .../va_gov_form_builder.module | 6 +- .../VaGovFormBuilderControllerTest.php | 31 +++++-- .../functional/Form/IntroTest.php | 14 ++- .../functional/Form/NameAndDobTest.php | 20 +++-- .../functional/Form/StartConversionTest.php | 23 +++-- .../templates/FormBuilderPageTemplateTest.php | 4 +- .../unit/Form/Base/FormBuilderBaseTest.php | 29 +----- .../unit/LibrariesTest.php | 71 +++++++++++++++ .../va_gov_form_builder/unit/ModuleTest.php | 10 +-- 14 files changed, 332 insertions(+), 105 deletions(-) create mode 100644 tests/phpunit/va_gov_form_builder/unit/LibrariesTest.php diff --git a/docroot/modules/custom/va_gov_form_builder/css/va_gov_form_builder.css b/docroot/modules/custom/va_gov_form_builder/css/va_gov_form_builder.css index e5f1ffc8dc..80bc63ece9 100644 --- a/docroot/modules/custom/va_gov_form_builder/css/va_gov_form_builder.css +++ b/docroot/modules/custom/va_gov_form_builder/css/va_gov_form_builder.css @@ -1,4 +1,92 @@ /* page container */ -.va-gov-form-builder-page-container { +.form-builder-page-container { font-family: var(--font-family-serif); } + +/* headings */ +.form-builder-page-container h1 { + font-size: var(--vads-font-size-heading-level-1); + line-height: var(--units-6); +} + +.form-builder-page-container h2 { + font-size: var(--vads-font-size-heading-level-2); +} + +.form-builder-page-container h2 { + font-size: var(--vads-font-size-heading-level-2); +} + +.form-builder-page-container h3 { + font-size: var(--vads-font-size-heading-level-3); +} + +.form-builder-page-container h4 { + font-size: var(--vads-font-size-heading-level-4); +} + +.form-builder-page-container h5 { + font-size: var(--vads-font-size-heading-level-5); +} + +.form-builder-page-container h6 { + font-size: var(--vads-font-size-heading-level-6); +} + +/* header */ +.form-builder-header { + background-color: var(--va-blue-darkest); + color: var(--va-white); + padding-top: var(--units-1); +} + +/* layout container */ +.form-builder-layout-container { + margin: 0 var(--units-7); +} + +/* title */ +.form-builder-title { + margin-bottom: var(--units-1p5); +} + +/* navbar */ +.form-builder-navbar__nav { + display: flex; +} + +.form-builder-navbar__tabs { + display: flex; + gap: var(--units-5); + list-style: none; + margin: 0; +} + +.form-builder-navbar__tab { + min-width: 100px; + padding: var(--units-1); + position: relative; + text-align: center; +} + +.form-builder-navbar__tab--active { + border-bottom: var(--units-0p5) solid var(--uswds-system-color-gold-vivid-20); +} + +.form-builder-navbar__link { + color: var(--vads-color-white); + font-size: var(--font-size-lg); + font-weight: var(--font-weight-bold); + line-height: var(--vads-font-line-height-default); + text-decoration: none; +} + +.form-builder-navbar__link:hover { + background: transparent; + color: var(--vads-color-white); +} + +.form-builder-navbar__tab--active .form-builder-navbar__link, +.form-builder-navbar__tab--active .form-builder-navbar__link:hover { + color: var(--uswds-system-color-gold-vivid-20); +} diff --git a/docroot/modules/custom/va_gov_form_builder/src/Controller/VaGovFormBuilderController.php b/docroot/modules/custom/va_gov_form_builder/src/Controller/VaGovFormBuilderController.php index 82308e899b..5217021410 100644 --- a/docroot/modules/custom/va_gov_form_builder/src/Controller/VaGovFormBuilderController.php +++ b/docroot/modules/custom/va_gov_form_builder/src/Controller/VaGovFormBuilderController.php @@ -31,6 +31,13 @@ class VaGovFormBuilderController extends ControllerBase { */ private $drupalFormBuilder; + /** + * The active tab in the form builder. + * + * @var 'forms'|'content'|'layout' + */ + private $activeTab; + /** * {@inheritdoc} */ @@ -41,6 +48,34 @@ public static function create(ContainerInterface $container) { return $instance; } + /** + * Returns a render array representing the page with the passed-in form. + * + * @param string $formName + * The filename of the form to be rendered. + * @param string $nid + * The node id, passed in when the form in question edits an existing node. + */ + private function getFormPage($formName, $nid = NULL) { + // @phpstan-ignore-next-line + $form = $this->drupalFormBuilder->getForm('Drupal\va_gov_form_builder\Form\\' . $formName, $nid); + + return [ + '#type' => 'page', + 'content' => $form, + // Add custom data. + 'form_builder_page_data' => [ + 'active_tab' => $this->activeTab, + ], + // Add styles. + '#attached' => [ + 'library' => [ + 'va_gov_form_builder/va_gov_form_builder_styles', + ], + ], + ]; + } + /** * Entry point for the VA Form Builder. Redirects to the intro page. */ @@ -52,22 +87,24 @@ public function entry() { * Intro page. */ public function intro() { - return $this->drupalFormBuilder->getForm('Drupal\va_gov_form_builder\Form\Intro'); + $this->activeTab = 'forms'; + return $this->getFormPage('Intro'); } /** * Start-conversion page. */ public function startConversion() { - return $this->drupalFormBuilder->getForm('Drupal\va_gov_form_builder\Form\StartConversion'); + $this->activeTab = 'forms'; + return $this->getFormPage('StartConversion'); } /** * Name-and-date-of-birth page. */ public function nameAndDob($nid) { - // @phpstan-ignore-next-line - return $this->drupalFormBuilder->getForm('Drupal\va_gov_form_builder\Form\NameAndDob', $nid); + $this->activeTab = 'content'; + return $this->getFormPage('NameAndDob', $nid); } } diff --git a/docroot/modules/custom/va_gov_form_builder/src/Form/Base/FormBuilderBase.php b/docroot/modules/custom/va_gov_form_builder/src/Form/Base/FormBuilderBase.php index fdf2f6c7c2..da73db7070 100644 --- a/docroot/modules/custom/va_gov_form_builder/src/Form/Base/FormBuilderBase.php +++ b/docroot/modules/custom/va_gov_form_builder/src/Form/Base/FormBuilderBase.php @@ -12,25 +12,13 @@ abstract class FormBuilderBase extends FormBase { /** * {@inheritdoc} + * + * After initially containing some logic, this function + * is now empty, and this entire class is a candiate + * for removal. Leaving it here for now, as it might prove + * necessary as we continue on. */ public function buildForm(array $form, FormStateInterface $form_state) { - $form['#theme'] = 'va_gov_form_builder'; - $form['#title'] = $this->t('Form Builder'); - - // Add styles. - $form['#attached']['html_head'][] = [ - [ - '#tag' => 'link', - '#attributes' => [ - 'rel' => 'stylesheet', - 'href' => 'https://unpkg.com/@department-of-veterans-affairs/css-library@0.16.0/dist/tokens/css/variables.css', - ], - ], - 'external_stylesheet', - ]; - $form['#attached']['library'][] = 'va_gov_form_builder/va_gov_form_builder_styles'; - - return $form; } } diff --git a/docroot/modules/custom/va_gov_form_builder/templates/page--va-gov-form-builder.html.twig b/docroot/modules/custom/va_gov_form_builder/templates/page--va-gov-form-builder.html.twig index 86efcd7ae3..0bc5004f56 100644 --- a/docroot/modules/custom/va_gov_form_builder/templates/page--va-gov-form-builder.html.twig +++ b/docroot/modules/custom/va_gov_form_builder/templates/page--va-gov-form-builder.html.twig @@ -3,38 +3,66 @@ * @file * VA.gov Form Builder's implementation of a single page. * - * Nearly identical to VAgovClaro's implementation, except: - * - An outermost page container has been added. - * - The header includes additional content (navbar, eventually) - * - Breadcrumbs have been removed + * The variables available to this template are passed from the controller: + * - page + * - content: The main content of the page; the individual form + * - form_builder_page_data + * - active_tab: The active tab in the navbar * - * For more information: - * @see docroot/themes/custom/vagovclaro/templates/page/page.html.twig + * @see /docroot/modules/custom/va_gov_form_builder/src/Controller/VaGovFormBuilderController.php */ #} -