Skip to content

Creating an element

jessevondoom edited this page Oct 30, 2012 · 2 revisions

Elements are pretty analogous to a smartphone app, providing a set of functionality with options specific to the individual element as defined by a user. So in the case of an email collection element the admin specifies the list, the fulfillment asset for download, and the messages to be shown to the user. The element can then be embedded directly with a single PHP call, via JavaScript, or using a CMS plugin.

##The shape of an element Elements consist of a main controller class, a JSON definition file, an image thumbnail, an admin panel, and Mustache views for all element states. The admin panel allows elements to be easily added from the admin app with a custom layout, specific to the element type. The views live in a subfolder next to the controller class, and the controller handles all processing by sorting parameters and managing CASHRequests. The intent is that the controller is fairly lightweight, passing most real work on to the core framework.

So as an example, an element might look like:

LICENSE
MyElement.php (controller class)
myelement/admin.php
myelement/image.jpg
myelement/metadata.json
myelement/templates/admin.mustache
myelement/templates/default.mustache

That bundle provides everything needed to define the element, render it, and provide both data and rendered markup results for any given element.

##The metadata.json file The metadata.json file is fairly basic. It's essentially an object that specifies interface copy, adds parameters and version information, etc. An example:

{
	"name":"My Element",
	"description":"This is my element. It's rad.",
	"longdescription":"This can be as long as it needs. Shows up in the 'more' section of the admin.",
	"instructions":"Currently not implemented, these will be part of the admin interface.",
	"pagetip":"The help message for a given element.",
	"lastupdated":"Jan 25, 2012",
	"version":1.0,
	"author":"CASH Music",
	"url":"http://cashmusic.org/"
}

##Licenses Our default elements are all licensed with an AGPL license, but we don't see them as derivative works of the core, rather standalone works that use the CASH core. As such, you're welcome to use any license you like for a custom element, though we strongly encourage you to use an AGPL, GPL or other open license.