Skip to main content
Drupal Development

These are few things I picked up and still learning on my Drupal development journey that made my life easier. I love the architecture of Drupal but do find sometimes the amount of code to write, effort and learning curve a bit tedious. But these are all solvable issues. And I have solved them (more or less). Here are some tips for the same.

Configure your IDE for Drupal development

Whether your using Sublime, Atom, NetBeans, VS code, or any other IDE available on the market, there are always plugins that you can enable to provide code formatting for PHP, twig, JS and CSS files. This will provide you with a basic set of suggestions to be a better Drupal developer.
I remember once using NetBeans and it used to always give a warning when a method of function goes over 20 lines. I hated that warning so I made smaller more precise methods and functions. This small thing simplified my code so much it was so easy to debug and find specific functionalities.

Use code generators

Use code generators like Drupal console generate or Drush generate. I usually estimate the task of creating a field type, field widget and field formatter as close to 2-3 days not because of the complexity but because of the amount of code to write. You can save hours of work by using the following commands

  1. drush generate plugin:field:type

  2. drush generate plugin:field:widget

  3. drush generate plugin:field:formatter

Take a break!

When you are stuck or in a rut, take a break, watch a movie, funny videos or whatever you do to relax. I cannot tell you the number of times inspiration struck me after a break or sometimes even during a random activity!

Hardware Limitations?

Try not to be limited by your hardware. An SSD hard disk and 16 GB of RAM is usually sufficient. Your CPU really doesn't matter much for development. A slightly above average one is enough. If you're RAM is sufficient your CPU will take care of everything else.

Use PHPStorm for Drupal development

For those people who are lazy to configure your IDE for a Drupal project, just install PHPStorm and try it out. It will automatically configure everything and prompt you to select the right Drupal and PHP versions. PHPStorm often helps me go deep into the Drupal core and gives me really intuitive suggestions and it can be configured for Symfony as well. I learned a lot after using PHPStorm and still uses it for many of my personal projects.

PHPCS, PHPCBF, Acquia BLT

Configuring these on your machine can be a pain, but I have found an easy way to do this by using Acquia BLT. Acquia BLT has built a wrapper around phpcs that you can include in your Drupal project. You can then use the BLT command `blt validate php` to validate your php files. You can see more here.

Containerized local Drupal development

The mistake most developers make in doing a local setup is to treat your machine like the server. Installing the web server, PHP and MySQL directly on your machine. This can go wrong in so many ways because you are making multiple software changes to your machine and opening ports and making your system vulnerable to attacks.
Instead, use lando, ddev, docksal or drupalvm for your local setup. This means you'll have to install Docker/VirtualBox and one of lando, ddev, docksal  or drupalvm. So if something goes wrong, just delete the containers and start over. You can also bring everything down with one command and bring it back up when you need it.

Save all your useful code, POCs

I always save the important code and POCs that I have worked on previously so that I can refer back to an implementation if I come across the same issue or problem statement again. If you are doing this please make sure you are doing this responsibly and do not reveal code from live projects to anyone and/or break NDAs.

KYC!

Not what you think. What I actually mean is Know Your Command-line. This greatly adds to your speed and it includes your git commands, drush commands, BLT commands, linux commands. I have seen people struggle to copy and paste things on the terminal and get frustrated by it! Know your commands and short-cuts. This will change your life. And I don't mean mug it up. There are a million cheat sheets available online. For example: https://www.guru99.com/linux-commands-cheat-sheet.html. Bookmark them in your browser and use them regularly.

Reasonably Rely on AI

Tools like Chat-GPT and Bard can be really helpful if you use them wisely. I use them mostly to correct my articles, give me ideas on what or how to write articles and occasionally for suggestions when I'm stuck on a bug or task. Apart from this they can also help in figuring out logically tricky code or any syntax you may have forgotten!

Things I use Chat-GPT for:

  • Formatting code, fixing missing html tags in html/twig code.
  • Snippets of small logic, string manipulations, url manipulations, complex loops, arrays etc.
  • Generating random strings, translations, for various applications I'm working on.
  • Writing long mails, analyses etc with input from me of-course.
  • Reasonably fact-checking. Chat-GPT will also tell you if it's not sure of the content.
  • Using the Drupal API for solutions.

Chat GPT drupal config vertical forms

Chat GPT current data in JS

Hope this helps!

x

Work

Therefore logo
80 Atlantic Ave, Toronto, ON Canada
Email: hello@therefore.ca
Call us: +1 4166405376
Linkedin

Let us know how we can help!