Browse Source

Attempt at updating taxonomy term pattern.

main
Rosie Le Faive 2 days ago
parent
commit
4f4d32077e
  1. 13
      islandlives.module

13
islandlives.module

@ -12,7 +12,7 @@ use Drupal\views\ViewExecutable;
* Implements hook_pathauto_pattern_alter(). * Implements hook_pathauto_pattern_alter().
*/ */
function islandlives_pathauto_pattern_alter(PathautoPatternInterface $pattern, array $context) { function islandlives_pathauto_pattern_alter(PathautoPatternInterface $pattern, array $context) {
// Only act on the repository_items pattern. // Nodes: Only act if the pattern has machine name `repository_items`.
if ($pattern->id() == 'repository_items') { if ($pattern->id() == 'repository_items') {
// If node has no PID... // If node has no PID...
$node = $context['data']['node']; $node = $context['data']['node'];
@ -23,6 +23,17 @@ function islandlives_pathauto_pattern_alter(PathautoPatternInterface $pattern, a
$pattern->setPattern($new_pattern); $pattern->setPattern($new_pattern);
} }
} }
// Taxonomy Terms: Only act if the pattern has machine name `person_vocabulary`.
if ($pattern->id() == 'person_vocabulary') {
// If term has no PID...
$term = $context['data']['taxonomy_term'];
$pid = $term->get('field_pid')->value;
if ($pid == NULL) {
// Replace the PID with the TID in the alias.
$new_pattern = preg_replace('/\[term:field_pid\]/', '[term:tid]', $pattern->getPattern());
$pattern->setPattern($new_pattern);
}
}
} }
/** /**

Loading…
Cancel
Save