d5f6d6c2937e596651466ae30b49142f7a5cc542
[yaffs-website] / web / core / modules / system / tests / modules / plugin_test / src / Plugin / plugin_test / mock_block / MockMenuBlockDeriver.php
1 <?php
2
3 namespace Drupal\plugin_test\Plugin\plugin_test\mock_block;
4
5 use Drupal\Component\Plugin\Derivative\DeriverInterface;
6
7 /**
8  * Mock implementation of DeriverInterface for the mock menu block plugin.
9  *
10  * @see \Drupal\plugin_test\Plugin\MockBlockManager
11  */
12 class MockMenuBlockDeriver implements DeriverInterface {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
18     $derivatives = $this->getDerivativeDefinitions($base_plugin_definition);
19     if (isset($derivatives[$derivative_id])) {
20       return $derivatives[$derivative_id];
21     }
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function getDerivativeDefinitions($base_plugin_definition) {
28     // This isn't strictly necessary, but it helps reduce clutter in
29     // DerivativePluginTest::testDerivativeDecorator()'s $expected variable.
30     // Since derivative definitions don't need further deriving, we remove this
31     // key from the returned definitions.
32     unset($base_plugin_definition['deriver']);
33
34     // Here, we create some mock menu block definitions for menus that might
35     // exist in a typical Drupal site. In a real implementation, we would query
36     // Drupal's configuration to find out which menus actually exist.
37     $derivatives = [
38       'main_menu' => [
39         'label' => t('Main menu'),
40       ] + $base_plugin_definition,
41       'navigation' => [
42         'label' => t('Navigation'),
43       ] + $base_plugin_definition,
44       'foo' => [
45         // Instead of the derivative label, the specific label will be used.
46         'label' => t('Derivative label'),
47         // This setting will be merged in.
48          'setting' => 'default'
49       ] + $base_plugin_definition,
50     ];
51
52     return $derivatives;
53   }
54
55 }