Use triplets

Store and fetch data using Y triplets.

Y: Triplets

[Note: You will need to install the Y module and the PHP YAML extension.]

Making Drupal 7 / YAD7 modules is well-documented. You will need to make an example folder in the modules directory and then create the following files in it:

  • example.info
  • example.module

Making effective use of the Y module requires a third file:

  • example.y.inc

Your YAML configuration files need to be placed in a subdirectory called 'config'.

Within the example/config directory, each subdirectory name corresponds to a large group / type concept called a 'protocol'. Each sub-type of data maintained in a protocol is called an 'api'. And, each grouping of 'api' data is associated with an 'id' identifier. Here is how to make a triplet:

Create a file called example/config/admin/helloworld.yaml with these contents:

routing:
  !name :
    menu:
      title: Hello World
      description: Say Hi
      page callback: y__render
      page arguments: [ !name , !protocol , render, !module ]
      access arguments: [ access content ]
    render:
      page:
        '#markup': How's it going?<p>This is the example from <a href="http://hkern0.com/y/how-to/triplets">Drupal 7 Triplets</a>

In your example.module file, put these contents:

<?php

use Drupal\Y;

/**
 * Implements hook_menu()
 */
function example_menu() {
  return Y\Y::protocol_get_all('admin', 'menu', 'example');;
}

Then, clear your caches and you should have a URI on your website at /helloworld

4 / 2019