You are here

function hide_revision_field_update_8201 in Hide Revision Field 8.2

Update settings.

File

./hide_revision_field.install, line 112
Install, update and uninstall functions for Hide Revision Field.

Code

function hide_revision_field_update_8201() {
  drupal_flush_all_caches();
  hide_revision_field_apply_updates();
  $entity_type_manager = \Drupal::entityTypeManager();
  $types = [
    'node_type' => 'node',
    'media_bundle' => 'media',
  ];
  foreach ($types as $type => $type_id) {
    if (!$entity_type_manager
      ->hasDefinition($type)) {
      continue;
    }

    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $bundle */
    foreach ($entity_type_manager
      ->getStorage($type)
      ->loadMultiple() as $k => $bundle) {
      $entity_type_manager
        ->getStorage('entity_form_display')
        ->load("{$type_id}.{$k}.default")
        ->setComponent('revision_log', [
        'type' => 'hide_revision_field_log_widget',
        'settings' => [
          'show' => !$bundle
            ->getThirdPartySetting('hide_revision_field', 'hide', FALSE),
        ],
      ])
        ->save();
      $bundle
        ->unsetThirdPartySetting('hide_revision_field', 'hide');
      $bundle
        ->unsetThirdPartySetting('hide_revision_field', 'personalizable');
    }
  }
  user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, [
    'view revision field',
  ]);
}