Skip to content

Instantly share code, notes, and snippets.

@blainelang
blainelang / Interacting with tasks
Created August 29, 2013 20:05
Using the maestro API to work with tasks Sample PHP code to interact with the Drupal maestro module (workflow engine) https://drupal.org/project/maestro
$task = MaestroTask::createTaskObject($queue_id);
$task_data = $task->prepareTask();
$notification_type = $task_data['optional_parm']['notification_type'];
// If you need to complete a task, you can use the engine()->completeTask() method
$maestro->engine()->completeTask($queue_id, $status);
@blainelang
blainelang / array_walk + anonymous function
Last active October 31, 2024 16:57
Using an anonymous function with array_walk and passing in a variable so that it's in scope for the function to use.
/* Objective: Loop over an array of Drupal user objects and build a string of email addresses for the $to variable.
* At first there was an issue because the variable $to_email_array was not being accessible to the anonymous function
* and then I saw answer2 to a similar question:
* > http://stackoverflow.com/questions/11420520/php-variables-in-anonymous-functions
*/
$to_email_array = array();
array_walk($users_group, function(&$user, &$uid) use (&$to_email_array) {
$to_email_array[] = $user->mail;
});
@blainelang
blainelang / hook_views_data
Created August 25, 2013 00:09
Example HOOK_views_data for 2 "related" custom tables and includes a relationship back to the users table. http://internetdevels.com/blog/describe-custom-table-for-views
/* Define Views interface for custom data tables */
function as_dashboard_views_data() {
$data = array();
$data['communication_builder_contact_list'] = array(
'table' => array(
'group' => t('AdvisorStream'),
'title' => t('contact list'),
'help' => t('Broker Contact List Names'),
'base' => array(
'field' => 'id',
@blainelang
blainelang / Hide Money Field's fieldset
Created July 16, 2013 19:39
Hide fieldset around the money field. The money field has an amount and currency field and these are wrapped inside a fieldset with a label which is redundant if your using the money field in a field collection and using the field_collection_table module - as I am for the PI expense form
// Add a theme_wrapper definition so thats it now treated like a standard form element
$form['field_DATEFIELDNAME']['und'][0]['#theme_wrappers'] = array('form_element');