View source
<?php
function block_patterns($op, $id = null, &$data = null) {
$defaults = array(
'id' => NULL,
'module' => NULL,
'description' => NULL,
'info' => NULL,
'pages' => NULL,
'delete' => NULL,
);
$data = array_merge($defaults, (array) $data);
switch ($op) {
case 'tags':
return array(
'block',
);
break;
case 'actions':
return array(
'block_admin_display_form' => t('Block: Change the region or order of a block'),
'block_admin_configure' => t('Block: Configure block'),
'block_add_block_form' => t('Block: Add block'),
'block_box_delete' => t('Block: Delete block'),
);
break;
case 'prepare':
if ($data['id']) {
$split = strpos($data['id'], '-');
$data['module'] = substr($data['id'], 0, $split);
$data['delta'] = substr($data['id'], $split + 1);
unset($data['id']);
}
elseif ($data['info']) {
$delta = db_result(db_query('SELECT delta FROM {blocks} bl INNER JOIN {boxes} bo ON bl.delta = bo.bid AND bl.module = "block" WHERE info = "%s"', $data['info']));
if ($delta) {
$data['delta'] = $delta;
$data['module'] = 'block';
}
}
if ($data['description']) {
$data['info'] = $data['description'];
unset($data['description']);
}
if ($data['delete'] && !$data['info'] && $data['module'] == 'block') {
$data['info'] = db_result(db_query('SELECT info FROM {boxes} WHERE bid = "%d"', $data['delta']));
}
if ($data['pages'] && is_array($data['pages'])) {
$pages = implode("\r\n", $data['pages']);
$data['pages'] = str_replace('[front]', '<front>', $pages);
}
if (!($data['module'] && isset($data['delta'])) && $data['info']) {
$data['module'] = 'block';
}
break;
case 'pre-validate':
if (!($data['module'] && isset($data['delta'])) && !$data['info']) {
return t('Missing required <module>, <delta> tags. Possibly malformed <id> tag could be the problem too. If creating a new block, tag <info> is required.');
}
else {
if ($data['delete'] && $data['module'] != 'block') {
return t('Unable to delete non-block module blocks');
}
}
break;
case 'form_id':
$diff = array_diff($data, _block_patterns_display_keys());
if (!($data['module'] && $data['delta']) && $data['info']) {
return array(
'block_add_block_form',
'block_admin_display_form',
);
}
else {
if ($data['delete']) {
return 'block_box_delete';
}
else {
if (empty($diff)) {
return 'block_admin_display_form';
}
else {
return array(
'block_admin_configure',
'block_admin_display_form',
);
}
}
}
break;
case 'build':
module_load_include('inc', 'block', 'block.admin');
$blocks = _block_rehash();
usort($blocks, '_block_compare');
if ($id == 'block_box_delete') {
$data['op'] = t('Delete');
$data['confirm'] = 1;
}
else {
if ($id == 'block_admin_display_form') {
if (isset($data['status']) && $data['status'] == 0) {
$data['region'] = -1;
}
if ($data['module'] == 'block' && empty($data['delta'])) {
$data['delta'] = db_result(db_query("SELECT bid FROM {boxes} WHERE info = '%s'", $data['info']));
}
$data = array(
$data['module'] . '_' . $data['delta'] => $data,
);
}
}
return $data;
break;
case 'validate':
break;
case 'params':
if ($id == 'block_admin_configure') {
return array(
$data['module'],
$data['delta'],
);
}
else {
if ($id == 'block_admin_display_form') {
$blocks = _block_rehash();
$check = current($data);
foreach ($blocks as $key => &$block) {
if ($block['module'] == $check['module'] && $block['delta'] == $check['delta']) {
$blocks = array(
&$block,
);
break;
}
}
return array(
$blocks,
$check['theme'],
);
}
else {
if ($id == 'block_box_delete') {
return $data['delta'];
}
}
}
break;
}
}
function _block_patterns_display_keys() {
return array(
'module',
'delta',
'theme',
'weight',
'region',
'status',
);
}