Sorry, you need to enable JavaScript to visit this website.
Brown Wooden Dock

News Web Development

Drupal core comes "battery-included", the simplistic UI means that a site requires minimal configuration before it hits the ground running. This is further supported by the vast ecosystem of community modules and themes, facilitating the majority of functionality through a simple 'plug-and-play' approach. 

However, hidden deep inside the Drupal codebase is a plethora of core libraries with the ability to power everything, Drupal core APIs allow us to go beyond what is imaginable and transform Drupal into more than just a CMS.

In this post, we will look into how the Entity API aids us in the development of an advanced web application, as seen in our work with Clearing House.

 

Object-Relational Mapping

With any web application that works with data storage, a critical step is database design. An Object-Relational Mapping (ORM) abstracts away the nitty-gritty of database syntax and allows developers to deal with database design in an Object-Oriented context. In Drupal, this is further extended to support features such as:

  • cardinality
  • data validation
  • date time conversion
  • auto-management of references to other models

In our work with Clearing House, this dramatically advanced project progress as we were not bogged down by the implementation of the data model. Instead, we were able to focus on linking functionalities between our custom entities. 

 

What does Drupal bring to the table?

 

Annotation declaration

Like many other core APIs, the Entity API utilises the annotation declaration to signify many essential properties. Instead of needing to dig through individual functions, source files can be read, understood and configured in a time-efficient manner.

 

Sensible defaults and base classes

With a strong supporting cast of base classes in the code base, the Developer Experience (DX) is also very much plug-and-play. Any generic functionality you can think of, such as timestamping when an entity is modified or tying an entity to a particular user as its owner, can all be integrated with a single line.

 

Neat integration with other Drupal core functionality

Once you have created your custom entities, they can then be read and used anywhere else by Drupal. One particular powerful integration is the Views API which allows site maintainers to easily create new view displays, similar to how nodes and other content can be displayed.

We have also created references from course content pages to our custom Course entities. This allows information to be pulled through a central source of truth and displayed on multiple separate content pages, all configured via the UI.

 

Familiar configurability

If you have been a content manager for a long time, you will find many of the same features present by default when you configure your shiny new entity. Settings such as form and view mode, form and view display all come included; the only step left is to hook up the relevant templates and form classes, however, as mentioned above, there are plenty of defaults available.

In addition to the crucial fields that an entity cannot work without, they can also be made fieldable to integrate with Drupal's Field API, allowing users/site maintainers to introduce changes to the entity without interfering with its core functionality. This is particularly handy when there is a request to have a degree of control as use cases change in the future.

 

Developer flexibility

Going beyond the UI and diving into custom code, establishing our entities via Drupal further allows us to leverage other significant services provided by Drupal, especially the entity type manager and its derivative. Retrieving information directly from the database was replaced with sensible usage of various Drupal services, which in turn made our code more readable and maintainable.

 

Conclusion

Drupal has established a reputation for being an all-in-one content management system with resounding community support. However, do not let that fool you into thinking that is all it can do. Throughout the years we have seen it being used as an e-Commerce storefront, a knowledge base, an educational platform etc.

The potential is limitless and what we have discussed above is just a glimpse of how far you can branch out from traditional "content management" with Drupal.