Skip to content

Instantly share code, notes, and snippets.

@litzinger
Created March 1, 2012 21:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save litzinger/1953488 to your computer and use it in GitHub Desktop.
Save litzinger/1953488 to your computer and use it in GitHub Desktop.
Clone publish layouts
<?php
$field_display = array(
'visible' => TRUE,
'collapse' => FALSE,
'html_buttons' => TRUE,
'is_hidden' => FALSE,
'width' => '100%'
);
$data = array(
'member_group' => $group_id,
'channel_id' => $row->channel_id
);
$qry = $this->EE->db->get_where('layout_publish', $data);
$insert = array_merge($data, array(
'field_layout' => $qry->row('field_layout'),
'site_id' => $qry->row('site_id'),
'channel_id' => $channel_id
));
// See if it's a Structure listing channel first.
if(array_key_exists('structure', $this->EE->addons->get_installed()))
{
$settings = $this->get_structure_settings();
$channel_data = $settings[$channel_id];
// If it's unmanaged or a listing, we need to clean up the field_layout.
if($channel_data['type'] != 'page')
{
$field_layout = unserialize($insert['field_layout']);
// Remove Structure tab entirely
if($channel_data['type'] == 'unmanaged')
{
unset($field_layout['structure']);
}
// Just remove a few of fields
elseif($channel_data['type'] == 'listing')
{
unset($field_layout['structure']['structure__listing_channel']);
unset($field_layout['structure']['structure__parent_id']);
unset($field_layout['structure']['structure__hidden']);
}
$insert['field_layout'] = serialize($field_layout);
}
}
// Going to do a few channel specific things here so the publish layouts
// don't blow up and throw a bunch of PHP errors.
// Get channel settings
$qry = $this->EE->db->get_where('channels', array('channel_id' => $channel_id));
$field_layout = unserialize($insert['field_layout']);
// See if Revisions are enabled for the channel, if not, make sure it's not a set tab
if($qry->row('enable_versioning') == 'n')
{
unset($field_layout['revisions']);
}
// Remove the comment exp date field if it's in the layout and commenting is off
if($qry->row('comment_system_enabled') == 'n')
{
unset($field_layout['date']['comment_expiration_date']);
}
// If commenting is on, give the field the default display
else
{
$field_layout['date']['comment_expiration_date'] = $field_display;
}
$insert['field_layout'] = serialize($field_layout);
$this->EE->db->insert('layout_publish', $insert);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment