Form Inspector module, when forms grow out of control. Contributing to the Drupal community

Andrés Camilo Moncada Barrios
Globant
Published in
3 min readAug 31, 2020

One of the greatest appeals of Drupal is its ever-growing and active community, it is unquestionable, feeling the support of a committed and enthusiastic group behind a project like this allows us to recommend it without reservations. It is for this reason that contributing to the improvement and growth of the CMS is a perfect option to give back a little of what has been received by seducing new developers and increasing the quality and quantity of this great family.

A good practice to achieve this purpose is to make a detailed retrospective diagnosis of the programming experience, identifying needs or persistent difficulties that are common cross cases throughout the development process. Once detected, it is essential to ask yourself some questions such as How much time do I lose in these recurring tasks? Are they necessary? How should this procedure ideally be?

In my particular case, it became clear that optimizing forms management would be an excellent alternative to improve my work and the conditions of those who have faced complex and evolving forms.

Undoubtedly, the versatility provided by Drupal for content management using forms is a significant advantage widely valued by developers and publishers. However, when we use these in projects in constant expansion whose contents are continually growing, their administration can become a real headache.

Although the Paragraphs module is a great help providing dynamism to the contents and allowing the reuse of fields through the construction of forms from smaller pieces, its excessive use can lead to strongly nested structures where finding field origin becomes complicated.

To make the maintenance of this type of forms easier, Form Inspector has arrived, this module offers the developer a clear and precise vision of the ancestors of each field via HTML comments. In this way, it is possible to find a specific field location and have an overview of the whole form structure.

Additionally, the module provides contextual links that allow you to edit fields quickly and efficiently, whether they are simple input fields or elaborated widgets.

The first step for its implementation was to store each field ancestor by including a static variable in the method responsible for the recursive form building in a class based on EntityFormDisplay, the value of the variable is added in a form property so that it is accessible in subsequent alterations.

Next, FormInspectorManager was implemented in charge of the alterations in the form to add HTML comments and contextual links. It is vital to ensure that data-contextual-id is unique so that links will work correctly in multi-valued paragraph fields.

To create contextual links, a new FormInspectorContextualLinks class is accountable for generating the derivatives for each bundle.

The contribution of this module was a positive and enriching experience. It has challenged my technical knowledge, stimulated my creativity, and generated a strong sense of belonging. In conclusion, even though an idea may seem simple and unimportant, it can produce a tremendous impact on the daily lives of many people. It is only needed to take the initiative and begin to build a legacy capable of uniting the members of the community around the same objective and last over time.

For more information, please visit https://www.drupal.org/project/form_inspector.

--

--