Select the right pathauto alias for a node I'm working on a drupal 8 project, I need to access the content type X nodes via two aliases depending on some conditions, for this I've created two Pathauto patterns using Pathauto contrib module: 

path_1 --&gt; /local/[node:title]

path_2 --&gt; /global/[node:title]


path_1 &amp; path_2 are supposed the machine name of those two patterns.

What are those two patterns? actually what I want to do is check if a node of type X has the checkbox field 'global' checked so use /global/[node:title] as alias for this node else use /local/[node:title].

Which hook should I implements for selecting/altering a pathauto pattern for a node? And can I use those aliases as a route for a controller?
Another option, and I find this to be preferable to altering the token because it's exposed to site builders and makes what's happening perfectly clear in the UI, is to create your own custom token that will return /global or /local for that piece of the url. You just need to implement hook_token_info and hook_tokens. This blog post walks you through the process.

Ex:

/**
 * Implements hook_token_info().
 */
function MY_MODULE_token_info() {
  $info['tokens']['node']['MY_TOKEN_ID'] = [
    'name' =&gt; t('MY TOKEN LABEL'),
    'description' =&gt; t('Return "/global" for nodes with the global checkbox checked, otherwise returns "/local".'),
    'type' =&gt; 'url-fragment',
  ];
  return $info;
}

/**
 * Implements hook_tokens().
 */
function MY_MODULE_tokens($type, $tokens, array $data, array $options, Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if ($type == 'node' &amp;&amp; !empty($data['node']) &amp;&amp; isset($tokens['MY_TOKEN_ID'])) {
    $node = $data['node'];
    $global_or_local = '/local';
    if ($node-&gt;hasField('MY_GLOBAL_FIELD') &amp;&amp; !empty($node-&gt;MY_GLOBAL_FIELD-&gt;value)) {
      $global_or_local = '/global';
    }
    $replacements['[node:MY_TOKEN_ID]'] = $global_or_local;
  }
  return $replacements;
}


Note: I'm not sure if that logic to determine global or local is perfect, but it should be close.