class Block extends LayoutHandler {
var $status;
var $module;
var $delta;
var $childDelta;
var $uuid;
var $style;
var $conditions = array();
var $contexts = array();
public $layout_title;
function __construct($plugin_name, array $data = array()) {
parent::__construct($plugin_name, $data);
$this->plugin = $plugin_name;
$data += array(
'settings' => array(),
'style' => array(
'plugin' => 'default',
'data' => array(),
),
'conditions' => array(),
);
$data['settings'] += array(
'title_display' => LAYOUT_TITLE_DEFAULT,
'title' => '',
'style' => 'default',
'block_settings' => array(),
'contexts' => array(),
);
list($this->module, $this->delta) = explode(':', $plugin_name);
$this->uuid = isset($data['uuid']) ? $data['uuid'] : NULL;
$this->is_new = !$this->uuid;
$this->status = isset($data['status']) ? $data['status'] : BLOCK_ENABLED;
$parts = explode(':', $this->plugin, 3);
$this->childDelta = isset($parts[2]) ? $parts[2] : NULL;
$this->style = layout_create_handler('layout_style', $data['style']['plugin'], $data['style']['data']);
foreach ($data['conditions'] as $condition) {
$this->conditions[] = layout_create_handler('layout_access', $condition['plugin'], $condition['data']);
}
$this->settings = $data['settings'];
}
function prepare() {
}
function getTitle() {
$title = NULL;
if ($this->settings['title_display'] === LAYOUT_TITLE_CUSTOM && $this->settings['title']) {
$title = check_plain($this->settings['title']);
}
return $title;
}
function getAdminTitle() {
if (!empty($this->settings['admin_label'])) {
return check_plain($this->settings['admin_label']);
}
$title = $this->getTitle();
if (empty($title)) {
$info = $this->getBlockInfo();
$title = check_plain($info['info']);
}
return $title;
}
function getContent() {
return '';
}
function getAdminPreview() {
if (!empty($this->settings['admin_description'])) {
return filter_xss($this->settings['admin_description']);
}
$info = $this->getBlockInfo();
$preview = '';
if (isset($info['description'])) {
$preview .= '<p>' . filter_xss($info['description']) . '</p>';
}
$preview .= $this->getAdminConditionsPreview();
return $preview;
}
function getBlockInfo() {
$block_info = layout_get_block_info($this->module, $this->delta);
if ($this->childDelta) {
$children_blocks = $this->getChildren();
$block_info = isset($children_blocks) ? array_merge($block_info, $children_blocks[$this->childDelta]) : NULL;
}
return $block_info;
}
function getAdminConditionsPreview() {
$preview = '';
if (!empty($this->conditions)) {
$condition_list = array();
foreach ($this->conditions as $condition) {
$condition_list[] = $condition->summary();
}
$conditions = theme('item_list', array('items' => $condition_list, 'attributes' => array('class' => array('block-conditions'))));
$fieldset = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Conditions'),
'#children' => $conditions,
'#parents' => array(),
);
$form_state = array();
form_process_fieldset($fieldset, $form_state);
$preview = backdrop_render($fieldset);
}
return $preview;
}
function form(&$form, &$form_state) {
$layout = $form_state['layout'];
$contexts = $layout->getContexts();
$block_info = $this->getBlockInfo();
$current_context_settings = isset($this->settings['contexts']) ? $this->settings['contexts'] : array();
$form['contexts'] = layout_contexts_form_element($contexts, $current_context_settings, $block_info);
$form['title_display']['#tree'] = FALSE;
$form['title_display']['title_display'] = array(
'#type' => 'select',
'#title' => t('Block title type'),
'#options' => array(
LAYOUT_TITLE_DEFAULT => t('Default'),
LAYOUT_TITLE_CUSTOM => t('Custom'),
LAYOUT_TITLE_NONE => t('None'),
),
'#default_value' => $this->settings['title_display'],
);
$form['title_display']['title'] = array(
'#type' => 'textfield',
'#default_value' => $this->settings['title'],
'#title' => t('Custom title'),
'#states' => array(
'visible' => array(
'form.layout-block-configure-form :input[name="title_display"]' => array('value' => LAYOUT_TITLE_CUSTOM),
),
),
'#maxlength' => 255,
);
$actions_weight = $form['actions']['#weight'];
$form['admin_label'] = array(
'#type' => 'fieldset',
'#title' => t('Admin label'),
'#tree' => FALSE,
'#collapsed' => empty($this->settings['admin_label']),
'#collapsible' => TRUE,
'#weight' => $actions_weight - 1,
'#access' => $this->module != 'block',
);
$form['admin_label']['admin_label'] = array(
'#type' => 'textfield',
'#default_value' => isset($this->settings['admin_label']) ? $this->settings['admin_label'] : '',
'#title' => t('Admin label'),
'#description' => t('Used to identify the block on layout pages.'),
'#maxlength' => 255,
);
$form['admin_label']['admin_description'] = array(
'#type' => 'textfield',
'#title' => t('Admin description'),
'#default_value' => isset($this->settings['admin_description']) ? $this->settings['admin_description'] : '',
'#maxlength' => 128,
'#description' => t('This text is used only in administrative interfaces. It will not be shown to site visitors.<br />Allowed HTML tags: @tags', array('@tags' => _filter_xss_display_allowed_tags())),
);
}
function formValidate($form, &$form_state) {
}
function formSubmit($form, &$form_state) {
$this->settings['title_display'] = $form_state['values']['title_display'];
$this->settings['title'] = $form_state['values']['title'];
$this->settings['admin_label'] = $form_state['values']['admin_label'];
$this->settings['admin_description'] = $form_state['values']['admin_description'];
$this->settings['style'] = $form_state['values']['style'];
if (isset($form_state['values']['contexts'])) {
$this->settings['contexts'] = $form_state['values']['contexts'];
}
else {
$this->settings['contexts'] = array();
}
}
function getClone() {
$new_block = clone $this;
$uuid = new Uuid();
$new_block->uuid = $uuid->generate();
$new_block->is_new = TRUE;
return $new_block;
}
function toArray() {
$array = array(
'status' => $this->status,
'module' => $this->module,
'delta' => $this->delta,
'settings' => $this->settings,
'uuid' => $this->uuid,
'style' => array(
'plugin' => $this->style->plugin,
'data' => $this->style->toArray(),
),
);
foreach ($this->conditions as $condition) {
$array['conditions'][] = array(
'plugin' => $condition->plugin,
'data' => $condition->toArray(),
);
}
return $array;
}
function getRequiredContexts() {
$required_contexts = array();
$block_info = $this->getBlockInfo();
if (!empty($block_info['required contexts'])) {
$required_contexts = $block_info['required contexts'];
}
return $required_contexts;
}
function setContexts(array $all_contexts) {
$block_info = $this->getBlockInfo();
$all_contexts_set = TRUE;
if (!empty($block_info['required contexts'])) {
$all_contexts_set = layout_set_handler_contexts($this->contexts, $all_contexts, $block_info['required contexts'], $this->settings['contexts']);
}
if (!$all_contexts_set) {
return FALSE;
}
foreach ($this->conditions as $condition) {
$all_contexts_set = $condition->setContexts($all_contexts);
if (!$all_contexts_set) {
return FALSE;
}
}
return TRUE;
}
function checkAccess() {
foreach ($this->conditions as $condition) {
if (!$condition->checkAccess()) {
return FALSE;
}
}
return TRUE;
}
function getChildren() {
return NULL;
}
}