You are here

function smart_title_uninstall in Smart Title 8

Implements hook_uninstall().

File

./smart_title.install, line 13
Install and update functions for Smart Title.

Code

function smart_title_uninstall() {
  $smart_title_bundles = \Drupal::configFactory()
    ->get('smart_title.settings')
    ->get('smart_title');
  if (empty($smart_title_bundles)) {
    return;
  }
  $entity_resave = function (EntityViewDisplayInterface $entity_view_display) {
    $display_array = $entity_view_display
      ->toArray() + [
      'hidden' => [],
    ];
    unset($display_array['hidden']['smart_title']);
    $entity_view_display
      ->removeComponent('smart_title')
      ->trustData()
      ->save();
  };
  foreach ($smart_title_bundles as $smart_title_bundle) {
    list($target_entity_id, $bundle) = explode(':', $smart_title_bundle);
    array_map($entity_resave, \Drupal::entityTypeManager()
      ->getStorage('entity_view_display')
      ->loadByProperties([
      'targetEntityType' => $target_entity_id,
      'bundle' => $bundle,
    ]));
  }
}