More tidying.
[yaffs-website] / web / modules / contrib / layout_plugin / layout_plugin.drush.inc
1 <?php
2 /**
3  * @file
4  * Drush integration.
5  */
6
7 use Drupal\Component\Serialization\Yaml;
8
9 /**
10  * Implements hook_drush_command().
11  */
12 function layout_plugin_drush_command() {
13   $items = array();
14
15   $items['layout-plugin-list'] = array(
16     'description' => 'List layouts.',
17     'arguments' => array(),
18     'options' => array(),
19     'examples' => array(
20       'drush layouts-list' => 'List layouts.',
21     ),
22   );
23
24   $items['layout-plugin-region-list'] = array(
25     'description' => 'List layout regions.',
26     'arguments' => array(),
27     'options' => array(),
28     'examples' => array(
29       'drush layouts-list' => 'List layouts.',
30     ),
31   );
32
33   $items['layout-plugin-region-normalize'] = array(
34     'description' => 'Parse regions.',
35     'arguments' => array(),
36     'options' => array(),
37     'examples' => array(
38       'drush layouts-list' => 'Parse layouts.',
39     ),
40   );
41
42   return $items;
43 }
44
45 /**
46  * Create a basic template and configuration file for new Display Suite layout.
47  */
48 function drush_layout_plugin_list($name = NULL) {
49   $layoutsManager = \Drupal::service('plugin.manager.layout_plugin');
50   /** @var $layoutsManager \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManager */
51   $plugins = $layoutsManager->getDefinitions();
52   foreach ($plugins as $id => $pluginInfo) {
53     $plugin = $layoutsManager->createInstance($id, array());
54     /** @var $plugin \Drupal\layout_plugin\Plugin\Layout\LayoutInterface */
55     drush_print(dt('Layout !id: !regions', array('!id' => $id, '!regions' => print_r($plugin->getRegionNames(), TRUE))));
56   }
57
58 }
59
60
61 /**
62  * Create a basic template and configuration file for a new Display Suite layout.
63  */
64 function drush_layout_plugin_region_list($name = NULL) {
65   $layoutsManager = \Drupal::service('plugin.manager.layout_plugin.region');
66   /** @var $layoutsManager \Drupal\layout_plugin\Plugin\LayoutRegion\LayoutRegionPluginManager */
67   $plugins = $layoutsManager->getDefinitions();
68   foreach ($plugins as $id => $pluginInfo) {
69     $plugin = $layoutsManager->createInstance($id, array());
70     /** @var $plugin \Drupal\layout_plugin\Plugin\Layout\LayoutInterface */
71     drush_print(dt('Layout region !id could be loaded.', array('!id' => $id)));
72   }
73
74 }
75
76 function drush_layout_plugin_region_normalize($file = NULL) {
77   $layouts = Yaml::decode(file_get_contents(drupal_get_path('module', 'layout_plugin_example'). '/layout_plugin_example.layouts.yml'));
78   foreach ($layouts as $layout_plugin_id => $layout_plugin_info) {
79     if ($layout_plugin_id === 'koleary') {
80       $regions = $layout_plugin_info['regions'];
81       var_dump($layout_plugin_id, $regions);
82     }
83   }
84
85 }