Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add theme debug command #429

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ system for each contributed module, theme and layout.
- Add or remove permissions from roles
- An implementation of Backdrop's telemetry function.
- A config-clear command.
- A new command to enable and disable the theme debug setting.

### Changed
- Call the install script using the PHP_BINARY constant to avoid issues if the
Expand Down
82 changes: 82 additions & 0 deletions commands/theme.bee.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ function theme_bee_command() {
'bee theme-admin basis' => bt('Set Basis as the admin theme.'),
),
),
'theme-debug' => array(
'description' => bt('Enable or disable "Theme debug" for Backdrop.'),
'callback' => 'theme_debug_bee_callback',
'group' => 'themes',
'arguments' => array(
'value' => bt('A boolean value to enable (true/1) or disable (false/0) theme debug. Omitting the value will return the current theme debug status.'),
),
'optional_arguments' => array('value'),
'aliases' => array('td'),
'bootstrap' => BEE_BOOTSTRAP_FULL,
'examples' => array(
'bee theme-debug true' => bt('Enable theme debug for the site (not case-sensitive).'),
'bee theme-debug FALSE' => bt('Disable theme debug for the site (not case-sensitive).'),
'bee theme-debug 1' => bt('Enable theme debug for the site.'),
'bee theme-debug 0' => bt('Disable theme debug for the site.'),
'bee theme-debug' => bt('Get the theme debug status for the site.'),
),
),
);
}

Expand Down Expand Up @@ -101,3 +119,67 @@ function theme_admin_bee_callback($arguments, $options) {
// Flush caches.
backdrop_flush_all_caches();
}

/**
* Command callback: Set the value of theme debug for Backdrop.
*/
function theme_debug_bee_callback($arguments, $options) {
// Check if a value has been provided.
if (isset($arguments['value'])) {
// Check for valid boolean value - allow true/false AND 1/0.
$value = strtoupper($arguments['value']);
switch ($value) {
case 'TRUE':
$value = (bool) TRUE;
break;
case '1':
$value = (bool) TRUE;
break;
case 'FALSE':
$value = (bool) FALSE;
break;
case '0':
$value = (bool) FALSE;
break;
default:
$err_msg = bt("'!value' is not a valid value. Enter 'TRUE', 'FALSE' (not case sensitive), '1' or '0'. Omit providing a value to get the current value.", array (
'!value' => (string) $value,)
);
bee_message((string) $err_msg, 'error');
return;
}
// Check if argument matches existing value.
if ((bool) config_get('system.core', 'theme_debug') == $value) {
$msg = bt('Theme debug is already !value', array(
'!value' => ($value) ? 'enabled' : 'disabled',
));
bee_message((string) $msg, 'status');
}
else {
// Attempt to set maintenance mode.
try {
config_set('system.core', 'theme_debug', $value);
$msg = bt('Theme debug was !value', array(
'!value' => ($value) ? 'enabled' : 'disabled',
));
bee_message((string) $msg, 'success');
}
catch (ParseError $e) {
// This is more readable than the default error we would get from PHP.
$err_msg = bt('!msg in: !value', array(
'!msg' => $e->getMessage(),
'!value' => $arguments['value'],
));
bee_message((string) $err_msg, 'error');
}
}
}
else {
// No value provided - get status.
$value = (bool) config_get('system.core', 'theme_debug');
$msg = bt('Theme debug is !status', array(
'!status' => ($value) ? 'enabled' : 'disabled',
));
bee_message((string) $msg, 'info');
}
}
16 changes: 15 additions & 1 deletion docs/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,21 @@ options in a given file.

*Examples:*
- `bee theme-default bartik` - Set Bartik as the default theme.


#### `theme-debug`
*Description:* Enable or disable "Theme debug" for Backdrop.
*Aliases:*`td`

*Arguments:*
- `value` - (optional) A boolean value to enable (true/1) or disable (false/0) theme debug. Omitting the value will return the current theme debug status.

*Examples:*
- `bee theme-debug true` - Enable theme debug for the site (not case-sensitive).
- `bee theme-debug FALSE` - Disable theme debug for the site (not case-sensitive).
- `bee theme-debug 1` - Enable theme debug for the site.
- `bee theme-debug 0` - Disable theme debug for the site.
- `bee theme-debug` - Get the theme debug status for the site.

### Information
#### `version`
*Description:* Display the current version of Bee.
Expand Down
24 changes: 24 additions & 0 deletions tests/backdrop/ThemeCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,28 @@ public function test_theme_admin_command_works() {
exec('bee theme-admin seven');
}

/**
* Make sure that the theme-debug command works.
*/
public function test_theme_debug_command_works() {
// Attempt to disable theme debug.
$output = shell_exec('bee theme-debug FALSE');
$this->assertStringContainsString('Theme debug is already disabled', (string) $output);

// Enable theme debug.
$output = shell_exec('bee theme-debug TRUE');
$this->assertStringContainsString('Theme debug was enabled', (string) $output);

// Get the status of theme debug.
$output = shell_exec('bee theme-debug');
$this->assertStringContainsString('Theme debug is enabled', (string) $output);

// Disable theme debug.
$output = shell_exec('bee theme-debug FALSE');
$this->assertStringContainsString('Theme debug was disabled', (string) $output);

// Get the status of theme debug.
$output = shell_exec('bee theme-debug');
$this->assertStringContainsString('Theme debug is disabled', (string) $output);
}
}
Loading