Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: symlink project with underscores instead of hyphens #35

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

tyler36
Copy link
Contributor

@tyler36 tyler36 commented Feb 27, 2024

This PR fixes an issue with projects that use 'underscores' in their name.

  • underscores are valid in machine names for Drupal modules,
  • underscores are invalid in hostnames.

This can lead to inconsistency when using a project name as the sym-linked folder name.

Problem

I have a module named 'apple_banana'.

Drupal rules state machine name as "only lower-case letters, digits, and underscores" (https://www.drupal.org/docs/develop/creating-modules/naming-and-placing-your-drupal-module#s-name-your-module)

Given this module is in a directory called apple_banana, I am unable to create a DDEV project in this folder:

$ ddev config
Creating a new DDEV project config in the current directory 
...
Project name (apple_banana):
apple_banana is not a valid project name. Please enter a project name in your configuration that will allow for a valid hostname. See https://en.wikipedia.org/wiki/Hostname#Syntax for valid hostname requirements

If I rename the project folder to apple-banana, DDEV creates successfully. (If not provided, DDEV automatically uses the folder name, here apple-banana, as site name)

When I run ddev symlink-project, the project is linked as web/modules/custom/apple-banana (using $DDEV_SITENAME).

This functions, but leads to a problem with local translations, %project should resolve to the module machine name

'interface translation project': 'apple_banana'
'interface translation server pattern': 'modules/custom/%project/translations/%language.po'

If this was hardcoded with the module name, it would be expecting to find the 'underscored' machine-name version of the module.

@see https://api.drupal.org/api/drupal/core%21modules%21locale%21locale.api.php/group/interface_translation_properties/10

@weitzman
Copy link
Collaborator

weitzman commented Feb 27, 2024

If I rename the project folder to apple-banana, DDEV creates successfully.

Couldn't you have kept the apple_banana folder name and answered the prompt with apple-banana? I'm a bit worried that the mismatch between the folder names is going to break something else. This came up in #20 and we documented a manual fix.

@weitzman
Copy link
Collaborator

For reference, Gitlab Ci calls symlink_project without an argument. That call is at XX and symlink_project itself is at https://git.drupalcode.org/project/gitlab_templates/-/blob/main/scripts/symlink_project.php?ref_type=heads. Ideally our setup matches Gitlab CI as much as possible.

@tyler36
Copy link
Contributor Author

tyler36 commented Feb 28, 2024

Couldn't you have kept the apple_banana folder name and answered the prompt with apple-banana?

Sorry, I don't think I explained the problem (or I'm doing something wrong).
Here are the steps to replicate the problem. I've tried to follow the steps document in the README.

Test

  1. Create project folder "apple_banana"
$ mkdir apple_banana
$ cd apple_banana
  1. Configure DDEV for Drupal 10
$ ddev config --project-name=apple_banana --project-type=drupal10 --docroot=web --create-docroot --php-version=8.1
failed to validate config: apple_banana is not a valid project name.
  1. Config DDEV for Drupal 10 with valid name
$ ddev config --project-name=apple-banana --project-type=drupal10 --docroot=web --create-docroot --php-version=8.1
...
Configuration complete. You may now run 'ddev start'.
  1. Run ddev get ddev/ddev-drupal-contrib
$ ddev get ddev/ddev-drupal-contrib
...
Installed ddev-drupal-contrib:1.0.0-rc12 from ddev/ddev-drupal-contrib
  1. Run ddev start
$ ddev start
Project can be reached at https://apple-banana.ddev.site https://127.0.0.1:32774
...
  1. Run ddev poser
$ ddev poser
...
[5/5] Building fresh packages...
Done in 29.19s.
  1. Run ddev symlink-project
$ ddev symlink-project
...
100  1018  100  1018    0     0   4847      0 --:--:-- --:--:-- --:--:--  4824
  1. Confirm project is linked
$ ddev exec ls web/modules/custom
apple-banana

By default, the addon command commands/web/symlink-project calls php symlink_project.php "$DDEV_SITENAME"
But DDEV_SITENAME=apple-banana

The module apple_banana is symlinked as web/modules/custom/apple-banana ($DDEV_SITENAME).
I expect the module apple_banana to be installed to web/modules/custom/apple_banana.

Am I missing something?

@weitzman weitzman merged commit de1eb04 into ddev:main Feb 29, 2024
2 checks passed
@weitzman
Copy link
Collaborator

Thanks for the excellent steps to reproduce.

@tyler36 tyler36 deleted the 20240227_fix_symlink_naming branch February 29, 2024 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants