Create custom URL pattern
In Drupal 8, pathauto patterns are configuration entities. You have  at least two choices to provide them with your custom module:

(1) Provide your pattern as YAML configurations in your module's config/install folder. They will be considered and installed to your Drupal, when your module will be installed. Easiest to create using the UI and doing a configuration export afterwards. Just remove the generated UUID of the pattern.

(2) On run-time or in your install/update hooks, you can use Drupal\pathauto\Entity\PathautoPattern::create() or the \Drupal::entityTypeManager() to create them dynamically:

$data = [
  'id' =&gt; 'my_pattern_machine_name',
  'type' =&gt; 'canonical_entities:node',
  'pattern' =&gt; 'my-path/[node:title]',
  'weight' =&gt; 0,
];
$pattern = \Drupal::entityTypeManager()-&gt;getStorage('pathauto_pattern')-&gt;create($data);


You can then use the returned pattern entity in $pattern to add selection conditions (e.g. bundles, language, ...) as required. Don't forget to save the entity afterwards, and - of course - check, if the pathauto module has been installed before or make it a dependency of your custom module.