Pattern Execution

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

The following diagram summarizes the execution flow of a pattern. Next sections detail each of the phases.

Running a pattern - diagram

Main function: patterns_start_engine()

Once a pattern has been parsed after being enabled or run, the function patterns_start_engine() goes into action. This function receives a Pattern object, the execution mode (php or batch) and a set of extra parameters if needed. The diagram below summarizes the main steps involved before calling the proper (PHP or batch) function:

Start engine - detailed diagram

  • As an example, a simple Pattern object generated after running the node.yaml example has the following structure:
    $pattern	stdClass	
    	CLASSNAME	stdClass	
    	pid	1	
    	name	node.yaml	
    	format	yaml	
    	status	1	
    	public	0	
    	file	sites/all/modules/custom/patterns/patterns_examples/patterns//node.yaml	
    	updated	1348051211	
    	enabled	1348479432	
    	title	Example Article creation	
    	description	Creates an example article node	
    	pattern	Array [2]	
    		info	Array [7]	
    			title	Example Article creation	
    			description	Creates an example article node	
    			author	QSCience	
    			version	1.0	
    			category	Content	
    			core	7.x	
    			author_website	http://qlectives.eu/	
    		actions	Array [1]	
    			0	Array [1]	
    				create	Array [4]	
    					tag	node	
    					type	article	
    					title	Test Article	
    					body	lorem ipsum ...	
    
  • Using the same example, the $parameters array has this structure:
    $params	Array [10]	
    	pid	1	
    	execution	extend	
    	mode	php	
    	run-subpatterns	never	
    	confirm	1	
    	submit	Confirm	
    	form_build_id	form-uEtwhgIz5faBmzn7DBL-AGDkqUE0E3YaDj5yHdO8tpI	
    	form_token	zTBMxkjkiecd-A26XPB47LqaVap1qUsA-smXtsC37Q0	
    	form_id	patterns_enable_pattern	
    	op	Confirm	
    
  • The Pattern object is passed afterwards to an auxiliary parsing function called patterns_parser_get_pattern_details() (includes/parser.inc). Internally, this function carries out a scanning and results validation process in the same way as it is detailed in the previous subsection “Enabling a pattern" by the functions patterns_enable_pattern() and patterns_enable_pattern_submit()”.
  • But the result is an array whose index is the Pattern ID. Following the same example we have used previously and being 1 the PID, the result of our execution would be:
    $patterns_details	Array [1]	
    	1	Array [3]	
    		info	Array [7]	
    			title	Example Article creation	
    			description	Creates an example article node	
    			author	QSCience	
    			version	1.0	
    			category	Content	
    			core	7.x	
    			author_website	http://qlectives.eu/	
    		sections	Array [1]	
    			actions	Array [1]	
    				0	Array [1]	
    					create	Array [4]	
    		modules	Array [0]
    
  • Afterwards, this array is decomposed into the PID and the different parts that compose the pattern ($info, $modules and $sections) (in the future it will be able to process several patterns from the same file).
  • The function later calls patterns_install_modules() (includes/modules.inc), that will enable all the required modules to run that pattern.
  • Then another temporal variable called $actions_map is build. This variable will be passed also to the proper execution function. This variable is obsolete (comes from the re-writting process from Patterns v.6) and it will be removed in future versions. Following our example, the $actions_map variable looks like:
    $actions_map	Array [2]	
    	patterns	Array [1]	
    		1	Array [7]	
    			title	Example Article creation	
    			description	Creates an example article node	
    			author	QSCience	
    			version	1.0	
    			category	Content	
    			core	7.x	
    			author_website	http://qlectives.eu/	
    	map	<Uninitialized>	
    
  • Finally, depending on the running mode (batch or php) a different function will be called: patterns_execute_pattern_php() or patterns_execute_pattern_batch().

Executing a pattern in Batch running mode

When a pattern is executed in Batch running mode, the core function patterns_execute_pattern_batch() (includes/core/batch.inc) is called.

Executing a pattern in PHP running mode

When a pattern is executed in PHP running mode, the core function patterns_execute_pattern_php() (includes/core/php.inc) is called. In this

Guide maintainers

drozas's picture