mglaman / drupal-typed-data-by-example

Drupal's Typed Data API by example
GNU General Public License v3.0
37 stars 6 forks source link
drupal

Drupal's Typed Data API by example

This repository aims to help show use cases and various exercises with using Drupal's Typed Data API.

The Typed Data API was created to provide developers with a consistent way of interacting with data in different ways.

Purpose

This repository provides examples of using the Typed Data API. The examples range from generic usage explaining the different data types available, to creating complex data definitions, to utilizing them in real world Drupal applications.

The intent is not to run this code in your Drupal site, but to browse the code examples.

Structure

The examples are broken into different groups, each with their own directory:

Trying it out!

All of the examples can be run to see sample outputs.

First, install the dependencies and generate the autoloader (requires PHP ^8.0):

composer install

For example, the following will run the emails example in primitives/ and print any of the additional output provided for context.

php primitives/email.php