Hi there,

in D6 I used the gmaplocation module and by installing CKEditor I could nicely format the information printed above the google map. See screenshot D6.

In Location Map the text fields to print additional info do not support the use of CKEditor (or any other client side editor). See screenshot D7.

I'm guessing this is linked to the fact that we also cannot choose the input format for the text fields like in Drupal 6/gmaplocation which triggers the use of an editor.

Any help is welcome.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rupertj’s picture

Title: Text fields do not support wysiwyg editors (or text formats) » Change text fields to support wysiwyg editors & text formats.
Category: bug » feature
Status: Active » Needs work

There's info here on how this could be added to locationmap: http://drupal.org/node/1087468

From the looks of it, it's as easy as changing the type of those form fields.

jvdurme’s picture

Thanks for the good tip, rupertj.
I can successfully change the field to text_format and specify the format. The wysiwyg editor appears!

I used this code:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  $id = $form['#id'];
  switch ($id) {
  case 'locationmap-admin-settings':
     $form['info']['locationmap_body']['#type'] = 'text_format';
     $form['info']['locationmap_body']['#format'] = 'full_html';
    break;
  }
}

Then I type some text in the editor and save it. Unfortunately this raises an error without displaying the text I typed:

Error message
Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1572 of /var/www/switch/drupal7/includes/bootstrap.inc).

Suggestions are welcome. :)

babbage’s picture

FileSize
60.65 KB

Initially I thought, sure, I'll add that. Why not. Then I did, and I saw what it looked like and remembered why I didn't do this in the first place:

Screenshot of locationmap module with html formatting added to text boxes

The configuration form just becomes an unreadable mess, thanks to Drupal's verbose "help" about html tags. Now not sure whether I want to do this or not. Hmm.

jvdurme’s picture

Well, you don't have to if you don't want, but a working workaround for people who want it, would be nice.
Right now we are stuck with this error when trying to alter the field type and try to save some text in the editor.
Any help is appreciated.

babbage’s picture

Yep, I know the cause of the error you're seeing and will fix soon. Will at the least post a patch for people who want this now, then look at how to implement while minimising the ugly. :)

Edit: By "soon", I mean at the earliest tomorrow.

jvdurme’s picture

Thanks babbage, much appreciated!
In the mean time, I have found a solution to get rid of the error. But your patch will be better, because my fix won't work with plain textareas. But I'm quite proud that I found it , so here goes.

The code to alter the form field to text_format:

function hook_form_alter(&$form, $form_state, $form_id) {
  $id = $form['#id'];
  switch ($id) {
    case 'locationmap-admin-settings':
      $locationmap_body = variable_get('locationmap_body');
      $locationmap_body_value = $locationmap_body['value'];
      $form['info']['locationmap_body']['#type'] = 'text_format';
      $form['info']['locationmap_body']['#default_value'] = $locationmap_body_value;
      break;
  }
}

Then I changed the line in locationmap.module:

$output = '<div id="locationmap_body">' . $locationmap_body . '</div>';

To:

$output = '<div id="locationmap_body">' . $locationmap_body['value'] . '</div>';

The text_format element outputs an array with 2 elements, one is the value of the field, the other is the text format. So the module has to print the value element of the array, not the entire array.
The difference with plain textarea is that textarea only outputs a string containing the value. I hope I'm right.

But I'm eager to see your patch, babbage. :)
Thanks again!

babbage’s picture

OK, I've committed the change to the 7.x-2.x branch, and a 7.x-2.x-dev release will be available next time the drupal.org packaging script runs (used to be once every six hours). This hasn't fixed the ugly yet (i.e. the form editing page now has multiple "help" text sections that tell you how to manage text formats) but it at least provides the requested functionality.

If you'd like to see the changes to manually apply them yourself, a diff and patch are here. jvdurme, you were indeed on the right track, as you'll see from the diff. :)

jvdurme’s picture

That's really great, babbage!
Forget the ugliness a little, that's not what the user sees (normally).
Really thanks for the quick update. :)

babbage’s picture

Status: Needs work » Needs review

Ugliness fixed in commit e51c3af on 7.x-2.x. Should be fixed now... Before closing this issue, I'd appreciate review from those wanting to use particular WYSIWYG editors that this has enabled their preferred editor to be used in these fields succesfully.

jvdurme’s picture

I promise to review it tonight. Haven't had the time to apply the patch, but will review everything tonight.
Thanks!

jvdurme’s picture

Hey babbage,

I disabled 7.x-2.1, deleted the whole module folder, installed 7.x-2.x-dev and enabled it.
When going to admin/config/locationmap, I get following drupal error message:

    Notice: Uninitialized string offset: 0 in locationmap_admin_settings() (line 177 of /var/www/switch/drupal7/sites/all/modules/contrib/locationmap/locationmap.module).
    Notice: Uninitialized string offset: 0 in locationmap_admin_settings() (line 178 of /var/www/switch/drupal7/sites/all/modules/contrib/locationmap/locationmap.module).

For the rest, everything works. Map is showing and I can use my favorite CKEditor in the config page. :)
One little thing: when going to admin/config/locationmap, I was only interested in the info above the map. So I selected Full html there. The other info boxes were not important to me, so I left them alone. However, when trying to save the settings, I got the error that I have to select a text format for every item/text field.
Not that it's fatal, but it's a bit annoying. ;)

Thanks!

Joost

babbage’s picture

Good feedback Joost. There is supposed to be a default set for those fields, based on your global default. Will look into it, and the error messages.

jvdurme’s picture

Mmm, today I'm not getting the error (the one I put in a code box in the previous post) anymore... that's strange.
But I think it had something to do with the fact that the footer field was the only empty one.
Marker and 'above info' had some text.

Great job on the ugliness fix, babbage. Looks really smooth now!

babbage’s picture

Actually, I suspected when I saw it you'd only get the error on the first visit. So unless you'd done a clean install again, you wouldn't see it the second time. Just about to test that. :)

babbage’s picture

Hey jvdurme. I'm afraid I've not been able to reproduce any of the errors that you described, using a stock-standard fresh Drupal 7.14 installation and a brand new installation of the module. I'm wondering if the error you saw was because although you had deleted the module code base, you hadn't actually uninstalled the module so the old configuration information was still in the database. So I'll try installing v2.1, the upgrading to the development branch, and see if I can reproduce what you saw...

Edit: Yep. Shockingly obvious when I think about it. The data for those fields is stored now as an array, it wasn't before, and I didn't provide an upgrade. Oops. Fixing now... :)

babbage’s picture

Commit to the 7.x-2.x-dev branch provides the necessary upgrade code to modify the variables. This fixes both of the reported error types, which were related to the same underlying problem.

Be sure to run update.php (or drush updb) when updating to the development branch...

jvdurme’s picture

Allrighty.
I disabled the previous version, enabled the new dev version, ran update.php and went to my locationmap.
All is well. And for the record: no error messages. ;-)

I think this issue can be closed. Job well done, babbage! Much appreciated.
I'll send you a link when my website is live. :)

babbage’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 99f6b44 on master, 7.x-2.x, 8.x-2.x by babbage:
    Issue #1692348: Support text formats in text fields.