From 419ae401508f3ce940ebec184d094f83fc0f9739 Mon Sep 17 00:00:00 2001 From: Volker Killesreiter Date: Thu, 18 Jun 2020 15:34:20 +0200 Subject: [PATCH] while updating from media_enitiy to media in core, when there is a module enabled or disabled, routes will get rebuild. This code tries to build routes based on media in core entities while the site is still media_entity based breaking the update (#86) --- .../dcx_migration/src/Routing/MediaRoutes.php | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/dcx_migration/src/Routing/MediaRoutes.php b/modules/dcx_migration/src/Routing/MediaRoutes.php index e5fed74..955fa77 100644 --- a/modules/dcx_migration/src/Routing/MediaRoutes.php +++ b/modules/dcx_migration/src/Routing/MediaRoutes.php @@ -13,33 +13,33 @@ class MediaRoutes { * {@inheritdoc} */ public function routes() { - - /** @var \Drupal\media\Entity\MediaType[] $bundles */ - $bundles = \Drupal::entityTypeManager()->getStorage('media_type')->loadMultiple(); - $routes = []; - foreach ($bundles as $bundle) { - - if ($bundle->get('source') == 'image') { - $routes['dcx_migration.form.' . $bundle->id()] = new Route( - // Path to attach this route to: - 'media/add/' . $bundle->id(), - // Route defaults: - [ - '_form' => '\Drupal\dcx_migration\Form\DcxImportForm', - '_title' => 'Import Image from DC-X', - ], - // Route requirements: - [ - '_entity_create_access' => 'media:' . $bundle->id(), - ], - [ - '_admin_route' => TRUE, - ] - ); + if (\Drupal::moduleHandler()->moduleExists('media')) { + /** @var \Drupal\media\Entity\MediaType[] $bundles */ + $bundles = \Drupal::entityTypeManager()->getStorage('media_type')->loadMultiple(); + + foreach ($bundles as $bundle) { + + if ($bundle->get('source') == 'image') { + $routes['dcx_migration.form.' . $bundle->id()] = new Route( + // Path to attach this route to: + 'media/add/' . $bundle->id(), + // Route defaults: + [ + '_form' => '\Drupal\dcx_migration\Form\DcxImportForm', + '_title' => 'Import Image from DC-X', + ], + // Route requirements: + [ + '_entity_create_access' => 'media:' . $bundle->id(), + ], + [ + '_admin_route' => TRUE, + ] + ); + } } - } return $routes;