Skip to content

Solve the problem of mapping Drupal fields to pattern Variables #8

Open
@cybtachyon

Description

@cybtachyon

Summary:

  • Find a Drupal pattern data-mapping solution that is a good fit for our specific implementation and tooling

Benefits:

  • We provide a solid solution to the problem of data mapping in Drupal 8 with themes using pattern libraries for our users to get started with

To Do:

  • Discuss solutions with community
  • Select a "best possible" solution for our particular implementation
  • Create required issues to implement the solution

One of the hard problems with making Drupal play nice with a pattern library is mapping your backend Drupal entities and fields to the pattern variables. Some patterns expect strings, or arrays, or can even accept complicated objects for rendering that make use of recursive rendering from the parent platform.

This would be relatively simple to solve if we just use schemas for our patterns and imported those at run-time into Drupal. Unfortunately for that approach, many Drupal sites have a complicated set of backend data, entity, and field organization that makes it impossible to map fields 1:1 to a frontend. This also makes it hard to dynamically generate data models in Drupal for all scenarios, since often we’ll want to include values contained in other fields/entities.

1:1 mapping is easier though than tackling data mapping, and there are a couple of solutions that implement it pretty well.

A common solution for data mapping in Drupal 8 is to use “presenter” twig templates that include a pattern from the library and do all the complicated data mapping in the Drupal “presenter” template. This essentially looks like:

Drupal controller, view node response render -> node.tpl.php (presenter data-mapping template) -> twig include patterns/myCustomPattern.twig

One possible solution is to use a Pattern Renderer API service, that allows a configuration tool to display and set replacement tokens for Drupal to manage. The issue with this is that it relies on developers to create those tokens for all of the backend data.

Another possible solution is to have a Drupal module that has a configurable set of data mapping transformations, much like Views, that allows assigning fields to the pattern schema variables.

Here are some of the current open source community attempts at solving this problem, in order of scope from smallest to largest:

The teams I work with internally already have a number of projects in this vein and are planning on moving forwards with a consolidated project starting August 21st.

cc @ThatGuyCND @EvanLovely @evanmwillhite

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions