You are here

function yoast_seo_update_8001 in Real-time SEO for Drupal 8

Detach Yoast SEO fields from all taxonomies.

File

./yoast_seo.install, line 48
Install, update, and uninstall functions for the Yoast SEO for Drupal module.

Code

function yoast_seo_update_8001() {
  $yoast_seo_manager = \Drupal::service('yoast_seo.manager');
  $entity_type_id = 'taxonomy_term';
  $enabled_bundles = $yoast_seo_manager
    ->getEnabledBundles($entity_type_id);
  if (!empty($enabled_bundles)) {
    foreach ($enabled_bundles as $bundle_id) {
      $yoast_seo_manager
        ->detachYoastSeoFields($entity_type_id, $bundle_id);
    }
  }

  // Fields have been marked as deleted. Attempt to delete them straight away.
  // Anything that's missed now will be cleaned up by cron later.
  $limit = \Drupal::config('field.settings')
    ->get('purge_batch_size');
  field_purge_batch($limit);
}