Exploring Contenta CMS

contenta cms

A great place to start a conversation about decoupled Drupal is evaluating Contenta CMS. While Contenta CMS is not necessarily something you must have to build a decoupled Drupal 8 site, it is designed to do it. You can relatively easily create a vanilla Drupal site that supports a decoupled application, but Contenta has already solved many of the related problems.

So what is Contenta CMS exactly? 

Contenta CMS is an API-first Drupal 8 distribution intended to be used to build fully decoupled Drupal sites. It was built by the developers of many of the modules you may end up using as you build your decoupled site, using their defined best practices to address typical needs and challenges. It is meant to be 100% decoupled, and only uses Drupal 8 as an administrative backend with no user-facing HTML content. This is something you could change if you desired to do so.

At first it seemed like a magical, mysterious system. However, Contena uses core and well-known contributed modules with only a single custom module that provides a few customizations. With only a few small tweaks, you could conceivably have a base system for your decoupled project with Contenta CMS as you would any Drupal 8 project.

Features

The main difference between Contenta CMS and a site you would conceivably build yourself lies in the only custom module the distribution comes with, Contenta Enhancements. This module primarily does a few things:

  • creates a new, streamlined administration toolbar for a decoupled site,
  • provides some additional local tasks menu items giving easy access to necessary configuration,
  • alters the node view to display JSON instead of HTML, allowing for easy viewing of node structure, and
  • disables certain routes not needed or necessarily useful for a decoupled site.

Because this is a Drupal module, you’re perfectly fine installing it in your own clean Drupal 8 install to try to replicate Contenta along with the contributed modules used.

Key Modules

The following modules make up the underlying Contenta architecture.

Consumers

Consumers is a utility module that allows other modules to define users of the API and then further allows administrators to manage access control for each consumer. 

Decoupled Router

As the module description states, "Decoupled Router provides an endpoint that will help you resolve path aliases and redirects for entity related routes. This is especially useful for decoupled applications where the editor wants full control over the paths available in the consumer application (for instance a React app)."

To further understand the purpose of Decoupled Router, read the great post (and series) by the module creator.

JSON:API (now part of Drupal 8.7 Core)

JSON:API is a plug and play module that fully implements the JSON:API Specification that without configuration exposes your Drupal entities via a REST API.

JSON:API Extras

JSON:API Extras extends the JSON:API module by allowing customizations and management of API endpoints. The JSON:API module does not offer any configuration options.

JSON-RPC

While JSON:API exposes Drupal entities via a REST API, JSON-RPC exposes Drupal administrative actions that would otherwise not be easily accessible or handled using the REST API.

OpenAPI

The OpenAPI is a utility module that allows your Web Services to be discoverable using the OpenAPI standard and thus neatly documented for testing and development when used in addition the OpenAPI UI and either something like OpenAPI UI Redoc or another similar module.

OpenAPI UI

OpenAPI UI helps provide a user interface within Drupal for displaying your OpenAPI standards-based API explorer for your Drupal site.

OpenAPI UI Redoc

This module provides a plugin that implements Redoc for use with OpenAPI UI to display from within Drupal. This is akin to GraphiQL in the GraphQL standard.

preview of redoc in drupalOpenAPI UI using Redoc in Contenta

SimpleOauth

SimpleOauth is an implementation of the OAuth 2.0 Authorization Framework RFC for Drupal allowing you to use Oauth 2.0 for user authentication.

Subrequests

The subrequests module allows aggregated requests and responses to be sent to Drupal. For example, instead of sending a request for a node and then the node’s associated taxonomy terms, it allows you to send a single request that returns all the data you’d need. The goal being to make decoupled applications more efficient by reducing requests. An excellent article on the motivation for this module can be found on Lullabot’s blog.

Installing Contenta

To get started, head over to the Contenta install page. After installing, run: drush runserver 127.0.0.1:8888 to run server, then access 127.0.0.1:8888 to view site.

preview of contenta home screen

Upon logging in, you will find a familiar interface, with some slightly different links available, with all but the “API” link leading to common Drupal administration pages, and the “Advanced Link” exposing the default Drupal administration toolbar.

preview of contenta admin screen

You should be now ready to begin building your decoupled site. In the following posts in this series, I will explore doing just that.

Conclusion

By adding and configuring the above modules to a new or existing Drupal 8 site (I can’t stress enough that you must install modules using composer), configuring CORS (if needed), you should be ready to begin developing your decoupled application using the technology of your choosing so at this point I wish you happy trails!

*P.S. The folks that brought you ContentaCMS also created ContentaJS, “a nodejs server that proxies to Contenta CMS and holds custom code”. It’s certainly not necessary to begin your decoupled journey, but it does provide some handy features that I think could be extremely useful.