<?php

/**
 * @file
 * Various install/uninstall hooks for the Metatag Views module.
 */

/**
 * Implements hook_install().
 */
function metatag_views_install() {
  // Enable metatag_display_extender plugin.
  $config = \Drupal::service('config.factory')->getEditable('views.settings');
  $display_extenders = $config->get('display_extenders') ?: [];
  $display_extenders[] = 'metatag_display_extender';
  $config->set('display_extenders', $display_extenders);
  $config->save();
}

/**
 * Implements hook_uninstall().
 */
function metatag_views_uninstall() {
  // Disable metatag_display_extender plugin.
  $config = \Drupal::service('config.factory')->getEditable('views.settings');
  $display_extenders = $config->get('display_extenders') ?: [];

  $key = array_search('metatag_display_extender', $display_extenders);
  if ($key !== FALSE) {
    unset($display_extenders[$key]);
    $config->set('display_extenders', $display_extenders);
    $config->save();
  }
}

/**
 * Implementations of hook_update_N().
 */

/**
 * Notify admins that the custom admin pages were (temporarily) disabled.
 */
function metatag_views_update_8100() {
  return (string) t("The custom admin pages for managing Views meta tags at /admin/config/search/metatag/views have been disabled for now, hopefully they'll be back in a future release. Until then, the meta tags can be managed directly on each individual view via the \"Meta tags\" section.");
}
