New Drupal Pretty Printer Streamlines Automated Code Formatting
A new PHP code formatting utility built for Drupal developers is now available on Packagist. The tool, chx/drupal-pretty-printer
, uses the widely adopted nikic/php-parser
library to output PHP that adheres to Drupal coding standards after code transformation.
The class was originally developed by Fran Garcia-Linares for use in the api.module
. Karoly Negyesi, a longtime contributor to the Drupal project, adapted it for broader use. He made the tool compatible with both versions 4 and 5 of php-parser
, fixed minor issues, added automated testing, and published it on GitHub.
The printer is already being integrated into automation tools such as Joachim Noreiko’s Module Builder and Björn Brala’s Drupal Rector. Negyesi also plans to use the utility to introduce builder-pattern helpers in Drupal core, easing the process of generating render arrays.
The project has already moved quickly past its initial release—Negyesi just tagged version 0.3. In a LinkedIn comment, he noted the rapid pace is driven by ongoing work on a core Drupal issue that depends on the printer’s behavior, underscoring its active development despite being in early versions.
The package can be installed via Composer:
composer require chx/drupal-pretty-printer
Source code, usage examples, and documentation are available on GitHub.