|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @file |
|
5
|
|
|
* Migrations for Landing Nodes. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class DFLandingNodes extends ImportBaseNodes { |
|
9
|
|
|
|
|
10
|
|
|
public function __construct($arguments) { |
|
11
|
|
|
parent::__construct($arguments); |
|
12
|
|
|
$this->description = t('Import Landing nodes.'); |
|
13
|
|
|
|
|
14
|
|
|
// Our parent defines this, but since we have indeterminate csvcolumns "title" is no longer set, just "Title" |
|
15
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
|
16
|
|
|
array( |
|
17
|
|
|
'Title' => array( |
|
18
|
|
|
'type' => 'varchar', |
|
19
|
|
|
'length' => 255, |
|
20
|
|
|
'not null' => TRUE, |
|
21
|
|
|
), |
|
22
|
|
|
), |
|
23
|
|
|
MigrateDestinationNode::getKeySchema() |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
// Create a MigrateSource object. |
|
27
|
|
|
if (isset($arguments['path'])) { |
|
28
|
|
|
$import_path = $arguments['path']; |
|
29
|
|
|
} |
|
30
|
|
|
else { |
|
31
|
|
|
$import_path = drupal_get_path('module', 'df_tools_panelizer') . '/import/df_tools_panelizer.nodes.landing.csv'; |
|
32
|
|
|
} |
|
33
|
|
|
$this->source = new MigrateSourceCSV($import_path, array(), array('header_rows' => 1)); |
|
34
|
|
|
$this->destination = new MigrateDestinationNode('landing'); |
|
35
|
|
|
|
|
36
|
|
|
$this->addFieldMapping('path', 'Path'); |
|
37
|
|
|
$this->addFieldMapping('title', 'Title'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function prepareRow($row) { |
|
41
|
|
|
// Check for columns that define region content |
|
42
|
|
|
foreach ($row as $key => $value) { |
|
43
|
|
|
// Set the value of this key to the exploded list of UUIDs |
|
44
|
|
|
if (strpos($key, 'region-') === 0) { |
|
45
|
|
|
$row->$key = explode(",", $value); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
return TRUE; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function complete($entity, stdClass $row) { |
|
52
|
|
|
// Load the new node |
|
53
|
|
|
list($id) = entity_extract_ids('node', $entity); |
|
54
|
|
|
$node = node_load($id); |
|
55
|
|
|
|
|
56
|
|
|
// As each node is imported, add default Panels displays and Panels if necessary |
|
57
|
|
|
foreach ($row as $key => $value) { |
|
|
|
|
|
|
58
|
|
|
// Check if this is a region column and that there are UUIDs set |
|
59
|
|
|
if (strpos($key, 'region-') === 0 && !empty($value)) { |
|
60
|
|
|
// Parse out the region name |
|
61
|
|
|
$location = str_replace('region-', '', $key); |
|
62
|
|
|
|
|
63
|
|
|
// Grab the display from the new Landing node |
|
64
|
|
|
$display = $node->panelizer['page_manager']->display; |
|
65
|
|
|
|
|
66
|
|
|
// Loop through each UUID in this region and add a new pane for this node |
|
67
|
|
|
foreach ($value as $uuid) { |
|
68
|
|
|
$pane = panels_new_pane('fieldable_panels_pane', 'uuid:' . $uuid, TRUE); |
|
69
|
|
|
// Check to see if any classy panel styles are included for this pane |
|
70
|
|
|
if (array_key_exists($uuid . '-style', $row) && $settings = json_decode($row->{$uuid . '-style'}, TRUE)) { |
|
71
|
|
|
// Add our default settings |
|
72
|
|
|
$settings['classy_panel_styles_flag'] = 'classy-panel-styles pane'; |
|
73
|
|
|
$pane->style = array( |
|
74
|
|
|
'style' => 'classy_panel_styles:cps_default', |
|
75
|
|
|
'settings' => $settings |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
// Add the pane to the display |
|
79
|
|
|
$display->add_pane($pane, $location); |
|
80
|
|
|
// Save the display |
|
81
|
|
|
$display = panels_save_display($display); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// Mark the Node as modified so that Panelizer is aware of our changes |
|
85
|
|
|
$node->panelizer['page_manager']->display_is_modified = TRUE; |
|
86
|
|
|
} |
|
87
|
|
|
// Check to see if a display setting needs to be changed |
|
88
|
|
|
elseif (strpos($key, 'display-') === 0) { |
|
89
|
|
|
// Parse out the display setting name |
|
90
|
|
|
$setting = str_replace('display-', '', $key); |
|
91
|
|
|
|
|
92
|
|
|
// Change the value for this display setting |
|
93
|
|
|
$node->panelizer['page_manager']->display->$setting = $value; |
|
94
|
|
|
// Mark the Node as modified so that Panelizer is aware of our changes |
|
95
|
|
|
$node->panelizer['page_manager']->display_is_modified = TRUE; |
|
96
|
|
|
panels_save_display($node->panelizer['page_manager']->display); |
|
97
|
|
|
} |
|
98
|
|
|
// Check to see if a panelizer settings needs to be changed |
|
99
|
|
|
elseif (strpos($key, 'panelizer-') === 0) { |
|
100
|
|
|
// Parse out the panelizer setting name |
|
101
|
|
|
$setting = str_replace('panelizer-', '', $key); |
|
102
|
|
|
$node->panelizer['page_manager']->$setting = $value; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// If we've made changes, save the node |
|
107
|
|
|
if ($node->panelizer['page_manager']->display_is_modified == TRUE) { |
|
108
|
|
|
node_save($node); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|