I'm adding a form element directly into a render array, and there isn't a default value for $description_display being set, since I'm not running it through FormBuilder. So my page is throwing a warning and the description doesn't display.

Keep the current behavior the default of the description being after
by adding
+ '#description_display' => 'after',
to core/lib/Drupal/Core/Form/FormBuilder.php
which all forms use.

It seems like there should be a better place to put the default?

Issue fork drupal-2717377

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mdfleury created an issue. See original summary.

Version: 8.0.5 » 8.0.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.0.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
catch’s picture

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

aayushpathak’s picture

working on it ...

aayushpathak’s picture

Status: Active » Needs review

Added fallback handling for missing #description_display in FormPreprocess to preserve the default 'after' behavior and avoid warnings.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

This one appears to need a summary update:.

Always wonder vs adding a fallback if there’s a bug somewhere and this fix is masking a different issue?

Maybe a test case could help figure that out

aayushpathak’s picture

Status: Needs work » Needs review

Thanks for the review. Updated the issue summary and added regression test coverage to verify the behavior when elements bypass FormBuilder.
The tests reproduce the missing #description_display case and confirm the fallback preserves the existing default after behavior without affecting explicit values.

CI is also passing.

smustgrave’s picture

Status: Needs review » Needs work

There not an existing test we could expand vs a brand new one?

aayushpathak’s picture

Searched the existing test suite under core/tests/Drupal/Tests/Core/Form/ — there is currently no existing test covering FormPreprocess or preprocessFormElement. So a new test class appears to be the only option here. Happy to be pointed to a specific file if there is one in mind.