Completed
Push — 8.x-1.x ( 48b271...fbaab6 )
by Janez
02:46
created

CtoolsFallbackRouteEnhancer::enhance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace Drupal\entity_browser\Routing;
4
5
use Drupal\Core\Extension\ModuleHandlerInterface;
6
use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Routing\Route;
9
10
/**
11
 * Enhances Entity browser edit/add form routes to display a message if ctools is missing.
12
 */
13
class CtoolsFallbackRouteEnhancer implements RouteEnhancerInterface {
14
15
  /**
16
   * The module handler service.
17
   *
18
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
19
   */
20
  protected $moduleHandler;
21
22
  /**
23
   * Constructs a CtoolsFallbackRouteEnhancer object.
24
   *
25
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
26
   *   Module handler service.
27
   */
28
  public function __construct(ModuleHandlerInterface $module_handler) {
29
    $this->moduleHandler = $module_handler;
30
  }
31
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public function enhance(array $defaults, Request $request) {
36
    if (!$this->moduleHandler->moduleExists('ctools')) {
37
      $defaults['_controller'] = '\Drupal\entity_browser\Controllers\CtoolsFallback::displayMessage';
38
    }
39
40
    return $defaults;
41
  }
42
43
  /**
44
   * {@inheritdoc}
45
   */
46
  public function applies(Route $route) {
47
    return $route->hasDefault('_entity_wizard') && strpos($route->getDefault('_entity_wizard'), 'entity_browser.') === 0;
48
  }
49
50
}
51