Commit 1a5edcb0 authored by young hahn's avatar young hahn
Browse files

Merge from DRUPAL-6--2.

parent 3e0f113c
$Id$
Strongarm 2.x for Drupal 7.x
----------------------------
Strongarm gives site builders a way to override the default variable values that
Drupal core and contributed modules ship with. It is not an end user tool, but a
developer and site builder tool which provides an API and a limited UI.
An example of such a variable is `site_frontpage`. In Drupal this defaults to
`node`, which ensures that the front page gets content as soon as some exists,
but for many Drupal sites this setting is simply wrong. Strongarm gives the site
builder a place in the equation - an opportunity to set the default value of
`site_frontpage` to something that makes sense for their site.
Installation
------------
Strongarm can be installed like any other Drupal module -- place it in
the modules directory for your site and enable it (and its requirement,
CTools) on the `admin/build/modules` page.
Strongarm is an API module. It does absolutely nothing for the end user out of
the box without other modules that take advantage of its API.
How Strongarm works
-------------------
Strongarm uses the CTools export API to make entries in the system module's
`variable` table exportables. Exportables are Drupal configuration objects that
lead a dual life -- they may be *defaults* set by code exports in modules, they
may be *overridden* if a user chooses to change the value in the database, or
they may be *normal* if the configuration object lives only in the database but
not in code. To learn more about exportables and the CTools export API, see the
CTools advanced help on "Exportable objects tool."
Exporting variables
-------------------
If you are a developer or site builder Strongarm gives you tools to export the
settings of variables in your site database and manage any overrides to default
values.
To export variable values, you will need to enable either the [Features][1]
module or the [Bulk Export][2] module provided by CTools (as of June 29, 2010
you must use a recent checkout CTools `DRUPAL-6--1` in order to use Bulk Export
with Strongarm). Features provides a UI for adding variable exports to a
feature. Bulk Export provides a UI for generating defaults hooks with exported
variables that you can add to your own modules. You do not need to enable both
modules.
Maintainers
-----------
- jmiccolis (Jeff Miccolis)
- yhahn (Young Hahn)
[1]: http://drupal.org/project/features
[2]: http://drupal.org/project/ctools
<?php
// $Id$
/**
* Get a map of variable to culprit (implementers of hook_strongarm()).
*/
function strongarm_get_culprits() {
$culprits = array();
foreach (module_implements('strongarm') as $module) {
$module_conf = module_invoke($module, 'strongarm');
foreach ($module_conf as $name => $value) {
$culprits[$name] = $module;
}
}
return $culprits;
}
/**
* Variable management strongarm form.
*/
function strongarm_admin_form($form, $form_state) {
function strongarm_admin_form($form_state) {
global $conf;
ctools_include('export');
$vars = ctools_export_load_object('variable');
ksort($vars);
$vars = strongarm_vars_load(TRUE, TRUE);
$form = array('#theme' => 'strongarm_admin_form',);
foreach ($vars as $name => $variable) {
if ($variable->export_type & EXPORT_IN_CODE) {
$default = ctools_get_default_object('variable', $name);
// If variable value does not match global $conf, this value has been
// hardcoded (e.g. in settings.php) and has been allowed to pass
// through. It cannot be reverted.
......@@ -46,15 +30,9 @@ function strongarm_admin_form($form, $form_state) {
$form['revert']['#tree'] = TRUE;
$form['revert'][$name] = array('#type' => 'checkbox');
}
$form['name'][$name] = array(
'#markup' => $name,
);
$form['storage'][$name] = array(
'#markup' => $storage,
);
$form['value'][$name] = array(
'#markup' => check_plain(_strongarm_readable($variable->value)),
);
$form['name'][$name] = array('#markup' => $name);
$form['storage'][$name] = array('#markup' => $storage);
$form['value'][$name] = array('#markup' => check_plain(_strongarm_readable($variable->value)));
}
}
if (!empty($form['revert'])) {
......
; $Id$
name = "Strongarm"
description = "Enforces variable values defined by modules that need settings set to operate properly."
name = Strongarm
description = Enforces variable values defined by modules that need settings set to operate properly.
core = 7.x
dependencies[] = "ctools"
dependencies[] = ctools
files[] = strongarm.admin.inc
files[] = strongarm.install
......
......@@ -4,7 +4,6 @@
/**
* @file
* Install, update and uninstall functions for the strongarm module.
*
*/
/**
......@@ -13,12 +12,10 @@
function strongarm_enable() {
// Weight strongarm exceptionally light.
db_update('system')
->fields(array(
'weight' => -1000,
))
->fields(array('weight' => -1000))
->condition('name', 'strongarm')
->condition('type', 'module')
->execute();
->execute();
}
/**
......@@ -35,7 +32,7 @@ function strongarm_update_6100() {
*/
function strongarm_update_6200() {
drupal_install_modules(array('ctools'));
$modules = module_implements($hook /* TODO Set this variable. */);
$modules = module_list();
if (!isset($modules['ctools'])) {
return array('#abort' => array('success' => FALSE, 'query' => 'Could not enable CTools.'));
}
......@@ -51,7 +48,7 @@ function strongarm_update_6201() {
foreach ($modules as $module) {
$variables = module_invoke($module, 'strongarm');
foreach ($variables as $variable => $value) {
$exists = db_query("SELECT name FROM {variable} WHERE name = :name", array(':name' => $variable))->fetchField();
$exists = db_result(db_query("SELECT name FROM {variable} WHERE name = '%s'", $variable));
if (!$exists && !(is_object($value) && isset($value->api_version))) {
variable_set($variable, $value);
$ret[] = array('success' => TRUE, 'query' => "Set 1.x strongarmed variable {$variable} in the database.");
......
......@@ -5,16 +5,16 @@
* Implements hook_init().
*/
function strongarm_init() {
strongarm_set_conf(TRUE);
strongarm_set_conf();
// This is a workaround for the very early check of the 'site_frontpage'
// variable in the Drupal bootstrap process. The workaround re-runs
// drupal_init_path() to ensure the strongarm'ed version of
// drupal_path_initialize() to ensure the strongarm'ed version of
// 'site_frontpage' is used. Note that this may be too late if other modules
// weighted even lower than strongarm (which is a superlightweight -1000)
// rely on $_GET['q'] or 'site_frontpage' in hook_init().
//$_GET['q'] = strongarm_language_strip($_REQUEST['q']);
//drupal_path_initialize();
$_GET['q'] = request_path();
drupal_path_initialize();
}
/**
......@@ -30,47 +30,22 @@ function strongarm_set_conf($reset = FALSE) {
$var_conf = $cache->data;
}
else {
// Ensure that the schema cache is not stale when we init.
$schema = drupal_get_schema('variable');
if (!isset($schema['export'])) {
drupal_get_schema('variable', TRUE);
}
$var_conf = array();
ctools_include('export');
foreach (ctools_export_load_object('variable') as $var) {
foreach (strongarm_vars_load(FALSE, TRUE) as $var) {
$var_conf[$var->name] = $var->value;
}
cache_set('strongarm', $var_conf);
}
global $conf;
$conf = array_merge($var_conf, $conf);
}
/**
* Remove the language prefix for a given path.
* Strongarm implements this itself as language_initialize() directly affects
* $_GET['q'] and cannot be reused.
*/
function strongarm_language_strip($path) {
// Configured presentation language mode.
$mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
// Get a list of enabled languages.
$languages = language_list('enabled');
$languages = $languages[1];
if (in_array($mode, array(LANGUAGE_NEGOTIATION_PATH_DEFAULT, LANGUAGE_NEGOTIATION_PATH))) {
$args = explode('/', $path);
$prefix = array_shift($args);
// Search prefix within enabled languages.
foreach ($languages as $language) {
if (!empty($language->prefix) && $language->prefix == $prefix) {
return implode('/', $args);
}
}
// Store the original variable values. This allows additional calls to
// strongarm_set_conf() to properly set Strongarm values.
static $original_conf;
if (!isset($original_conf)) {
$original_conf = $conf;
}
return $path;
$conf = array_merge($var_conf, $original_conf);
}
/**
......@@ -140,7 +115,44 @@ function strongarm_schema_alter(&$schema) {
}
/**
* Implementation of hook_features_revert().
* Implementation hook_help().
*/
function strongarm_help($path, $arg) {
switch ($path) {
case 'admin/help#strongarm':
$output = file_get_contents(drupal_get_path('module', 'strongarm') .'/README.txt');
return module_exists('markdown') ? filter_xss_admin(module_invoke('markdown', 'filter', 'process', 0, -1, $output)) : '<pre>'. check_plain($output) .'</pre>';
case 'admin/settings/strongarm':
return '<p>'. t("Strongarm lets site builders manage default variable settings. All the default values provided by Strongarm are listed on this page. Any overridden value can be reverted to its default by selecting its checkbox and clicking 'Reset to defaults'.") .'</p>';
}
}
/**
* Load all variables (DB and Strongarmed).
*/
function strongarm_vars_load($sorted = TRUE, $reset = FALSE) {
ctools_include('export');
static $vars;
// Ensure that the schema cache is not stale when trying to load.
$schema = drupal_get_schema('variable');
if (!isset($schema['export']) || $reset) {
ctools_export_load_object_reset('variable');
drupal_get_schema('variable', TRUE);
}
// Load vars.
if (!isset($vars) || $reset) {
$vars = ctools_export_load_object('variable');
if ($sorted) {
ksort($vars);
}
}
return $vars;
}
/**
* Implements hook_features_revert().
*/
if (!function_exists('variable_features_revert')) {
function variable_features_revert($module) {
......@@ -148,3 +160,31 @@ if (!function_exists('variable_features_revert')) {
cache_clear_all('variables', 'cache');
}
}
/**
* Implements hook_features_pipe_alter() for node component.
* Add node type variables on behalf of core modules.
*/
function strongarm_features_pipe_node_alter(&$pipe, $data, $export, $module_name) {
if (!empty($data)) {
$variables = array(
'comment',
'comment_anonymous',
'comment_controls',
'comment_default_mode',
'comment_default_order',
'comment_default_per_page',
'comment_form_location',
'comment_preview',
'comment_subject_field',
'language_content_type',
'node_options',
'upload',
);
foreach ($data as $node_type) {
foreach ($variables as $variable_name) {
$pipe['variable'][] = "{$variable_name}_{$node_type}";
}
}
}
}
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