bt_faq-8.x-1.x-dev/bt_faq.module
bt_faq.module
<?php /** * @file * The module file of bt_faq module. */ use Drupal\node\NodeInterface; /** * Implements hook_entity_insert(). */ function bt_faq_node_insert(NodeInterface $entity) { // Convert to lowercase, trim spaces, // replace spaces with underscore and then truncate to 60 chars. $pathTitle = substr(str_replace(" ", "-", trim(strtolower($entity->label()))), 0, 60); if ($entity->bundle() == 'faq') { \Drupal::service('path.alias_storage')->save("/node/" . $entity->id() . '/edit', "/question/" . $pathTitle . '/edit', "en"); \Drupal::service('path.alias_storage')->save("/node/" . $entity->id() . '/delete', "/question/" . $pathTitle . '/delete', "en"); \Drupal::service('path.alias_storage')->save("/node/" . $entity->id() . '/latest', "/question/" . $pathTitle . '/latest', "en"); } }