Skip to content

Commit f2264d1

Browse files
committed
Merge pull request #77 from drupol/Merge-parameters
Merge definitions from .services.yml properly.
2 parents 41ef286 + ad21171 commit f2264d1

File tree

26 files changed

+272
-27
lines changed

26 files changed

+272
-27
lines changed

modules/providers/service_container_annotation_discovery/lib/Drupal/service_container_annotation_discovery/Tests/ServiceContainerAnnotationDiscoveryIntegrationTest.php

+27-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class ServiceContainerAnnotationDiscoveryIntegrationTest extends ServiceContaine
1919
* {@inheritdoc}
2020
*/
2121
protected function setUp() {
22-
parent::setUp('service_container_annotation_discovery_test');
23-
22+
$modules[] = 'service_container_annotation_discovery_test';
23+
$modules[] = 'service_container_annotation_discovery_subtest';
24+
parent::setUp($modules);
2425
$this->container = \Drupal::getContainer();
2526
}
2627

@@ -97,4 +98,28 @@ public function testDoctrinePlugin() {
9798
$object = $plugin_manager->createInstance($plugin['name']);
9899
$this->assertTrue($object->getMessenger() instanceof MessengerInterface);
99100
}
101+
102+
/**
103+
* Tests if multiple module with plugins annotations are available as services.
104+
*/
105+
function testMultiple() {
106+
$plugins = array(
107+
array(
108+
'owner' => 'sc_doctrine_test',
109+
'type' => 'Plugin1',
110+
'name' => 'Plugin1A',
111+
),
112+
array(
113+
'owner' => 'sc_doctrine_test',
114+
'type' => 'Plugin5',
115+
'name' => 'Plugin5B',
116+
),
117+
);
118+
foreach ($plugins as $plugin) {
119+
$plugin_manager = $this->container->get($plugin['owner'] . '.' . $plugin['type']);
120+
$this->assertTrue($plugin_manager->hasDefinition($plugin['name']));
121+
$object = $plugin_manager->createInstance($plugin['name']);
122+
$this->assertTrue($object instanceof PluginBase);
123+
}
124+
}
100125
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name = Services Container Annotation Discovery SubTest
2+
description = Services Container Annotation Discovery SubTest.
3+
package = Utility
4+
core = 7.x
5+
php = 5.3.10
6+
hidden = TRUE
7+
8+
; Dependencies
9+
dependencies[] = service_container_symfony
10+
dependencies[] = service_container_annotation_discovery
11+
12+
registry_autoload[] = PSR-0
13+
registry_autoload[] = PSR-4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
annotated_plugins_auto_discovery.service_container_annotation_discovery_subtest:
3+
- { owner: 'sc_doctrine_test', type: 'Plugin5', directory: 'Plugin/Plugin5', class: 'Drupal\Component\Annotation\Plugin' }
4+
- { owner: 'sc_doctrine_test', type: 'Plugin6', directory: 'Plugin/Plugin6', class: 'Drupal\Component\Annotation\Plugin' }
5+
- { owner: 'sc_doctrine_test', type: 'Plugin7', directory: 'Plugin/Plugin7', class: 'Drupal\Component\Annotation\Plugin' }
6+
- { owner: 'sc_doctrine_test', type: 'Plugin8', directory: 'Plugin/Plugin8', class: 'Drupal\Component\Annotation\Plugin' }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin5\Plugin5A;
4+
5+
use Drupal\Component\Annotation\Plugin;
6+
use Drupal\Component\Plugin\PluginBase;
7+
8+
/**
9+
* Class Plugin5A
10+
*
11+
* @Plugin(
12+
* id = "Plugin5A",
13+
* label = "Label Plugin5A"
14+
* )
15+
*
16+
* @package Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin5\Plugin5A
17+
*/
18+
class Plugin5A extends PluginBase {
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin5\Plugin5B;
4+
5+
use Drupal\Component\Annotation\Plugin;
6+
use Drupal\Component\Plugin\PluginBase;
7+
8+
/**
9+
* Class Plugin5B
10+
*
11+
* @Plugin(
12+
* id = "Plugin5B",
13+
* label = "Label Plugin5B"
14+
* )
15+
*
16+
* @package Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin5\Plugin5B
17+
*/
18+
class Plugin5B extends PluginBase {
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin6\Plugin6A;
4+
5+
use Drupal\Component\Annotation\Plugin;
6+
use Drupal\Component\Plugin\PluginBase;
7+
8+
/**
9+
* Class Plugin6A
10+
*
11+
* @Plugin(
12+
* id = "Plugin6A",
13+
* label = "Label Plugin6A"
14+
* )
15+
*
16+
* @package Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin6\Plugin6A
17+
*/
18+
class Plugin6A extends PluginBase {
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin6\Plugin6B;
4+
5+
use Drupal\Component\Annotation\Plugin;
6+
use Drupal\Component\Plugin\PluginBase;
7+
8+
/**
9+
* Class Plugin6B
10+
*
11+
* @Plugin(
12+
* id = "Plugin6B",
13+
* label = "Label Plugin6B"
14+
* )
15+
*
16+
* @package Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin6\Plugin6B
17+
*/
18+
class Plugin6B extends PluginBase {
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin7\Plugin7A;
4+
5+
use Drupal\Component\Annotation\Plugin;
6+
use Drupal\Component\Plugin\PluginBase;
7+
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8+
use Symfony\Component\DependencyInjection\ContainerInterface;
9+
10+
/**
11+
* Class Plugin7A
12+
*
13+
* @Plugin(
14+
* id = "Plugin7A",
15+
* label = "Label Plugin7A"
16+
* )
17+
*
18+
* @package Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin7\Plugin7A
19+
*/
20+
class Plugin7A extends PluginBase implements ContainerFactoryPluginInterface {
21+
22+
protected $data;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
28+
return new static($configuration, $plugin_id, $plugin_definition, 'Hello world!');
29+
}
30+
31+
public function __construct($configuration, $plugin_id, $plugin_definition, $data) {
32+
parent::__construct($configuration, $plugin_id, $plugin_definition);
33+
$this->data = $data;
34+
}
35+
36+
public function getData() {
37+
return $this->data;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin8\Plugin8A;
4+
5+
use Drupal\Component\Annotation\PluginID;
6+
use Drupal\Component\Plugin\PluginBase;
7+
use Drupal\service_container\Messenger\MessengerInterface;
8+
use Symfony\Component\DependencyInjection\ContainerInterface;
9+
10+
/**
11+
* Class Plugin8A
12+
*
13+
* @Plugin(
14+
* id = "Plugin8A",
15+
* label = "Label Plugin8A",
16+
* arguments = {
17+
* "@messenger"
18+
* }
19+
* )
20+
*
21+
* @package Drupal\service_container_annotation_discovery_subtest\Plugin\Plugin8\Plugin8A
22+
*/
23+
class Plugin8A extends PluginBase {
24+
25+
/**
26+
* @var \Drupal\service_container\Messenger\MessengerInterface
27+
*/
28+
protected $messenger;
29+
30+
public function __construct($configuration, $plugin_id, $plugin_definition, MessengerInterface $messenger) {
31+
parent::__construct($configuration, $plugin_id, $plugin_definition);
32+
$this->messenger = $messenger;
33+
}
34+
35+
public function getMessenger() {
36+
return $this->messenger;
37+
}
38+
}

modules/providers/service_container_annotation_discovery/tests/modules/service_container_annotation_discovery_test/service_container_annotation_discovery_test.services.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
annotated_plugins_auto_discovery:
2+
annotated_plugins_auto_discovery.service_container_annotation_discovery_test:
33
- { owner: 'sc_doctrine_test', type: 'Plugin1', directory: 'Plugin/Plugin1', class: 'Drupal\Component\Annotation\Plugin' }
44
- { owner: 'sc_doctrine_test', type: 'Plugin2', directory: 'Plugin/Plugin2', class: 'Drupal\Component\Annotation\Plugin' }
55
- { owner: 'sc_doctrine_test', type: 'Plugin3', directory: 'Plugin/Plugin3', class: 'Drupal\Component\Annotation\Plugin' }

modules/providers/service_container_annotation_discovery/tests/modules/service_container_annotation_discovery_test/src/Plugin/Plugin4/Plugin4A/Plugin4A.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* }
1919
* )
2020
*
21-
* @package Drupal\service_container_annotation_discovery_test\Plugin\Plugin3\Plugin3A
21+
* @package Drupal\service_container_annotation_discovery_test\Plugin\Plugin4\Plugin4A
2222
*/
2323
class Plugin4A extends PluginBase {
2424

modules/providers/service_container_symfony/lib/Drupal/service_container_symfony/Tests/ServiceContainerSymfonyTest.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,26 @@ public static function getInfo() {
2626
* {@inheritdoc}
2727
*/
2828
protected function setUp() {
29-
$modules[] = 'test_service_container_symfony';
29+
$modules[] = 'service_container_symfony_test';
30+
$modules[] = 'service_container_symfony_subtest';
3031
parent::setUp($modules);
31-
}
32+
}
3233

3334
/**
3435
* Tests some basic
3536
*/
3637
public function testInit() {
37-
$this->assertTrue(\Drupal::hasService('test_service_container_symfony_yolo'));
38-
$this->assertFalse(\Drupal::hasService('test_service_container_symfony_yolo1'));
38+
$this->assertTrue(\Drupal::hasService('service_container_symfony_test_yolo'));
39+
$this->assertFalse(\Drupal::hasService('service_container_symfony_test_yolo1'));
3940
}
4041

42+
/**
43+
* Tests with multiple modules enabled.
44+
*/
45+
public function testMultiple() {
46+
$this->assertTrue(\Drupal::hasService('service_container_symfony_test_yolo'));
47+
$this->assertFalse(\Drupal::hasService('service_container_symfony_test_yolo1'));
48+
$this->assertTrue(\Drupal::hasService('service_container_symfony_subtest_yolo'));
49+
$this->assertFalse(\Drupal::hasService('service_container_symfony_subtest_yolo1'));
50+
}
4151
}
42-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name = Test Symfony's Services Container (Subtest)
2+
description = Test Symfony's Services Container (Subtest)
3+
core = 7.x
4+
php = 5.3.10
5+
hidden = TRUE
6+
7+
; Dependencies
8+
dependencies[] = service_container_symfony_test
9+
10+
registry_autoload[] = PSR-0
11+
registry_autoload[] = PSR-4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
/**
3+
* @file
4+
* Main module file for the service_container_symfony_subtest module.
5+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
service_container_symfony_subtest_yolo:
3+
class: Drupal\service_container_symfony_subtest\ServiceContainerSymfonySubTestYolo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Drupal\service_container_symfony_subtest;
4+
5+
class ServiceContainerSymfonySubTestYolo {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = Test Symfony's Services Container
2-
description =
2+
description = Test Symfony's Services Container
33
core = 7.x
44
php = 5.3.10
55
hidden = TRUE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
/**
3+
* @file
4+
* Main module file for the service_container_symfony_test module.
5+
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
service_container_symfony_test_yolo:
3+
class: Drupal\service_container_symfony_test\ServiceContainerSymfonyTestYolo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Drupal\service_container_symfony_test;
4+
5+
class ServiceContainerSymfonyTestYolo {
6+
7+
}

modules/providers/service_container_symfony/tests/modules/test_service_container_symfony/src/TestServiceContainerSymfonyYolo.php

-7
This file was deleted.

modules/providers/service_container_symfony/tests/modules/test_service_container_symfony/test_service_container_symfony.module

-5
This file was deleted.

modules/providers/service_container_symfony/tests/modules/test_service_container_symfony/test_service_container_symfony.services.yml

-3
This file was deleted.

src/ServiceContainer/ServiceProvider/ServiceContainerServiceProvider.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,18 @@ public function getContainerDefinition() {
184184
* {@inheritdoc}
185185
*/
186186
public function alterContainerDefinition(&$container_definition) {
187+
foreach(array('annotated_plugins_auto_discovery', 'ctools_plugins_auto_discovery') as $prefix) {
188+
$container_definition['parameters'][$prefix] = array();
189+
foreach($container_definition['parameters'] as $parameter => $value) {
190+
if (strpos($parameter, $prefix) === 0) {
191+
$container_definition['parameters'][$prefix] = array_merge($container_definition['parameters'][$prefix], $value);
192+
}
193+
}
194+
}
187195

188196
if (!empty($container_definition['parameters']['ctools_plugins_auto_discovery']) && $this->moduleExists('ctools')) {
189197
$ctools_types = $this->cToolsGetTypes();
190-
$filtered_types = array_intersect_key($ctools_types, $container_definition['parameters']['ctools_plugins_auto_discovery']);
198+
$filtered_types = array_intersect_key($ctools_types, array_flip($container_definition['parameters']['ctools_plugins_auto_discovery']));
191199
$this->registerCToolsPluginTypes($container_definition, $filtered_types);
192200
}
193201

tests/modules/service_container_test_ctools/src/ServiceContainer/ServiceProvider/ServiceContainerServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ServiceContainerServiceProvider implements ServiceProviderInterface {
2121
*/
2222
public function getContainerDefinition() {
2323
$services = array();
24-
$parameters['ctools_plugins_auto_discovery']['service_container_test_ctools'] = TRUE;
24+
$parameters['ctools_plugins_auto_discovery.service_container_test_ctools'] = array('service_container_test_ctools');
2525

2626
return array(
2727
'parameters' => $parameters,

0 commit comments

Comments
 (0)