ContentTranslationRouteSubscriber.php 4.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
<?php

/**
 * @file
 * Contains \Drupal\content_translation\Routing\ContentTranslationRouteSubscriber.
 */

namespace Drupal\content_translation\Routing;

10
use Drupal\Core\Entity\EntityManagerInterface;
11
use Drupal\Core\Routing\RouteSubscriberBase;
12
use Symfony\Component\Routing\Route;
13
use Symfony\Component\Routing\RouteCollection;
14
15
16
17

/**
 * Subscriber for entity translation routes.
 */
18
class ContentTranslationRouteSubscriber extends RouteSubscriberBase {
19
20
21
22

  /**
   * The entity type manager.
   *
23
   * @var \Drupal\Core\Entity\EntityManagerInterface
24
25
26
27
28
29
   */
  protected $entityManager;

  /**
   * Constructs a ContentTranslationRouteSubscriber object.
   *
30
   * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager
31
32
   *   The entity type manager.
   */
33
  public function __construct(EntityManagerInterface $entityManager) {
34
35
36
37
38
39
    $this->entityManager = $entityManager;
  }

  /**
   * {@inheritdoc}
   */
40
  protected function routes(RouteCollection $collection) {
41
    foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) {
42
43
44
      if (!empty($entity_info['translatable']) && !empty($entity_info['links']['drupal:content-translation-overview'])) {
        $path = $entity_info['links']['drupal:content-translation-overview'];

45
        $route = new Route(
46
         $path,
47
48
49
50
          array(
            '_content' => '\Drupal\content_translation\Controller\ContentTranslationController::overview',
            '_title' => 'Translate',
            'account' => 'NULL',
51
            '_entity_type' => $entity_type,
52
53
54
55
56
57
          ),
          array(
            '_access_content_translation_overview' => $entity_type,
            '_permission' => 'translate any entity',
          ),
          array(
58
            '_access_mode' => 'ANY',
59
60
61
62
63
64
65
66
67
68
            'parameters' => array(
              'entity' => array(
                'type' => 'entity:' . $entity_type,
              ),
            ),
          )
        );
        $collection->add("content_translation.translation_overview_$entity_type", $route);

        $route = new Route(
69
          $path . '/add/{source}/{target}',
70
71
72
73
74
          array(
            '_content' => '\Drupal\content_translation\Controller\ContentTranslationController::add',
            'source' => NULL,
            'target' => NULL,
            '_title' => 'Add',
75
            '_entity_type' => $entity_type,
76
77
78
79
80
81
82

          ),
          array(
            '_permission' => 'translate any entity',
            '_access_content_translation_manage' => 'create',
          ),
          array(
83
            '_access_mode' => 'ANY',
84
85
86
87
88
89
90
91
92
93
            'parameters' => array(
              'entity' => array(
                'type' => 'entity:' . $entity_type,
              ),
            ),
          )
        );
        $collection->add("content_translation.translation_add_$entity_type", $route);

        $route = new Route(
94
          $path . '/edit/{language}',
95
96
97
98
          array(
            '_content' => '\Drupal\content_translation\Controller\ContentTranslationController::edit',
            'language' => NULL,
            '_title' => 'Edit',
99
            '_entity_type' => $entity_type,
100
101
102
103
104
105
          ),
          array(
            '_permission' => 'translate any entity',
            '_access_content_translation_manage' => 'update',
          ),
          array(
106
            '_access_mode' => 'ANY',
107
108
109
110
111
112
113
114
            'parameters' => array(
              'entity' => array(
                'type' => 'entity:' . $entity_type,
              ),
            ),
          )
        );
        $collection->add("content_translation.translation_edit_$entity_type", $route);
115
116
117
118
119
120
121

        $route = new Route(
          $path . '/delete/{language}',
          array(
            '_content' => '\Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation',
            'language' => NULL,
            '_title' => 'Delete',
122
            '_entity_type' => $entity_type,
123
124
125
126
127
128
129
130
131
132
133
          ),
          array(
            '_permission' => 'translate any entity',
            '_access_content_translation_manage' => 'delete',
          ),
          array(
            'parameters' => array(
              'entity' => array(
                'type' => 'entity:' . $entity_type,
              ),
            ),
134
            '_access_mode' => 'ANY',
135
136
137
          )
        );
        $collection->add("content_translation.delete_$entity_type", $route);
138
139
140
141
142
      }
    }
  }

}