Chi-teck / drupal-code-generator

A code generator for Drupal.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minor issue with `drush generate service:custom`

ultimike opened this issue · comments

Describe the bug
A new custom service is placed in the parameters section of an existing module_name.services.yml file if the parameters section is placed after the services section.

To Reproduce

  1. Create a custom service using drush generate service:custom
  2. Manually add a parameters section the new module_name.services.yml below the services section.
  3. Create a second custom service using drush generate service:custom

Expected behavior
The second service should be added to the services section of module_name.services.yml

Actual behavior
The second service is added to the parameters section of module_name.services.yml

Workaround
Either:

  1. Be sure to manually add the parameters section above the services section of module_name.services.yml
  2. Manually move the definition of the second service created to the services section.

Note: I originally filed this issue here: drush-ops/drush#5267

commented

I dont think this is fixable because the generator doesnt load the file and parse it for meaning. It just appends. This is a known and accepted limitation AFAIK.

That's true.

It's seems natural to use Yaml::decode and Yaml::encode to merge content but in that case we won't be able to preserve the comments and formatting of yaml files.

See symfony/symfony#22516

commented

Be sure to manually add the parameters section above the services section of module_name.services.yml

Drupal core follows that style. Parameters section always goes first.

Roger that - makes sense. Thanks. Closing.

-mike