I would like to attach a specific library using a taxonomy term to a content type with a specific field that is not empty. The following is not working:
function lehigh_preprocess_page(&$variables) {
// Via taxonomy term: If the landing page is a node and has taxonomy
via a field named field_taxonomy
$current_route = \Drupal::routeMatch();
$node = $current_route->getParameter('node');
$target_taxonomy_id = 123;
if ($node->getType() === 'standard_content_page') && $node->hasField('field_section') && !$node->get('field_section')->isEmpty()) {
if ($node->get('field_section')->referencedEntities()[0]->id() == $target_taxonomy_id) {
$variables['#attached']['library'][] = 'lehigh/financialaid';
}
}
}