|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\df_tools_panelizer\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Drush\Commands\DrushCommands; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* A Drush commandfile. |
|
9
|
|
|
* |
|
10
|
|
|
* In addition to this file, you need a drush.services.yml |
|
11
|
|
|
* in root of your module, and a composer.json file that provides the name |
|
12
|
|
|
* of the services file to use. |
|
13
|
|
|
* |
|
14
|
|
|
* See these files for an example of injecting Drupal services: |
|
15
|
|
|
* - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php |
|
16
|
|
|
* - http://cgit.drupalcode.org/devel/tree/drush.services.yml |
|
17
|
|
|
*/ |
|
18
|
|
|
class DfToolsPanelizerCommands extends DrushCommands { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Exports a given Node's Panelizer Display to a pseudo-config file. |
|
22
|
|
|
* |
|
23
|
|
|
* @param $nid |
|
24
|
|
|
* The ID of the override Node. |
|
25
|
|
|
* @param $scenario |
|
26
|
|
|
* The target Scenario. |
|
27
|
|
|
* @usage df-pe 1 dfs_tec |
|
28
|
|
|
* Export the Panels Display of Node 1 to the given scenario's data directory. |
|
29
|
|
|
* @validate-module-enabled panelizer,df_tools_panelizer |
|
30
|
|
|
* |
|
31
|
|
|
* @command df:panelizer-export |
|
32
|
|
|
* @aliases df-pe,df-panelizer-export |
|
33
|
|
|
* |
|
34
|
|
|
* @return bool |
|
35
|
|
|
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function panelizerExport($nid, $scenario) { |
|
38
|
|
|
// Load the Node. |
|
39
|
|
|
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid); |
|
40
|
|
|
|
|
41
|
|
|
// Check if it is Panelized. |
|
42
|
|
|
if ($node->panelizer) { |
|
|
|
|
|
|
43
|
|
|
// Get the path to the current scenario. |
|
44
|
|
|
$base_path = drupal_get_path('module', $scenario); |
|
45
|
|
|
if (!$base_path) { |
|
46
|
|
|
drupal_set_message(t('The scenario @scenario is not installed.', ['@scenario' => $scenario]), 'error'); |
|
|
|
|
|
|
47
|
|
|
return FALSE; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// Write YAML to a file. |
|
51
|
|
|
$panels_file = $base_path . '/data/panelizer.panels_display.node.'.$node->uuid() . '.yml'; |
|
52
|
|
|
$configuration = \Drupal::service('panelizer')->getPanelsDisplay($node, 'full')->getConfiguration(); |
|
53
|
|
|
$yaml = \Symfony\Component\Yaml\Yaml::dump($configuration, 99, 2); |
|
54
|
|
|
file_put_contents($panels_file, $yaml); |
|
55
|
|
|
|
|
56
|
|
|
drupal_set_message(t('Successfully exported Panelizer display for Node @nid to @panels_file', ['@nid' => $node->id(), '@panels_file' => $panels_file])); |
|
|
|
|
|
|
57
|
|
|
return TRUE; |
|
58
|
|
|
} |
|
59
|
|
|
else { |
|
60
|
|
|
drupal_set_message(t('The given Node is not Panelized.'), 'error'); |
|
|
|
|
|
|
61
|
|
|
return FALSE; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|