Skip to content

Commit

Permalink
while updating from media_enitiy to media in core, when there is a mo…
Browse files Browse the repository at this point in the history
…dule 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)
  • Loading branch information
ol0lll authored Jun 18, 2020
1 parent f61fe48 commit 419ae40
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions modules/dcx_migration/src/Routing/MediaRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 419ae40

Please sign in to comment.