Abstracted array files (YAML?)

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by d00bz on February 15, 2010 at 1:56am

I am experimenting with abstracting the complex nested arrays that populate the definition of Drupal modules as separate resource files in YAML.

Example YAML for a menu: a separate file:


[module_dir]/resources/menu.yml

admin/game:
path: admin/game
title: game
page callback: game_admin
access arguments: [access administration pages]
type:
function: constant
arguments: [MENU_NORMAL_ITEM]

admin/game/add:
path: admin/game/add
title: Add Task
page callback: game_admin_add
access arguments: [access administration pages]
type:
function: constant
arguments: [MENU_NORMAL_ITEM]

admin/game/timeline:
path: admin/game/timeline
title: Timeline
page callback: game_admin_timeline
access arguments: [access administration pages]
type:
function: constant
arguments: [MENU_NORMAL_ITEM]

node/add/project:
path: node/add/project
title:
function: t
arguments: [Project]
access arguments: [create project]

------------------------ END -------------------------
You'll note that anything that is functional is broken down into a sub-array for post processing.

The advantage to a separate resource file for menus/nodes/forms is:

a) a cleaner leaner definition format for core elements
b) separation of key resources into files
c) lays the groundwork for a meta-system to edit module resources regardless of context.

potential costs:

a) The resources are interpreted which might cause some efficiency blowback. A solution would be to compile the resource file into a class or function as a mid step for efficiencies' sake.
b) adds another potential element to the learning curve of module creation.

The work I'm doing uses the Symfony YAML engine. Argument could be made to use the more popular JSON encoding to effect the same system -- there is nothing about YAML that makes it uniquely fitting for this purpose, it just has an exceptionally clean profile.

Categories:

Comments

The YML -- formatted

Posted by d00bz on February 15, 2010 at 1:58am

Sorry -- the nesting of the YAML was flattened by the posting process. here is it, nested:

admin/game:
 path: admin/game
 title: game
 page callback: game_admin
 access arguments: [access administration pages]
 type: 
 function: constant
 arguments: [MENU_NORMAL_ITEM]
admin/game/add:
 path: admin/game/add
 title: Add Task
 page callback: game_admin_add
 access arguments: [access administration pages]
 type: 
 function: constant
 arguments: [MENU_NORMAL_ITEM]
admin/game/timeline:
 path: admin/game/timeline
 title: Timeline
 page callback: game_admin_timeline
 access arguments: [access administration pages]
 type: 
 function: constant
 arguments: [MENU_NORMAL_ITEM]
node/add/project:
 path: node/add/project
 title: 
 function: t
 arguments: [Project]
 access arguments: [create project]

another minor issue with yaml are the colons

Posted by stephen.moz on February 24, 2010 at 8:37pm

Another issue with YAML is that you have to be careful if you are specifying a name value pair and the value contains a colon

YAML in module form

Posted by noobizness on March 12, 2010 at 12:38am

I have the YAML system in module form. When I've run it around the pike a few times I'll submit it to Drupal.

Hi, did anything ever come of

Posted by MichaelCole on April 4, 2011 at 8:39pm

Hi, did anything ever come of this?

SF Bay Area

Group categories

Resources

user group

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /