public static function Blocks::disable in Hook Update Deploy Tools 7
Disables a block for a specific theme.
Parameters
string $module: The machine name of the module that created the block. Use 'block' if was one created in the block UI.
string $block_delta: the block delta (machine name of the block)
string $theme: The name of the theme to target. Defaults to default theme.
Return value
string The message to output to the hook_update_N.
Throws
HudtException In the event that the disable was unssuccessful.
File
- src/
Blocks.php, line 54
Class
- Blocks
- Public methods for working with Blocks.
Namespace
HookUpdateDeployToolsCode
public static function disable($module, $block_delta, $theme = NULL) {
try {
// Gather the theme.
$theme = !empty($theme) ? $theme : variable_get('theme_default', NULL);
Check::notEmpty('$theme', $theme);
Check::notEmpty('$module', $module);
Check::notEmpty('$block_delta', $block_delta);
$vars = array(
'@module' => $module,
'@block_delta' => $block_delta,
'@theme' => $theme,
);
$block_original = self::load($module, $block_delta, $theme);
if ($block_original->region === (string) \BLOCK_REGION_NONE) {
$message = 'The block @module:@block_delta for theme:@theme was already disabled. No change.';
}
else {
// The block is not disabled, so disable it.
$fields = array(
'region' => \BLOCK_REGION_NONE,
);
self::updateInstancePropertiesSilent($module, $block_delta, $theme, $fields);
$block_new = self::load($module, $block_delta, $theme);
// Verify that it stuck.
if ($block_new->region === (string) \BLOCK_REGION_NONE) {
$message = 'The block @module:@block_delta for theme:@theme was disabled.';
}
else {
// The change did not stick.
throw new HudtException('The block @module:@block_delta for theme:@theme was NOT disabled.', $vars, WATCHDOG_ERROR, TRUE);
}
}
} catch (\Exception $e) {
$vars['!error'] = method_exists($e, 'logMessage') ? $e
->logMessage() : $e
->getMessage();
if (!method_exists($e, 'logMessage')) {
// Not logged yet, so log it.
$message = 'Blocks::disable @module:@block_delta for theme:@theme failed because: !error';
Message::make($message, $vars, WATCHDOG_ERROR);
}
throw new HudtException('Caught Exception: Update aborted! !error', $vars, WATCHDOG_ERROR, FALSE);
}
$return_msg = Message::make($message, $vars, WATCHDOG_INFO, 2);
return $return_msg;
}