Extracting Data from Drupal Entities Without Dying Inside

patrickocoffeyo

Extracting Data from Drupal Entities Without Dying Inside

Extracting Data from

Drupal Entities

Without Dying Inside


I’m also on the interwebs:

Twitter: @patrickocoffeyo

Github: @patrickocoffeyo

Drupal: @pcoffey (yyeah)


Drupal is awesome!

It does a great job of managing and organizing

your content in a structured way.


Drupal is awesome!

Drupal has really good tools for working with

and rendering entities within itself.

That’s not really an issue.


Problem?

hi, yes, this is

drupal. i have your

data. theres a lot of

it. come and get it

lol.

When you need to use Entity

data OUTSIDE of Drupal,

things can get complicated.


The problem

Properly extracting and formatting data from

Drupal entity objects can be complicated and

verbose.


The problem

Organizing extraction rules and formatting

patterns in a modular and reusable way is

really challenging.


The problem

If you are dealing with a lot of entity types,

trying to extract/format data from lots of fields,

then your codebase can get out of control

quickly.


An example situation





A client had very specific and complicated rules for

extracting and formatting data.

Their formatting rules needed to be field-type-agnostic.

(one formatter works for multiple compatible field types).

Codebase became REALLY big and hard to manage.

Lots of un-DRY code was written, especially since

multiple people were working on this codebase.


The problem

This is very frustrating.

It feels a little like dying inside, because all the

hard work you put into organization seems to

fail you as your codebase grows and grows.


The problem

We need a solution!

And that’s where Distill comes in.


Distill

Drupal module that enables dependent

modules to extract and format data from Drupal

entities in a structured way.

github.com/patrickocoffeyo/distill


How does Distill Work?

Distill contains 2 classes:

1. Processor class defines field formatters.

2. Distillation class takes an entity, a processor

class, and a list of fields that should be

returned, executes the processor’s formatter

methods, and returns an array of data.


How does Distill Work?

Entity

Distiller

(extractor)

Consume-able

Data

Processor

(formatter)


How does Distill Work?

Breaking the formatters and the extractors into

two different mechanisms allows for better

organization, reusability, and extendability.


How does Distill Work?

Using object orientation allows one to define a

processor class, and create extensions of the

processor that deviate from the parent.


How does Distill Work?

Parent Processing Ruleset

Child Processing

Ruleset

Child Processing

Ruleset

Child Processing

Ruleset

Child Processing

Ruleset

Distiller


Let’s see how this works!

Code examples :)

github.com/patrickocoffeyo/distill-example

Similar magazines