← Back

Using AI with Drupal

Using AI with Drupal is not always easy, considering how many entities, fields, custom modules, Twig templates… that a project can include. However, using this powerful tool, as it is the artificial intelligence, is a great way to make your time much more productive and get the best out for your projects.

The context you provide is extremely important, as it helps you to generate and edit code more efficiently. It allows and help you to understand the legacy code, go deeper into specific parts you need, summarize how it works, and give the model a more precise prompt for your needs.

In addition, once you have a clear idea of what your project requires, AI can help you follow best practices and specifications to keep your code consistent, reusable (for example, in the Single Directory Components (SDC)), and easier to maintain and extend.

IDEs and AI tools in my daily workflow

Among all the AI tools available today, in my experience, the ones that best adapt and perform when working with Drupal, are Anthropic's Claude Code and Cursor.

Sometimes, when I need to discuss possible solutions and explore alternatives, I also use ChatGPT, as long as it has the right context, for sure.

Practical use cases

Code refactoring

If we need to understand and improve code, AI can quickly get the general overview and details we could need. In just a few seconds, it help you apply a consistent template to hundred of files (modules, services, Twig templates…), improving the overall code quality.

Assistance with complex logic

In many cases, you need to create custom modules, preprocess certain data from different fields, or generate a specific output.

Discussing the logic step by step with AI and giving it precise instructions can be really useful.

Problems rendering certain fields

If you have issues rendering fields, we can describe them the problem, share what the dump() shows in the entity you're working on, and by providing the full dump() the AI can help you to find the issue much faster and help you to solve it.

Documentation

Once you create a new feature, it's important to write the proper documentation about how it works, its use cases, and even how it can be applied to other projects to make it more extendable.

Using AI not only to generate code but also to create the necessary documentation is essential. It helps summarize the functionality, list all the steps needed to make it work, and highlight the key considerations.

Remember: context is the most important thing. Having the right documentation will make it much faster to understand the project and build new features on top of it.

Conclusion

Using AI with Drupal is not magic, and it might not feel simple at first. But it's a great way to optimize your tasks and save time, helping you understand and improve legacy code, refactor it, and keep your projects consistent and maintainable.