class LayoutRendererFlexible {
var $layout;
var $layout_info;
var $layout_template_info;
var $rendered_editor = array();
var $admin = TRUE;
var $prefix = '';
var $suffix = '';
var $region_buttons = array();
function __construct(Layout $layout, array $renderer_plugin) {
$template_id = $layout->layout_template;
$template_info = layout_get_layout_template_info($template_id);
$template_data = layout_flexible_tempstore_load($template_id);
foreach ($template_data->rows as $position => $info) {
$layout->positions[$position] = array();
$template_info['regions'][$position] = $position;
}
$this->admin = TRUE;
$this->layout = &$layout;
$this->layout_template_info = $template_info;
$this->layout_info = $this->layout_template_info;
}
function render() {
$this->addMeta();
$output = '<div id="layout-flexible-edit-main">';
$output .= $this->renderEditor();
$output .= '</div>';
return $output;
}
function renderEditor() {
$this->renderRowButtons();
module_load_include('inc', 'layout', 'layout.theme');
if (empty($this->layout_template_info['template'])) {
$theme = 'layout__' . $this->layout->layout_template;
}
else {
$theme = str_replace('-', '_', $this->layout_template_info['template']);
}
$this->rendered_editor = theme($theme, array('content' => array(), 'settings' => array(), 'layout' => $this->layout, 'layout_info' => $this->layout_template_info, 'renderer' => $this, 'admin' => $this->admin));
return $this->prefix . $this->rendered_editor . $this->suffix;
}
function addMeta() {
backdrop_add_library('system', 'backdrop.ajax');
backdrop_add_library('system', 'ui.sortable');
backdrop_add_js(backdrop_get_path('module', 'layout') . '/js/layout.admin.js');
backdrop_add_css(backdrop_get_path('module', 'layout') . '/css/layout.admin.css');
backdrop_add_css(backdrop_get_path('module', 'layout') . '/css/layout.flexible.admin.css');
}
function renderRowButtons() {
foreach ($this->layout_template_info['regions'] as $region_id => $title) {
$this->region_buttons[$region_id] = $this->getRowButtons($region_id);
}
return $this->region_buttons;
}
protected function getRowButtons($region_id) {
$links = array();
$links['configure'] = array(
'title' => t('Configure'),
'href' => 'admin/structure/layouts/settings/flexible-template/' . $this->layout_template_info['name'] . '/row/' . $region_id . '/configure',
'attributes' => array(
'class' => array('use-ajax'),
'data-dialog' => TRUE,
'data-dialog-options' => json_encode(array('dialogClass' => 'layout-dialog')),
),
);
$links['delete'] = array(
'title' => t('Delete row'),
'href' => 'admin/structure/layouts/settings/flexible-template/' . $this->layout_template_info['name'] . '/row/' . $region_id . '/delete',
'query' => array(
'token' => backdrop_get_token('layout-region-' . $region_id),
),
'attributes' => array(
'class' => array('use-ajax'),
),
);
$dropbutton = array(
'#type' => 'dropbutton',
'#links' => $links,
);
return backdrop_render($dropbutton);
}
}