New Drupal Pretty Printer Streamlines Automated Code Formatting

Drupal Pretty Printer in Action for Automated Code Formatting with PHP-Parser

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.

Note: The vision of this web portal is to help promote news and stories around the Drupal community and promote and celebrate the people and organizations in the community. We strive to create and distribute our content based on these content policy. If you see any omission/variation on this please reach out to us at #thedroptimes channel on Drupal Slack and we will try to address the issue as best we can.

Upcoming Events

Latest Opportunities