business_rules.install in Business Rules 8
File
business_rules.install
View source
<?php
use Drupal\business_rules\Entity\Action;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Field\BaseFieldDefinition;
function business_rules_update_8101(&$sandbox) {
$actions = Action::loadMultiple();
foreach ($actions as $key => $action) {
if ($action
->getType() == 'send_email') {
$old_body = $action
->getSettings('body');
if (!is_array($old_body)) {
$new_body = [
'format' => 'full_html',
'value' => $old_body,
];
$action
->setSetting('body', $new_body);
$action
->save();
}
}
}
}
function business_rules_update_8102() {
$fields['update_entity'] = BaseFieldDefinition::create('boolean')
->setLabel('Save entity as the last action of the task')
->setDescription('It the task will save the entity in the end of the process.');
$fields['event'] = BaseFieldDefinition::create('map')
->setLabel(t('Event.'))
->setDescription(t('The event that has created the schedule.'));
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('update_entity', 'business_rules_schedule', 'business_rules', $fields['update_entity']);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition('event', 'business_rules_schedule', 'business_rules', $fields['event']);
}
function business_rules_update_8103() {
if (!($field_storage_configs = \Drupal::entityTypeManager()
->getStorage('field_storage_config')
->loadByProperties(array(
'type' => 'entity_reference',
)))) {
return;
}
foreach ($field_storage_configs as $field_storage) {
$field_name = $field_storage
->getName();
if (!($fields = \Drupal::entityTypeManager()
->getStorage('field_config')
->loadByProperties([
'field_name' => $field_name,
]))) {
continue;
}
foreach ($fields as $field) {
if ($field
->toArray()['settings']['handler'] != 'business_rules_views') {
continue;
}
$new_field = $field
->toArray();
$new_field['settings']['handler_settings']['business_rules_view']['reference_parent_by_uuid'] = FALSE;
$new_field = FieldConfig::create($new_field);
$new_field->original = $field;
$new_field
->enforceIsNew(FALSE);
$new_field
->save();
}
}
}