Version 1
[yaffs-website] / web / core / modules / system / tests / modules / plugin_test / src / Plugin / plugin_test / mock_block / MockLayoutBlockDeriver.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 layout block plugin.
9  *
10  * @see \Drupal\plugin_test\Plugin\MockBlockManager
11  */
12 class MockLayoutBlockDeriver 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     $derivatives = [
35       // Adding a NULL key signifies that the base plugin may also be used in
36       // addition to the derivatives. In this case, we allow the administrator
37       // to add a generic layout block to the page.
38       NULL => $base_plugin_definition,
39
40       // We also allow them to add a customized one. Here, we just mock the
41       // customized one, but in a real implementation, this would be fetched
42       // from some \Drupal::config() object.
43       'foo' => [
44         'label' => t('Layout Foo'),
45       ] + $base_plugin_definition,
46     ];
47
48     return $derivatives;
49   }
50
51 }