/**
  * Removes URL alias of a rolled back entity.
  *
  * This fills the gap of URL aliases not being deleted when a entity is
  * removed. This event listener should be removed when
  * https://www.drupal.org/node/2539634 is fixed.
  *
  * @param \Drupal\migrate\Event\MigrateRowDeleteEvent $event
  * @param $name
  */
 public function removeUrlAlias(MigrateRowDeleteEvent $event, $name)
 {
     $migration = $event->getMigration();
     $entity_type_id = substr($migration->getDestinationPlugin()->getPluginDefinition()['id'], strlen('entity:'));
     $entity_type_manager = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
     // Check if canonical route is available.
     if ($entity_type_manager->getLinkTemplate('canonical')) {
         // Get destination entity id.
         $destination_entity_id = $event->getDestinationIdValues()[$entity_type_manager->getKeys()['id']];
         // Get Url object of the entity path.
         $url = Url::fromRoute("entity.{$entity_type_id}.canonical", [$entity_type_id => $destination_entity_id]);
         // Remove URL alias of the destination entity.
         \Drupal::service('path.alias_storage')->delete(array('source' => '/' . $url->getInternalPath()));
     }
 }
예제 #2
0
 /**
  * Reacts to item deletion.
  *
  * @param \Drupal\migrate\Event\MigrateRowDeleteEvent $event
  *   The post-save event.
  */
 public static function onPostRowDelete(MigrateRowDeleteEvent $event)
 {
     // We want to interrupt this batch and start a fresh one.
     if (time() - REQUEST_TIME > static::$maxExecTime) {
         $event->getMigration()->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);
     }
 }