modules/stanford_courses/stanford_courses.module
<?php
/**
* @file
* Stanford_courses.module.
*/
use Drupal\pathauto\PathautoPatternInterface;
use Drupal\views\ViewExecutable;
/**
* Implements hook_views_pre_render().
*/
function stanford_courses_views_pre_render(ViewExecutable $view) {
if ($view->storage->id() == 'stanford_courses') {
$view->element['#attached']['library'][] = 'stanford_courses/courses_page';
}
}
/**
* Implements hook_pathauto_alias_alter().
*/
/**
* Implements hook_pathauto_pattern_alter().
*/
function stanford_courses_pathauto_pattern_alter(PathautoPatternInterface $pattern, array $context) {
if (isset($context['data']['node']) && $context['bundle'] == 'stanford_course') {
/** @var \Drupal\node\NodeInterface $node */
$node = $context['data']['node'];
if (
!$node->get('su_course_subject')->count() &&
!$node->get('su_course_code')->count()
) {
$pattern->setPattern('/courses/[node:title]');
}
}
}