This page deals with an experimental feature of the Patterns module: Automatic exporting the configuration of a Drupal web site.

In the alpha release of Patterns 7.x automatic exporting was achieved by implementing hook_get_arguments. While still valid, such hook is now deprecated in favor of using hook_patterns and specifying one or more export functions as a return value in the associative array. The following code snippet explains how:

function mymodule_patterns($data = NULL) {

  $actions['mytag'] = array(
    // ...
    PATTERNS_EXPORT => array(PATTERNS_EXPORT_ALL => 'mymodule_export_all_mytag'),
   );
}

function mymodule_export_all_mytag(){
  // ...
  //return $all_mytag_collection;
}

For each tag (here only 'mytag') it is possible to specify one ore more export function inside the array indexed by PATTERNS_EXPORT. The key of such array will be displayed to the users for selection in the Export page, while the values must contain the name of a valid function.

The export function, must return an associative array of Patterns actions (create, modify, delete) specific for the tag of interest. An example of such function taken from the Taxonomy component follow:

function taxonomy_patterns_export_all_vocs($args = NULL, &$result = NULL) {
	$info = taxonomy_patterns();
	$form_id = current($info['vocabulary'][PATTERNS_MODIFY]);
	$vocs = taxonomy_get_vocabularies();
	$result = array();
	foreach ($vocs as $voc) {
		// It is important to user array merge. Pushing is not enough
  	$result = array_merge($result, patterns_api_extract_actions($form_id, $voc, 'vocabulary', PATTERNS_MODIFY));
  }
  return $result;
}

The above listed function makes use of a very important pattern API: patterns_api_extract_actions. Such api can call a form, retrieve the current values, and return them incapsulated inside a valid pattern action. Extensive documentation for developers about patterns_api_extract_actions is available as comments in the code of the of patterns/includes/api/api.inc file.

Further details about the internal flow of execution while exporting configuration can be found in the following section.
A very simple "patterns_hello_world" module implementing an export function can also be checkout from GitHub at: git://github.com/QScience/patterns_hello_world.git

Function patterns_utils_check_keys()

Versions of patterns >= 7.x-2.1 include a new powerful tool to validate component input parameters. It supports the following conditions: 'mandatory', 'at_least_one', 'one_and_only_one', 'exclusive'.
The conditions must be inserted as a new element of the checkings array in the form: array('type' => params). E.g.

 $kchecks = array();
 $kchecks[] = array('mandatory', array('key1', 'key2', 'key3');
 $kchecks[] = array('at_least_one', array('key4', 'key5', 'key6');