diff --git a/src/Routing/CtoolsFallbackRouteEnhancer.php b/src/Routing/CtoolsFallbackRouteEnhancer.php index e2988e2..1096a47 100644 --- a/src/Routing/CtoolsFallbackRouteEnhancer.php +++ b/src/Routing/CtoolsFallbackRouteEnhancer.php @@ -3,14 +3,15 @@ namespace Drupal\entity_browser\Routing; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface; +use Drupal\Core\Routing\EnhancerInterface; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Route; /** * Enhances Entity browser edit/add form routes to display a message if ctools is missing. */ -class CtoolsFallbackRouteEnhancer implements RouteEnhancerInterface { +class CtoolsFallbackRouteEnhancer implements EnhancerInterface { /** * The module handler service. @@ -33,7 +34,8 @@ class CtoolsFallbackRouteEnhancer implements RouteEnhancerInterface { * {@inheritdoc} */ public function enhance(array $defaults, Request $request) { - if (!$this->moduleHandler->moduleExists('ctools')) { + $route = $defaults[RouteObjectInterface::ROUTE_OBJECT]; + if ($this->isApplicable($route) && !$this->moduleHandler->moduleExists('ctools')) { $defaults['_controller'] = '\Drupal\entity_browser\Controllers\CtoolsFallback::displayMessage'; } @@ -41,9 +43,15 @@ class CtoolsFallbackRouteEnhancer implements RouteEnhancerInterface { } /** - * {@inheritdoc} + * Returns if current route use ctools default parameter '_entity_wizard'. + * + * @param \Symfony\Component\Routing\Route $route + * The route to check. + * + * @return bool + * TRUE if the route use ctools route default parameter, FALSE otherwise. */ - public function applies(Route $route) { + public function isApplicable(Route $route) { return $route->hasDefault('_entity_wizard') && strpos($route->getDefault('_entity_wizard'), 'entity_browser.') === 0; } diff --git a/src/Tests/ConfigUITest.php b/src/Tests/ConfigUITest.php index da58a79..5c4dd14 100644 --- a/src/Tests/ConfigUITest.php +++ b/src/Tests/ConfigUITest.php @@ -46,6 +46,14 @@ class ConfigUITest extends WebTestBase { // We need token module to test upload widget settings. $this->container->get('module_installer')->install(['token']); + $existing = $this->container->get('entity_type.manager') + ->getStorage('entity_browser') + ->loadMultiple(); + + if (empty($existing)) { + $this->assert(TRUE, 'There are no existing entity browsers'); + } + $this->drupalGet('/admin/config/content/entity_browser'); $this->assertResponse(403, "Anonymous user can't access entity browser listing page."); $this->drupalGet('/admin/config/content/entity_browser/add');