Skip to content
Browse files

Form tweak renamed and committed.

  • Loading branch information...
1 parent 47c1a92 commit c53a019ca108ee89e15a3588e6ee6f485be0ac26 @mlncn committed Jun 15, 2009
View
6 modules/custom/form_tweak/form_tweak.info
@@ -1,6 +0,0 @@
-; $Id$
-name = Form tweak
-description = Make lots of useful little modifications to Drupal form pages.
-core = 6.x
-package = User interface
-
View
45 modules/custom/form_tweak/form_tweak_ui.admin.inc
@@ -1,45 +0,0 @@
-<?php
-
-/**
- * @file
- * Having a file that loaded only for people who have permission to tweak
- * forms didn't do anything getting included within a form_tweak_form_alter,
- * and since everything can be edited in config files anyway, it made a lot of
- * sense to make the user interface for tweaking forms a separate module.
- *
- * But we will still have most of that module only load for privileged users.
- */
-
-/**
- * Implementation of hook_help().
- */
-function form_tweak_ui_help($path) {
- switch ($path) {
- case 'admin/help#form_tweak_ui':
- return '<p>' . t('Form tweak offers the following ') . '</p>';
- }
-}
-
-/**
- * Implementation of hook_form_alter().
- */
-function form_tweak_ui_form_alter(&$form, &$form_state, $form_id) {
- if (isset($form['type']) && isset($form['#node'])
- && ($form_id == $form['type']['#value'] .'_node_form')
- ) {
- // we are on a node edit or add form
- ///////////////////////////////////////////////////
- // Rename any submit buttons, default for all forms.
- // leave out translation for now
- ///////////////////////////////////////////////////
- $buttons = fs_variables_load('form_tweak', 'buttons');
- drupal_set_message('<pre>'.var_export($buttons,TRUE).'</pre>');
- foreach ($buttons as $button => $value) {
- if (isset($form['buttons'][$button])) {
- $form['buttons'][$button]['#value'] = $value;
- }
- }
- }
- //
-}
-
View
6 modules/custom/form_tweak/form_tweak_ui.info
@@ -1,6 +0,0 @@
-; $Id$
-name = Form tweak administrative user interface
-description = Configure tweaks to Drupal form pages through the web interface.
-core = 6.x
-package = User interface
-
View
5 modules/custom/formtweak/config/formtweak.ini
@@ -0,0 +1,5 @@
+; Show a "Save and edit" submit button before the regular submit on node forms
+save_and_edit_button = TRUE
+save_and_edit_button_exclude[] = profile
+; initialization file for File-based Settings configuration
+suppress_messages = FALSE
View
6 modules/custom/formtweak/formtweak.info
@@ -0,0 +1,6 @@
+; $Id$
+name = Form tweak
+description = [formtweak] Make lots of useful little modifications to Drupal form pages.
+core = 6.x
+package = User interface
+
View
6 modules/custom/form_tweak/form_tweak.install → modules/custom/formtweak/formtweak.install
@@ -9,8 +9,8 @@
/**
* Implementation of hook_install().
*/
-function form_tweak_install() {
- $success = db_query("UPDATE {system} SET weight = 25 WHERE name = 'form_tweak'");
+function formtweak_install() {
+ $success = db_query("UPDATE {system} SET weight = 25 WHERE name = 'formtweak'");
if ($success) {
drupal_set_message(st('Form tweak module installed.'));
}
@@ -22,7 +22,7 @@ function form_tweak_install() {
/**
* Implementation of hook_uninstall().
*/
-function form_tweak_uninstall() {
+function formtweak_uninstall() {
// $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'author_field_%'");
// while ($row = db_fetch_object($result)) {
// variable_del($row->name);
View
57 modules/custom/form_tweak/form_tweak.module → modules/custom/formtweak/formtweak.module
@@ -9,36 +9,37 @@
/**
* Implementation of hook_help().
*/
-function form_tweak_help($path) {
+function formtweak_help($path) {
switch ($path) {
- case 'admin/help#form_tweak':
+ case 'admin/help#formtweak':
return '<p>' . t('Form tweak offers the following ') . '</p>';
}
}
/**
- * Implementation of hook_perm().
- */
-function form_tweak_perm() {
- return array('tweak forms');
-}
-
-/**
* Implementation of hook_form_alter().
*/
-function form_tweak_form_alter(&$form, &$form_state, $form_id) {
+function formtweak_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['type']) && isset($form['#node'])
&& ($form_id == $form['type']['#value'] .'_node_form')
) {
// we are on a node edit or add form
- if (fs_variable_get('form_tweak', 'save_and_edit_button')) {
- form_tweak_save_and_edit_button(&$form, &$form_state, $form_id);
+ if (fs_variable_get('formtweak', 'save_and_edit_button')) {
+ $run = TRUE;
+ if (is_array($saeb = fs_variable_get('formtweak', 'save_and_edit_button_exclude'))) {
+ if (in_array($form['type']['#value'], $saeb)) {
+ $run = FALSE;
+ }
+ }
+ if ($run) {
+ formtweak_save_and_edit_button(&$form, &$form_state, $form_id);
+ }
}
///////////////////////////////////////////////////
// Rename any submit buttons, default for all forms.
// leave out translation for now
///////////////////////////////////////////////////
- $buttons = fs_variables_load('form_tweak', 'buttons');
+ $buttons = fs_variables_load('formtweak', 'buttons');
foreach ($buttons as $button => $value) {
if (isset($form['buttons'][$button])) {
$form['buttons'][$button]['#value'] = $value;
@@ -50,7 +51,7 @@ function form_tweak_form_alter(&$form, &$form_state, $form_id) {
/**
* Implementation of hook_form_FORM_ID_alter() for node.
*/
-// function form_tweak_form_node_type_form_alter(&$form, &$form_state) {
+// function formtweak_form_node_type_form_alter(&$form, &$form_state) {
// }
/**
@@ -59,7 +60,7 @@ function form_tweak_form_alter(&$form, &$form_state, $form_id) {
* This is a sub-implementation of hook_form_alter() and could be moved to a
* conditionally included file to reduce memory load.
*/
-function form_tweak_save_and_edit_button(&$form, &$form_state, $form_id) {
+function formtweak_save_and_edit_button(&$form, &$form_state, $form_id) {
// modeled on modules/node/node.pages.inc $form['buttons']['submit']
$form['buttons']['save_and_edit'] = array(
'#type' => 'submit',
@@ -68,15 +69,15 @@ function form_tweak_save_and_edit_button(&$form, &$form_state, $form_id) {
'#weight' => 4,
'#submit' => array(
'node_form_submit',
- 'form_tweak_save_and_edit_submit',
+ 'formtweak_save_and_edit_submit',
),
);
}
/**
* Called by our Save and edit button, this modifies the redirect to add /edit.
*/
-function form_tweak_save_and_edit_submit($form, &$form_state) {
+function formtweak_save_and_edit_submit($form, &$form_state) {
$old_redirect = $form_state['redirect'];
// if statement is probably unnecessary check
if (substr($old_redirect, 0, 4) == 'node') {
@@ -101,7 +102,7 @@ function form_tweak_save_and_edit_submit($form, &$form_state) {
* To call all variables associated with a module each category must be
* requested separately.
*
- * In short, use of module_name.ini will be analogous to using settings.php
+ * In short, use of module_name.ini will be analogous to using variables table
* (albeit with the welcomed-by-everyone requirement of module namespacing).
* Use of module_name.category.ini will be analogous to using a custom
* database table to hold settings for your module.
@@ -119,6 +120,9 @@ function fs_variables_load($module, $category = '', $reset = FALSE) {
fs_parse_ini_file($path)
);
}
+ if (!isset($variables[$module][$category])) {
+ $variables[$module][$category] = array();
+ }
}
return $variables[$module][$category];
}
@@ -263,9 +267,24 @@ function fs_variable_get($module, $name, $category = '', $reset = FALSE) {
}
else {
$msg = t("No default defined for configuration variable %name in module %module", array('%name' => $name, '%module' => $module));
- if (!fs_variable_get('form_tweak', 'suppress_messages')) { // @TODO change to fs when we split the modules
+ if (!fs_suppress_messages()) {
drupal_set_message($msg, 'warning');
}
watchdog('fs', $msg, NULL, WATCHDOG_WARNING);
}
}
+
+/**
+ * Check if suppress_messages is set TRUE or FALSE. Default to FALSE.
+ *
+ * The suppress_messages variable is used inside fs_variable_get, and
+ * therefore cannot be used
+ */
+function fs_suppress_messages() {
+ $ret = FALSE;
+ $vars = fs_variables_load('formtweak');
+ if (isset($vars['suppress_messages'])) {
+ $ret = $vars['suppress_messages'];
+ }
+ return $ret;
+}
View
44 modules/custom/formtweak/formtweakui.admin.inc
@@ -0,0 +1,44 @@
+<?php
+
+/**
+ * @file
+ * Having a file that loaded only for people who have permission to tweak
+ * forms didn't do anything getting included within a form_tweak_form_alter,
+ * and since everything can be edited in config files anyway, it made a lot of
+ * sense to make the user interface for tweaking forms a separate module.
+ *
+ * But we will still have most of that module only load for privileged users.
+ */
+
+/**
+ * Implementation of hook_menu().
+ */
+function formtweakui_menu() {
+ $items = array();
+ $items['admin/settings/formtweak'] = array(
+ 'title' => t('Form tweak configuration'),
+ 'description' => t('Tweak your forms'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('fs_raw_config_form', 'form_tweak', ''),
+ 'access arguments' => array('tweak forms'),
+ 'type' => MENU_CALLBACK,
+ );
+}
+
+/**
+ * Implementation of hook_form_alter().
+ */
+function formtweakui_form_alter(&$form, &$form_state, $form_id) {
+ if (isset($form['type']) && isset($form['#node'])
+ && ($form_id == $form['type']['#value'] .'_node_form')
+ ) {
+ // we are on a node edit or add form
+ $buttons = $form['buttons'];
+ drupal_set_message('<pre>'.var_export($form,TRUE).'</pre>');
+ foreach ($buttons as $button => $value) {
+ // $name = $value['#value'];
+ $form['buttons'][$button]['#prefix'] = $button;
+ }
+ }
+ //
+}
View
6 modules/custom/formtweak/formtweakui.info
@@ -0,0 +1,6 @@
+; $Id$
+name = Form tweak administrative user interface
+description = "[formtweakui] Configure tweaks to Drupal form pages through the web interface."
+core = 6.x
+package = User interface
+
View
8 ...s/custom/form_tweak/form_tweak_ui.install → modules/custom/formtweak/formtweakui.install
@@ -9,13 +9,13 @@
/**
* Implementation of hook_install().
*/
-function form_tweak_ui_install() {
- $success = db_query("UPDATE {system} SET weight = 25 WHERE name = 'form_tweak_ui'");
+function formtweakui_install() {
+ $success = db_query("UPDATE {system} SET weight = 25 WHERE name = 'formtweakui'");
if ($success) {
drupal_set_message(
st('Form tweak user interface module installed. Tweak forms inline or
<a href="@url">edit configuration files</a>',
- array('@url' => url('admin/settings/form_tweak')))
+ array('@url' => url('admin/settings/formtweak')))
);
}
else {
@@ -26,7 +26,7 @@ function form_tweak_ui_install() {
/**
* Implementation of hook_uninstall().
*/
-function form_tweak_ui_uninstall() {
+function formtweakui_uninstall() {
drupal_set_message(t('Form tweak user interface module has been uninstalled.'));
}
View
4 ...es/custom/form_tweak/form_tweak_ui.module → modules/custom/formtweak/formtweakui.module
@@ -13,10 +13,10 @@
/**
* Implementation of hook_perm().
*/
-function form_tweak_ui_perm() {
+function formtweakui_perm() {
return array('tweak forms');
}
if (user_access('tweak forms')) {
- module_load_include('inc', 'form_tweak', 'form_tweak_ui.admin');
+ module_load_include('inc', 'formtweak', 'formtweakui.admin');
}

0 comments on commit c53a019

Please sign in to comment.
Something went wrong with that request. Please try again.