Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // sync panelizer settings using services
- function sync_panelizer_node($nid) {
- $context = stream_context_create(array(
- 'http' => array(
- 'header' => "Authorization: Basic " . base64_encode("u:p")
- )
- ));
- $contents = file_get_contents(variable_get('web_services_end_point', 'http://somesite.dev.zivtech.com') . '/rest/node/' . $nid . '.json', false, $context);
- $json = drupal_json_decode($contents);
- $node = node_load($nid);
- $node->title = $json['title'];
- $node->title_field = $json['title_field'];
- $node->body = $json['body'];
- foreach($json as $key => $value) {
- if(strpos($key,'field') !== false) {
- $node->$key = $value;
- }
- }
- // adjust the decoded json into the correct data
- $panes = array();
- foreach($json['panelizer']['page_manager']['display']['content'] as $key => $pane) {
- $pane = (object)$pane;
- $query = db_query("SELECT pid FROM {panels_pane} WHERE pid = :pid AND did = :did", array(
- ':pid' => $pane->pid,
- ':did' => $pane->did,
- ));
- if(!$query->fetch()) {
- // replace the name of the pid if it doesn't yet exist on the site
- $pid = $pane->pid;
- $pane->pid = 'new-' . $pane->uuid;
- $replace_pids[$pid] = $pane->pid;
- }
- // sync the did with the existing one (since it may differ)
- $pane->did = $node->panelizer['page_manager']->did;
- $panes[$pane->pid] = $pane;
- $panes[$pane->pid]->configuration = (array)$panes[$pane->pid]->configuration;
- $panes[$pane->pid]->style = (array)$panes[$pane->pid]->style;
- }
- // trick panelizer into thinking we are saving this from the UI.
- $node->panelizer['page_manager']->display_is_modified = TRUE;
- $node->panelizer['page_manager']->display->content = $panes;
- $node->panelizer['page_manager']->display->panels = $json['panelizer']['page_manager']['display']['panels'];
- // replace pids with new-uuid values if needed
- foreach($node->panelizer['page_manager']->display->panels as $region => $pids) {
- foreach($pids as $key => $pid) {
- if($replace_pids[$pid]) {
- $node->panelizer['page_manager']->display->panels[$region][$key] = $replace_pids[$pid];
- }
- }
- }
- node_save($node);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement