It would be great if we could control where Form Tooltip is applied. I love that it's working when people create or edit content, but I don't like it when it's showing up when I'm trying to get around the administration area. It's especially hard to get around the modules page now. My two cents! Thanks!

CommentFileSizeAuthor
#9 form_tooltips.zip11.26 KBsinasquax

Comments

entrigan’s picture

: ) you are right. This is my first module, and it amazing how something that works perfectly for your own personal needs can be wrong in so many ways when applied in a general sense.

Ok so my question is, until I can build a admin-interface (I do not think I will have time until perhaps the end of the month) what forms should have the tooltips applied? It could grab only forms not on admin pages. Or possibly only node add / node edit forms (that is how it used to be).

What do you think?

entrigan’s picture

So rather than change where the tooltips are applied I have reduced the cases they get applied to so that it only happens for things that look like form item containers (not always a black and white question). This means it no longer applies to the modules page, but will still apply to something like the add vocabulary page.

This also means it will not apply to *any* thing you put a description tag on.

Sorry for the obvious bugs, I think I was a little hasty with the 1.0 release, but either way thanks for the help, I think we have it pretty close to working now.

entrigan’s picture

Assigned: Unassigned » entrigan
TheAlienShore’s picture

I would say it would be good for pretty much anything public facing. For my case, I'd like it to only apply on node add or edit forms. Other people may feel differently, but that's what would work for the site I'm currently building.

sinasquax’s picture

It's a great module but it could be greater if you add an admin page with a textarea where we can write the form name where this module should apply to.

sinasquax’s picture

Hello, i have implemented a little administration page for this module, you can choose which forms will have tooltips :

Create a form_tooltips.install and put this code :

// $Id$

/**
 * @file
 * Installation file for form_tooltips module.
 */

/**
 * Implementation of hook uninstall.
 */
function form_tooltips_uninstall() {
  // Remove variables
  variable_del('form_tooltips_scope');
  variable_del('form_tooltips_forms');
}
// Remove the PHP end tag

Create a form_tooltips.admin.inc and put this code :

// $Id: form_tooltips.admin.inc

/**
 * Administration form
 *
 * @ingroup forms
 * @see form_tooltips_admin_form_validate()
 * @see form_tooltips_admin_form_submit()
 */
function form_tooltips_admin_settings() {
   // Add tooltips options
  $form['visibility'] = array(
    '#type' => 'fieldset',
	'#title' => t('Visibility options'),
	'#collapsible' => TRUE,
	'#collapsed' => FALSE,
  );
  
  $form['visibility']['form_tooltips_scope'] = array(
	'#type' => 'radios',
	'#title' => t('Show tooltips on specific forms'),
	'#options' => array(
	  t('Show on every form except the listed forms.'),
	  t('Show on only the listed forms.'),
	),
	'#default_value' => variable_get('form_tooltips_scope', 0),
  );
  
  $form['visibility']['form_tooltips_forms'] = array(
    '#type' => 'textarea',
    '#title' => t('Forms which have tooltips'),
    '#default_value' => variable_get('form_tooltips_forms', ''),
    '#cols' => 40,
	'#rows' => 3,
	'#resizable' => TRUE,
  );
  
  return system_settings_form($form);
}

/**
* Correct textareas
*/
function _form_tooltips_correct_fields(&$field) {
  // Convert separate chars to line return
  $field = str_replace(array(',', ';', ' ', "\r\n", "\r"), "\n", $field);
  
  // Convert to array and remove empty elements
  $field = array_filter(explode("\n", $field));
  
  // Store as string
  $field = implode("\n", $field);
}

/**
 * Verify that a new path is valid
 */
function form_tooltips_admin_settings_validate($form, &$form_state) {
  // Correct fields
  _form_tooltips_correct_fields($form_state['values']['form_tooltips_forms']);
  
  // Get forms id in an array
  $forms_id = explode("\n", $form_state['values']['form_tooltips_forms']);
  
  // Forms loop
  foreach ($forms_id as $form_id) {
    // If no value, continue
	if (!($form_id)) {
	  continue;
	}
	
    // If no function with form id name, so form id doesn't exists
    if (!(function_exists($form_id))) {
	  form_set_error('forms', t('The form %form_id doesn\'t exists.', array('%form_id' => $form_id)));
	}
  }
}
// Remove the PHP end tag

And replace code of form_tooltips.module by :

// $Id: form_tooltips.module,v 1.1.2.3 2009/04/06 01:29:18 entrigan Exp $


/**
 * Implementation of hook_perm().
 */
function form_tooltips_perm() {
  return array('administer form_tooltips');
}

/**
 * Implementation of hook_menu().
 */
function form_tooltips_menu() {
  $items = array();
  
  $items['admin/settings/form_tooltips'] = array(
    'title' => 'Form tooltips',
    'description' => 'Administer form tooltips.',
    'page callback' => 'drupal_get_form',
	'page arguments' => array('form_tooltips_admin_settings'),
    'access arguments' => array('administer form_tooltips'),
	'type' => MENU_NORMAL_ITEM,
	'file' => 'form_tooltips.admin.inc',
  );
  
  return $items;
}

/**
 * Implementation of hook_form_alter().
 */
function form_tooltips_form_alter(&$form, &$form_state, $form_id) {
  // Get scope
  $scope = variable_get('form_tooltips_scope', 0);
  
  // Get forms id in array
  $forms_id = explode("\n", variable_get('form_tooltips_forms', ''));
  
  // If form is allowed to have tooltips
  if ((in_array($form_id, $forms_id)) ^ (!($scope))) {
    drupal_add_js(drupal_get_path('module', 'form_tooltips') . '/form_tooltips.js');
    drupal_add_css(drupal_get_path('module', 'form_tooltips') . '/form_tooltips.css', 'module', 'all', FALSE);
  }
}
// Remove the PHP end tag

This code works fine but if you set visibily to : 'Show on every form except the listed forms.' and you set a form id in the forms list, so if the form listed is on a page with other forms, the tooltips will be used regardless the option.

So maybe it will be better to set a list of path where tooltips will be applied instead a list of forms id.

And we can add other options like style of tooltips, color, effect, ...

entrigan’s picture

Thanks Sinasquax,

I have been planning on looking into how to do this for a while, and this looks great. I just committed your updates to the 1.x-dev, and I am going to play/test it alot more tomorrow morning when I have time.

is the ^ an XOR operation?
if ((in_array($form_id, $forms_id)) ^ (!($scope)))

BTW, thanks for the amazing code commenting.

EDIT: So it looks like the form validation is failing for things like page_node_form, perhaps because node forms are not declared with functions? I am looking into it. Otherwise it works great.

sinasquax’s picture

Thank you for testing,

Yes the ^ is a XOR operation but for 'bit' test instead for logical test (in this case it's the same but it's preferable to put XOR instead ^, my mistake)

You are right, the node form doesn't works, i think it's because the code for nodes (node_form which is factory form for all content type) is doesn't loaded when drupal shows form tooltips admin form and so the test with function_exists return false.

But with this test, there's another problem, you can put function like variable_get, ... in the textarea and it will be validated (but it will does nothing), it's another reason to use path instead form name for the check but maybe there's a drupal function which return an array of form name or use drupal_get_form instead function_exists.

(sorry for my bad english)

sinasquax’s picture

StatusFileSize
new11.26 KB

I have modified the code to deal with paths instead with form id, i don't know what is the best solution (form id or path ?) but if you want keep the form id version so you must remove the check which looks if the form id is correct (because it's wrong).

You can set which path has / hasn't form_tooltips with paths like this :

node/%
node/%/edit
node/add/page
...

entrigan’s picture

I am hesitant to implement path based controls, because I think it is less intuitive (although perhaps easier to use). Either way my computer went kaput, so I will be revisiting this in a few days when I get this all sorted out.

On second thought paths might be a great idea, because many people do not know how to find form ID's, and like you said since it will apply to all forms on the page, that might actually be more intuitive. Unless it passes a variable to the JQuery which makes it only apply to specific forms within the page.