View source
<?php
function organigrams_rules_data_info_alter(&$data_info) {
$data_info['organigrams']['wrapper class'] = 'RulesOrganigramsWrapper';
$data_info['organigrams']['ui class'] = 'RulesDataUIOrganigrams';
}
function organigrams_rules_event_info() {
$defaults_organigrams_item = array(
'group' => t('Organigrams'),
'access callback' => 'rules_organigrams_item_integration_access',
'module' => 'organigrams',
'class' => 'RulesOrganigramsEventHandler',
);
$defaults_organigrams = array(
'group' => t('Organigrams'),
'access callback' => 'rules_organigrams_integration_access',
'module' => 'organigrams',
);
return array(
'organigrams_item_insert' => $defaults_organigrams_item + array(
'label' => t('After saving a new organigrams item'),
'variables' => array(
'item' => array(
'type' => 'organigrams_item',
'label' => t('created organigrams item'),
),
),
),
'organigrams_item_update' => $defaults_organigrams_item + array(
'label' => t('After updating an existing organigrams item'),
'variables' => array(
'item' => array(
'type' => 'organigrams_item',
'label' => t('updated organigrams item'),
),
'item_unchanged' => array(
'type' => 'organigrams_item',
'label' => t('unchanged organigrams item'),
'handler' => 'rules_events_entity_unchanged',
),
),
),
'organigrams_item_presave' => $defaults_organigrams_item + array(
'label' => t('Before saving an organigrams item'),
'variables' => array(
'item' => array(
'type' => 'organigrams_item',
'label' => t('saved organigrams item'),
'skip save' => TRUE,
),
'item_unchanged' => array(
'type' => 'organigrams_item',
'label' => t('unchanged organigrams item'),
'handler' => 'rules_events_entity_unchanged',
),
),
),
'organigrams_item_delete' => $defaults_organigrams_item + array(
'label' => t('After deleting an organigrams item'),
'variables' => array(
'item' => array(
'type' => 'organigrams_item',
'label' => t('deleted organigrams item'),
),
),
),
'organigrams_insert' => $defaults_organigrams + array(
'label' => t('After saving a new organigram'),
'variables' => array(
'organigrams' => array(
'type' => 'organigrams',
'label' => t('created organigram'),
),
),
),
'organigrams_update' => $defaults_organigrams + array(
'label' => t('After updating an existing organigram'),
'variables' => array(
'organigrams' => array(
'type' => 'organigrams',
'label' => t('updated organigram'),
),
'organigrams_unchanged' => array(
'type' => 'organigrams',
'label' => t('unchanged organigram'),
'handler' => 'rules_events_entity_unchanged',
),
),
),
'organigrams_presave' => $defaults_organigrams + array(
'label' => t('Before saving an organigram'),
'variables' => array(
'organigrams' => array(
'type' => 'organigrams',
'label' => t('saved organigram'),
'skip save' => TRUE,
),
'organigrams_unchanged' => array(
'type' => 'organigrams',
'label' => t('unchanged organigram'),
'handler' => 'rules_events_entity_unchanged',
),
),
),
'organigrams_delete' => $defaults_organigrams + array(
'label' => t('After deleting an organigram'),
'variables' => array(
'organigrams' => array(
'type' => 'organigrams',
'label' => t('deleted organigram'),
),
),
),
);
}
function rules_organigrams_item_integration_access($type) {
if ($type == 'event' || $type == 'condition') {
return entity_access('view', 'organigrams_item');
}
}
function rules_organigrams_integration_access($type) {
if ($type == 'event' || $type == 'condition') {
return entity_access('view', 'organigrams');
}
}
class RulesOrganigramsEventHandler extends RulesEventHandlerEntityBundle {
protected function getBundlePropertyLabel() {
return t('organigrams');
}
}
class RulesOrganigramsWrapper extends EntityDrupalWrapper {
protected function setEntity($data) {
if (isset($data) && $data !== FALSE && !is_object($data) && !is_numeric($data)) {
parent::setEntity(organigrams_machine_name_load($data));
}
else {
parent::setEntity($data);
}
}
public function validate($value) {
if (isset($value) && is_string($value)) {
return TRUE;
}
return parent::validate($value);
}
}
class RulesDataUIOrganigrams extends RulesDataUIEntity implements RulesDataInputOptionsListInterface {
public static function getDefaultMode() {
return 'input';
}
public static function optionsList(RulesPlugin $element, $name) {
$options = array();
foreach (organigrams_get_names() as $machine_name => $organigram) {
$options[$machine_name] = $organigram->name;
}
return $options;
}
}