You are here

business_rules.install in Business Rules 8

Same filename and directory in other branches
  1. 2.x business_rules.install

File

business_rules.install
View source
<?php

use Drupal\business_rules\Entity\Action;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Field\BaseFieldDefinition;

/**
 * Update the email actions to allow HTML.
 */
function business_rules_update_8101(&$sandbox) {
  $actions = Action::loadMultiple();

  /** @var \Drupal\business_rules\Entity\Action $action */
  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();
      }
    }
  }
}

/**
 * Allows schedule to work with event variables.
 * @see https://www.drupal.org/project/business_rules/issues/3040833
 */
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']);
}

/**
 * Add dependent field configuration option for referencing the parent by UUID.
 */
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();
    }
  }
}

Functions

Namesort descending Description
business_rules_update_8101 Update the email actions to allow HTML.
business_rules_update_8102 Allows schedule to work with event variables.
business_rules_update_8103 Add dependent field configuration option for referencing the parent by UUID.