drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

Generating SDC creates slot in twig file, but not component.yml file #6131

Closed lostcarpark closed 3 weeks ago

lostcarpark commented 1 month ago

Describe the bug Running drush generate sdc creates a single directory component.

Components may contain props and slots.

The generator asks if I want to create props, but not slots. props are correctly added to the props section of the component.

However, the created component has attempts to use a slot called "example_block" without it being defined in the slots section of the component.yml file. This results in a compiler error when attempting to use the default component.

To Reproduce

I ran drush generate sdc, selected a theme name and component name, specified no properties, and used defaults for all other options.

The generated .twig file contains the following:

  {% block example_block %}
    The contents of the example block
  {% endblock %}

This implements a slot called "example_block". However, as there are no slots defined in the .component.yml file.

When attempting to view the generated component, the use of an undefined slot results in a compile error.

Expected behavior If the default .twig file contains a {% block %}, the block should be defined in the .component.yml.

The simple fix would be to add the slots section to the .component.yml file.

An even better fix would be to ask about slots after the questions about props, and create a {% block %} item for each slot, and a matching entry in .component.yml.

Actual behavior The current default component results in a compile error.

Workaround It's fairly simple to fix, either by removing the block and endblock, or by adding the slot definition. However, it would be great if new users were given a working component out of the box.

System Configuration

Q A
Drush version? 12.5.2.0
Drupal version? 10.3
PHP version 8.2
OS? Linux

Additional information None.

PierrePaul commented 1 month ago

Hey @lostcarpark ! Since it's about the code generation module of Drush, do you mind moving your issue into the drupal-code-generator issue queue? I will start a PR right away.

Thanks!

PierrePaul commented 3 weeks ago

I moved the issue into the drupal-code-generator issue queue : https://github.com/Chi-teck/drupal-code-generator/issues/190

We can close this one.