Commit 4726739c authored by amitgoyal's avatar amitgoyal Committed by Mateu Aguiló Bosch
Browse files

Issue #2267361 by amitgoyal: Coding Style Issues.

parent b7268c1a
......@@ -44,4 +44,4 @@ function environment_indicator_settings_submit($form, $form_state) {
// Clear admin menu caches.
admin_menu_flush_caches();
}
}
\ No newline at end of file
}
......@@ -10,16 +10,19 @@
*/
function environment_indicator_schema() {
$schema['environment_indicator_environment'] = array(
'description' => t('Table storing preset definitions.'),
'description' => 'Table storing preset definitions.',
'export' => array(
'key' => 'machine',
'key name' => 'Machine name',
'primary key' => 'envid',
'identifier' => 'environment', // Exports will be defined as $environment
'default hook' => 'default_environment_indicator_environment', // Function hook name.
// Exports will be defined as $environment.
'identifier' => 'environment',
// Function hook name.
'default hook' => 'default_environment_indicator_environment',
'api' => array(
'owner' => 'environment_indicator',
'api' => 'default_environment_indicator_environments', // Base name for api include files.
// Base name for api include files.
'api' => 'default_environment_indicator_environments',
'minimum_version' => 1,
'current_version' => 1,
),
......@@ -40,7 +43,8 @@ function environment_indicator_schema() {
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary ID field for the table. Not used for anything except internal lookups.',
'no export' => TRUE, // Do not export database-only keys.
// Do not export database-only keys.
'no export' => TRUE,
),
'regexurl' => array(
'type' => 'varchar',
......@@ -83,16 +87,16 @@ function environment_indicator_uninstall() {
*/
function environment_indicator_requirements($phase) {
$requirements = array();
// Ensure translations don't break at install time
// Ensure translations don't break at install time.
$t = get_t();
// Report Drupal version
// Report Drupal version.
if ($phase == 'runtime') {
if (_environment_indicator_has_old_vars()) {
$requirements['environment_indicator'] = array(
'title' => $t('Environment indicator'),
'value' => $t('You are using old environment indicator variables. Please check the !help on how to upgrade your variables for the new release, and then remove the old ones.', array('!help' => l(t('help pages'), 'admin/help/environment_indicator'))),
'severity' => REQUIREMENT_ERROR
'severity' => REQUIREMENT_ERROR,
);
}
if (
......@@ -128,7 +132,7 @@ function environment_indicator_requirements($phase) {
}
/**
* Add table when updating from 1.x
* Add table when updating from 1.x.
*/
function environment_indicator_update_7200(&$sandbox) {
if (!db_table_exists('environment_indicator_environment')) {
......@@ -183,6 +187,7 @@ function environment_indicator_update_7202(&$sandbox) {
// This variable is no longer used. Remove it.
variable_del($row['name']);
break;
case 'environment_indicator_suppress_pages':
// This variable is still used, keep it.
break;
......
......@@ -11,22 +11,22 @@
function environment_indicator_help($path, $arg) {
switch ($path) {
case 'admin/config/development/environment-indicator':
return t('The Environment Indicator adds a coloured strip to the site informing you which environment you\'re currently in (Development, Staging Production etc). You may override these settings by adding a new environment based on the hostname being seen or with your settings.php file in each of your environments.');
return t("The Environment Indicator adds a coloured strip to the site informing you which environment you're currently in (Development, Staging Production etc). You may override these settings by adding a new environment based on the hostname being seen or with your settings.php file in each of your environments.");
case 'admin/help#environment_indicator':
$output = '<p>' .t('The Environment Indicator adds a coloured strip to the site informing you which environment you\'re currently in (Development, Staging Production etc') .'</p>';
$output = '<p>' . t("The Environment Indicator adds a coloured strip to the site informing you which environment you're currently in (Development, Staging Production etc") . '</p>';
$output .= '<p>'. t('The Environment Indicator <a href="@settings">settings page</a> allows you to modify some elements of the indicator\'s behavior and appearance. Since the appearance of the indicator is dependent on your site theme, substantial customisations require modifications to your site\'s theme and CSS files.', array('@settings' => url('admin/config/development/environment-indicator'))) . '</p>';
$output .= '<p>' . t('The Environment Indicator <a href="@settings">settings page</a> allows you to modify some elements of the indicator\'s behavior and appearance. Since the appearance of the indicator is dependent on your site theme, substantial customisations require modifications to your site\'s theme and CSS files.', array('@settings' => url('admin/config/development/environment-indicator'))) . '</p>';
$output .= '<p>'. t('The Environment Indicator\'s visibility depends upon the permissions of the viewer. The <a href="@permissions">access environment indicator</a> permission must be enabled for a user role in order for users of that role to see the indicator.', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-environment_indicator')))) .'</p>';
$output .= '<p>' . t('The Environment Indicator\'s visibility depends upon the permissions of the viewer. The <a href="@permissions">access environment indicator</a> permission must be enabled for a user role in order for users of that role to see the indicator.', array('@permissions' => url('admin/people/permissions', array('fragment' => 'module-environment_indicator')))) . '</p>';
$output .= '<p>'. t('The settings for the Environment Indicator, such as the text to display and the color can be overridden for each of your specific environments using the configuration UI or in the site\'s settings.php file. You can also export this configuration to code, this allows you to customise the indicator for each environment without needing to make any changes in the database. This means that the Environment Indicator will always display correctly when moving your site from development to staging to production. If you choose to detect your environment using settings.php, then all configuration variables can be overridden in settings.php, but the most common three are:') .'</p>';
$output .= '<p>' . t("The settings for the Environment Indicator, such as the text to display and the color can be overridden for each of your specific environments using the configuration UI or in the site's settings.php file. You can also export this configuration to code, this allows you to customise the indicator for each environment without needing to make any changes in the database. This means that the Environment Indicator will always display correctly when moving your site from development to staging to production. If you choose to detect your environment using settings.php, then all configuration variables can be overridden in settings.php, but the most common three are:") . '</p>';
$output .= '<dl>';
$output .= '<dt><em>environment_indicator_overwrite</em></dt><dd>'. t('A boolean value indicating whether the Environment Indicator should use the settings.php variables for the indicator. On your production environment, you should probably set this to FALSE.') . '<br/>$conf[\'environment_indicator_overwrite\'] = FALSE;<br />* ' . t('This setting corresponds to the old %setting in version 1.x.', array('%setting' => 'environment_indicator_enabled')) . '</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_name</em></dt><dd>'. t('The text that will be displayed on the indicator.') . '<br/>$conf[\'environment_indicator_overwritten_name\'] = \'Staging\';<br />* ' . t('This setting corresponds to the old %setting in version 1.x.', array('%setting' => 'environment_indicator_text')) . '</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_color</em></dt><dd>'. t('A valid css color.') . '<br/>$conf[\'environment_indicator_overwritten_color\'] = \'#ff5555\';<br />* ' . t('This setting corresponds to the old %setting in version 1.x.', array('%setting' => 'environment_indicator_color')) . '</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_position</em></dt><dd>'. t('Where your indicator may appear. Allowed values are "top" and "bottom".') . '<br/>$conf[\'environment_indicator_overwritten_position\'] = \'top\';</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_fixed</em></dt><dd>'. t('A boolean value indicating whether the Environment Indicator should be visible at all times, fixed at the top/bottom of the screen.') . '<br/>$conf[\'environment_indicator_overwritten_fixed\'] = FALSE;</dd></dt>';
$output .= '<dt><em>environment_indicator_overwrite</em></dt><dd>' . t('A boolean value indicating whether the Environment Indicator should use the settings.php variables for the indicator. On your production environment, you should probably set this to FALSE.') . '<br/>$conf[\'environment_indicator_overwrite\'] = FALSE;<br />* ' . t('This setting corresponds to the old %setting in version 1.x.', array('%setting' => 'environment_indicator_enabled')) . '</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_name</em></dt><dd>' . t('The text that will be displayed on the indicator.') . '<br/>$conf[\'environment_indicator_overwritten_name\'] = \'Staging\';<br />* ' . t('This setting corresponds to the old %setting in version 1.x.', array('%setting' => 'environment_indicator_text')) . '</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_color</em></dt><dd>' . t('A valid css color.') . '<br/>$conf[\'environment_indicator_overwritten_color\'] = \'#ff5555\';<br />* ' . t('This setting corresponds to the old %setting in version 1.x.', array('%setting' => 'environment_indicator_color')) . '</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_position</em></dt><dd>' . t('Where your indicator may appear. Allowed values are "top" and "bottom".') . '<br/>$conf[\'environment_indicator_overwritten_position\'] = \'top\';</dd></dt>';
$output .= '<dt><em>environment_indicator_overwritten_fixed</em></dt><dd>' . t('A boolean value indicating whether the Environment Indicator should be visible at all times, fixed at the top/bottom of the screen.') . '<br/>$conf[\'environment_indicator_overwritten_fixed\'] = FALSE;</dd></dt>';
$output .= '</dl>';
return $output;
......@@ -44,7 +44,7 @@ function environment_indicator_menu() {
'page arguments' => array('environment_indicator_settings'),
'access arguments' => array('administer environment indicator settings'),
'type' => MENU_LOCAL_TASK,
'file' =>'environment_indicator.admin.inc',
'file' => 'environment_indicator.admin.inc',
);
return $items;
}
......@@ -54,11 +54,11 @@ function environment_indicator_menu() {
*/
function environment_indicator_permission() {
$permissons = array(
'administer environment indicator settings' => array(
'administer environment indicator settings' => array(
'title' => t('Administer environment_indicator settings'),
'description' => t('Configure the environments and the colors to display.'),
),
'access environment indicator' => array(
'access environment indicator' => array(
'title' => t('See environment indicator'),
'description' => t('See all the environment indicators in the site.'),
),
......@@ -93,12 +93,18 @@ function environment_indicator_ctools_plugin_api($owner, $api) {
function environment_indicator_default_environment_indicator_environment() {
$export = array();
$environment = new stdClass;
$environment = new stdClass();
$environment->api_version = 1;
$environment->machine = 'default_environment';
$environment->name = t('Default environment');
$environment->regexurl = '.*';
$environment->settings = array('color' => '#aa3333', 'text_color' => '#ffffff', 'weight' => 99, 'position' => 'top', 'fixed' => FALSE);
$environment->settings = array(
'color' => '#aa3333',
'text_color' => '#ffffff',
'weight' => 99,
'position' => 'top',
'fixed' => FALSE,
);
$export['default_environment'] = $environment;
return $export;
......@@ -109,13 +115,13 @@ function environment_indicator_default_environment_indicator_environment() {
*/
function environment_indicator_ctools_plugin_directory($module, $type) {
// Load the export_ui plugin.
if ($type =='export_ui') {
if ($type == 'export_ui') {
return 'plugins/export_ui';
}
}
/**
* System settings form
* System settings form.
*/
function environment_indicator_ui_form(&$form, &$form_state) {
$environment = $form_state['item'];
......@@ -138,7 +144,7 @@ function environment_indicator_ui_form(&$form, &$form_state) {
'#title' => t('Name'),
'#description' => t('Name for this environment.'),
'#default_value' => $environment->name,
'#id' => 'name'
'#id' => 'name',
);
$form['machine'] = array(
'#title' => t('Machine name'),
......@@ -174,19 +180,19 @@ function environment_indicator_ui_form(&$form, &$form_state) {
),
);
$form['text_color_picker'] = array(
'#markup' => '<div id="environment-indicator-text-color-picker"></div>',
'#markup' => '<div id="environment-indicator-text-color-picker"></div>',
);
$form['text_color'] = array(
'#type' => 'textfield',
'#title' => t('Text Color'),
'#description' => t('Text Color for the indicator. Ex: #ffffff.'),
'#default_value' => $environment->text_color ? $environment->text_color : '#ffffff',
'#attached' => array(
// Add Farbtastic color picker.
'library' => array(
array('system', 'farbtastic'),
),
'#type' => 'textfield',
'#title' => t('Text Color'),
'#description' => t('Text Color for the indicator. Ex: #ffffff.'),
'#default_value' => $environment->text_color ? $environment->text_color : '#ffffff',
'#attached' => array(
// Add Farbtastic color picker.
'library' => array(
array('system', 'farbtastic'),
),
),
);
$form['weight'] = array(
'#type' => 'textfield',
......@@ -244,7 +250,8 @@ function environment_indicator_ui_form_submit(&$form, &$form_state) {
'fixed' => $form_state['values']['fixed'],
);
// We need to flush admin_menu cache so that the new indicator shows up properly.
// We need to flush admin_menu module cache so that the new indicator shows
// up properly.
$integrations = variable_get('environment_indicator_integration', array('toolbar' => 'toolbar', 'admin_menu' => 'admin_menu'));
if (module_exists('admin_menu') && user_access('access administration menu') && !empty($integrations['admin_menu'])) {
admin_menu_flush_caches();
......@@ -270,7 +277,8 @@ function environment_indicator_page_build(&$page) {
$js_settings = array(
'environment_indicator' => array(
'addFavicon' => TRUE,
'faviconLabel' => $match['name'][0], // Get the first letter out of the name.
// Get the first letter out of the name.
'faviconLabel' => $match['name'][0],
'faviconColor' => $match['color'],
'faviconTextColor' => $match['text_color'],
),
......@@ -364,7 +372,8 @@ function environment_indicator_get_active() {
$environments = environment_indicator_get_all();
$matches = array();
foreach ($environments as $machine => $environment) {
// Check if the environment record has been disabled. Then check the regex.
// Check if the environment record has been disabled.
// Then check the regex.
if (preg_match("/$environment->regexurl/", $_SERVER['HTTP_HOST'])) {
$settings = $environment->settings;
$matches[] = array(
......@@ -396,10 +405,11 @@ function environment_indicator_get_active() {
* Helper function to get all environments.
*
* @param bool $fixed
* (optional) If TRUE it will only return fixed environments. Fixed environments are
* those that do not use a regular expression for detection.
* (optional) If TRUE it will only return fixed environments. Fixed
* environments are those that do not use a regular expression for detection.
*
* @return array
* Returns all the environments.
*/
function environment_indicator_get_all($fixed = FALSE) {
module_load_include('inc', 'ctools', 'includes/export');
......@@ -412,7 +422,7 @@ function environment_indicator_get_all($fixed = FALSE) {
/**
* Helper function to check access to show the indicator.
*
* @param array
* @param array $environment_info
* The environment info array.
*
* @return bool
......@@ -509,7 +519,7 @@ function environment_indicator_environment_indicator_matched_indicator_alter(&$e
// The first line of the .git/HEAD file contains a reference to the branch
// in a string like: ref: refs/heads/[branch]
$git_head_file = file($git_path . '/.git/HEAD', FILE_USE_INCLUDE_PATH);
list(,,$branch_name) = explode('/', reset($git_head_file));
list(, , $branch_name) = explode('/', reset($git_head_file));
if (!empty($branch_name)) {
$environment_info['git_branch'] = $branch_name;
}
......@@ -528,7 +538,7 @@ function environment_indicator_environment_indicator_matched_indicator_alter(&$e
}
/**
* Determines if a command exists on the current environment
* Determines if a command exists on the current environment.
*
* @param string $command
* The command to check.
......@@ -536,18 +546,21 @@ function environment_indicator_environment_indicator_matched_indicator_alter(&$e
* @return bool
* TRUE if the command has been found; otherwise, FALSE.
*/
function command_exists ($command) {
function command_exists($command) {
if ($obj = cache_get('command_exists:' . $command)) {
return $obj->data;
}
$whereIsCommand = (PHP_OS == 'WINNT') ? 'where' : 'which';
$where_is_command = (PHP_OS == 'WINNT') ? 'where' : 'which';
$process = proc_open(
"$whereIsCommand $command",
"$where_is_command $command",
array(
0 => array("pipe", "r"), //STDIN
1 => array("pipe", "w"), //STDOUT
2 => array("pipe", "w"), //STDERR
// STDIN.
0 => array("pipe", "r"),
// STDOUT.
1 => array("pipe", "w"),
// STDERR.
2 => array("pipe", "w"),
),
$pipes
);
......@@ -568,8 +581,7 @@ function command_exists ($command) {
}
/**
* Helper function to determine if the Acquia post deploy hook is has been
* installed.
* Helper function to determine if the Acquia post deploy hook is installed.
*
* @param string $env
* String containing the name of the environment as declared in the drush
......
......@@ -8,7 +8,6 @@
/**
* Theme function for listing environments.
*/
function theme_environment_indicator_switches($variables) {
$items = $variables['switches'];
$output = '<div class="item-list"><ul class="environment-switcher-container">';
......@@ -77,7 +76,7 @@ function theme_environment_indicator_indicator_bar($variables) {
}
/**
* Theme function for the overriden environment indicator in the header of the list.
* Theme function for overriden environment indicator in the header of the list.
*/
function theme_environment_indicator_overwritten_header($variables) {
$header = '<div class="overriden-indicator"><h2 class="label">' . t('Overriden indicator.') . '</h2>';
......
......@@ -24,10 +24,10 @@ function environment_indicator_variable_info() {
);
$variables['environment_indicator_overwritten_text_color'] = array(
'title' => t('Color'),
'description' => t('Text color for the indicator. Ex: #ffffff.'),
'default' => '#ffffff',
'group' => 'environment_indicator',
'title' => t('Color'),
'description' => t('Text color for the indicator. Ex: #ffffff.'),
'default' => '#ffffff',
'group' => 'environment_indicator',
);
$variables['environment_indicator_overwritten_fixed'] = array(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment