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

Drupal support #2

Open
tanc opened this issue Oct 14, 2023 · 5 comments
Open

Drupal support #2

tanc opened this issue Oct 14, 2023 · 5 comments
Labels
feature New feature or request help wanted Extra attention is needed

Comments

@tanc
Copy link

tanc commented Oct 14, 2023

Hi @moetelo, I'm trying your fork on a Drupal project. Opening the project and looking at the Twig Language Server output I see:

Language server started for: /my-file-path/my-project
Twig info not initialized

Is there any way to tell why the Twig info is not initialising?

@moetelo
Copy link
Owner

moetelo commented Oct 14, 2023

Hi @tanc, could you tell me the templates directory for your project, relative to the workspace directory?

The mechanism of definitionProvider defaults to workspaceDirectory/templates. If your templates are stored there, the definition would work.

And have you tried to Ctrl+Click any of the template inclusion statements/functions?
e.g {{ include('template.html.twig') }}. Click the template.html.twig part.


Twig info not initialized

The extension calls a Symfony command to get custom developer-defined twig functions, globals and filters. Since your project is based not on the Symfony framework, this won't work. The other features should work as expected.

I will change the output message to better represent that behavior.

@tanc
Copy link
Author

tanc commented Oct 14, 2023

The templates directory is at web/themes/custom/[theme_name] but with Drupal projects they can be set up in all sorts of ways and in different locations.

So I guess it would be good to have a workspace level config option for defining the templates directory or directories.

Control clicking includes don't work for me. But it could be because the use string interpolation with a variable, like: {{ include(directory ~ '/templates/misc/steps.html.twig') }}

@moetelo
Copy link
Owner

moetelo commented Oct 14, 2023

Is it possible to get all template directories programmatically?

string interpolation with a variable

Yep, that's not supported

@moetelo moetelo changed the title Twig info not initialized Drupal — definition suppport Oct 15, 2023
@moetelo
Copy link
Owner

moetelo commented Oct 16, 2023

@tanc

workspace level config option for defining the templates directory or directories

What setting format could be good for Drupal case?

I'm thinking of adding a new extension setting:

"twiggy.tempateMappings": [
  // include('template.html.twig') -> ./templates/template.html.twig
  { "alias": "", "path": "./templates" },

  // include('@custom_theme_name/template.html.twig') -> ./web/themes/custom_theme_name/templates/template.html.twig
  { "alias": "@custom_theme_name", "path": "./web/themes/custom_theme_name/templates/" },
],

This would work for Drupal projects as well as for other non-Symfony projects.

But as far as I can see from Drupal quick start project (Download Drupal page, web/core/scripts/drupal quick-start demo_umami), there is some layer of additional magic for templates resolving under the hood.
For example, in web/core/modules/node/templates/field--node--title.html.twig the {% include "field.html.twig" %} line should resolve to web/core/modules/system/templates/field.html.twig, if my guess is correct.

@moetelo moetelo added the help wanted Extra attention is needed label Oct 23, 2023
@moetelo moetelo changed the title Drupal — definition suppport Drupal support Apr 6, 2024
@moetelo
Copy link
Owner

moetelo commented Apr 6, 2024

Will take a second look here after #10 is resolved.
Drupal experts are welcome to come here and drop a snippet close to this: #10 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants