SU-SWS/stanford_profile_helper

View on GitHub
modules/stanford_publication/stanford_publication.install

Summary

Maintainability
Test Coverage
<?php

/**
 * @file
 * stanford_publication.install
 */

use Drupal\menu_link_content\Entity\MenuLinkContent;

/**
 * Implements hook_uninstall().
 */
function stanford_publication_uninstall() {
  \Drupal::state()->delete('stanford_publication.citation_format');
}

/**
 * Create the 'All' publication topic term.
 */
function stanford_publication_update_8001() {
  MenuLinkContent::create([
    'title' => 'All',
    'link' => 'internal:/publications',
    'weight' => -99,
    'menu_name' => 'stanford-publication-topics',
  ])->save();
}

/**
 * Delete duplicate "All" publication links.
 */
function stanford_publication_update_8002() {
  $all_links = \Drupal::entityTypeManager()
    ->getStorage('menu_link_content')
    ->loadByProperties([
      'menu_name' => 'stanford-publication-topics',
      'title' => 'All',
    ]);
  if (count($all_links) >= 2) {
    array_pop($all_links);
    foreach ($all_links as $link) {
      $link->delete();
    }
  }
}