You are here

function business_rules_update_8103 in Business Rules 8

Same name and namespace in other branches
  1. 2.x business_rules.install \business_rules_update_8103()

Add dependent field configuration option for referencing the parent by UUID.

File

./business_rules.install, line 52

Code

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();
    }
  }
}