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

CtoolsFallbackRouteEnhancer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A enhance() 0 7 2
A applies() 0 3 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