There seems to be a bigger problem in combination with wysiwyg.module (and possibly other modules). The module seems to change the array structure in form element which wysiwyg expects.

This leads to several notices and warnings for me:

  • Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 194 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
  • Warning: Invalid argument supplied for foreach() in wysiwyg_pre_render_text_format() (Zeile 194 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
  • Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 223 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
  • Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 226 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
  • Notice: Undefined variable: format_id in wysiwyg_pre_render_text_format() (Zeile 227 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
  • Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 229 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
  • Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 237 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).

The cause for that is in

function simplify_hide_text_format_element($element) {
$element['format']['#access'] = FALSE;

return $element;
}

This seems to create an array structure that wysiwyg does not expect as you can see from the lines above in wysiwyg module.

As a quick fix I added the following condition that only adds the #access property if the format key exists. This fixes the bug for me, but I'm not sure if the format element hiding now works properly in all conditions or if it has side effects.

That should be checked:

function simplify_hide_text_format_element($element) {
if (!empty($element['format'])) {
$element['format']['#access'] = FALSE;
}

return $element;
}

Perhaps the module maintainer has some comments on this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anybody’s picture

BWPanda’s picture

Status: Active » Needs review
FileSize
964 bytes

Thanks for your issues and code fixes! I like both solutions and think that it should be fine to commit without too much testing (as making sure a form element exists before changing it seems like a sensible thing to do).

Here's a patch that adds both changes (from this issue and the other one you linked to above).

Anybody’s picture

The patch equals my changes and thereby the code I have in production. RTBC from my point.

Anybody’s picture

PS: Thank you very much for your quick response and beautiful work. :) This is a great module!

steve65140’s picture

Issue summary: View changes

The patch works fine for me.
And I echo comment #4 - this is a great module. Makes things much clearer for content authors.

steve65140’s picture

Issue summary: View changes

Sorry but I seem to have accidentally destroyed the Issue Summary. I've pasted it back.

BWPanda’s picture

Status: Needs review » Reviewed & tested by the community

  • BWPanda committed 1b1d095 on 7.x-3.x
    Issue #2483393 by BWPanda: Multiple notices and warnings when used...
BWPanda’s picture

Status: Reviewed & tested by the community » Fixed
Stephen Ollman’s picture

Confirm patch at #2 resolves the issue. Great work!

Anybody’s picture

Cool! So perhaps this will be part of the next stable release? :)

  • BWPanda committed 1b1d095 on 8.x-1.x
    Issue #2483393 by BWPanda: Multiple notices and warnings when used...
webservant316’s picture

#2 removed the errors for me... HOWEVER, the main problem still remains.

I had been using simplify to force user to only use the default format option. However, now for some reason all my text formats are default to plain text instead of the wysiwyg format option I had selected as the default in the content field configuration.

I need to get this fixed fast on my production site :-(

Anybody’s picture

Please disable simplify, clear all caches and test if the behaviour is normal.
Perhaps also have a look at https://www.drupal.org/project/better_formats.

But of course we should fix this. How is your module configured and do you still get any PHP Notices / Warnings / Errors from this module after the patch?
Did this problem occur before the patch already?

webservant316’s picture

ok - this patch did work for me, but my TinyMCE editor was not displaying, making it look like I was defaulting to the wrong text format type. So the second problem was solved with a patch from here https://www.drupal.org/node/2477343#comment-9966239. So both patch #2 above and the patch from https://www.drupal.org/node/2477343#comment-9966239 were needed to solve the problem.

The two patches effect lines of code VERY near each other. The patch at https://www.drupal.org/node/2477343 simply changes one line in simplify.module.

-$element['format']['#access'] = FALSE;
+$element['format']['#attributes']['class'][] = 'element-invisible';

Seems like these two patches ought to be reviewed and committed together.

BWPanda’s picture

The patch from this issue has already been committed. The other issue needs further testing before I'm happy to commit it too. Please leave further discussion for the other issue as this one is fixed.

CD’s picture

I know that the patch from this issue has already been committed. But I'm going to wait until the next recommended release comes out because my drupal skills are not the best.

I wanted to ask though, are there any security issues with the clash with wysiwyg and getting in the log report these errors:

Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 194 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
Warning: Invalid argument supplied for foreach() in wysiwyg_pre_render_text_format() (Zeile 194 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 223 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 226 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
Notice: Undefined variable: format_id in wysiwyg_pre_render_text_format() (Zeile 227 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 229 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).
Notice: Undefined index: format in wysiwyg_pre_render_text_format() (Zeile 237 von sites/all/modules/contrib/wysiwyg/wysiwyg.module).

So the question is is there a security issue here, and can someone use this to hack my site?

Thanks

BWPanda’s picture

No security issue, just WYSIWYG looking for something that didn't exist - you're safe.

Anybody’s picture

The patch works great. Anyway I eventually have a follow-up.

When I visit the user registration page now I get the following Warning:

Warning: Invalid argument supplied for foreach() in element_children() (Zeile 6521 von includes/common.inc).

Here's the backtrace:
#0 element_children() called at [sites/all/modules/contrib/simplify/simplify.module:661]
#1 simplify_hide_text_format_elements() called at [sites/all/modules/contrib/simplify/simplify.module:663]
#2 simplify_hide_text_format_elements(Array ([administer_users] => Array ([#type] => value,[#value] => ),[#user] => stdClass Object ([uid] => 0 ...
...
drupal_build_form
drupal_get_form(user_register_form)
call_user_func_array(drupal_get_form, Array ([0] => user_register_form)) called...
menu_execute_active_handler() called ...

$elements is NULL in element_children().

I've got no idea yet, why this happens...

BWPanda’s picture

That sounds like a separate issue. Can you create a new issue for that please?

Status: Fixed » Closed (fixed)

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

ggevalt’s picture

Actually, I don't think it's fixed.
I attached the patch just fine.
I uninstalled the first module. Cleared out the folder. Uploaded the new/patched folder with modules. And I get the same warning messages.
This module was working several months ago. I'm working on a dev site so I'm not sure what, on my end, might be contributing to this, but I am flummoxed. Sure would like to solve this.
Here's the message I get:
Notice: Undefined index: format in wysiwyg_pre_render_text_format() (line 222 of .... /sites/all/modules/wysiwyg/wysiwyg.module) Repeats for lines 224 three times, 225 and 268.

Help is always appreciated. And thanks for all your hard work. Sorry it isn't helping me. :)
g

LittleCoding’s picture

I've just bumped into the same error message when creating an admin form. The fix I found was to check for each format, guidelines, help and limit access for each. Well that is you goal is to hide all three (format - "Text format" [drop down selector], guidelines - "Text Formatter Details" [like limits of markup and filter tips], help - "more information about text formats").

<?php
function simplify_hide_text_format_element($element) {
if (!empty($element['format']['format'])) {
$element['format']['format']['#access'] = FALSE;
}
if (!empty($element['format']['guidelines'])) {
$element['format']['guidelines']['#access'] = FALSE;
}
if (!empty($element['format']['help'])) {
$element['format']['help']['#access'] = FALSE;
}
return $element;
}
?>

Sorry I do not have time to make up and submit the patch.

zeezhao’s picture

Status: Closed (fixed) » Active

Hi. Seeing this issue too. Setting to open.

joshuautley’s picture

Patch #2 worked for us. Thank you.

TwoD’s picture

Status: Active » Needs review
Related issues: +#2243413: Error when adding field items - Add another item
FileSize
672 bytes

Encountered the original issue when debugging #2243413-21: Error when adding field items - Add another item and I'm glad to see that part fixed already.

Rolled a patch for the additional changes in #23.

NWOM’s picture

#26 worked great. Thank you!

Tharick’s picture

#26 working cool. Thank you :)

LittleCoding’s picture

FileSize
722 bytes

A minor change to the patch in #26 to individually remove access to the format elements.

Dom.’s picture

Status: Needs review » Reviewed & tested by the community

Patch 29 is RTBC

BWPanda’s picture

Status: Reviewed & tested by the community » Postponed

There seems to be two different solutions to hiding the text format element happening here in the issue queues. #2477343: TinyMCE editor hidden on upgrade solves the problem by simply adding CSS to hide the text format element (rather than this solution which disables access to it). I suspect the CSS solution is the better option as other issues seem to revolve around the fact that disabling access to form elements can muck up other modules that require them.

So please test the patch #2477343: TinyMCE editor hidden on upgrade instead and let's see if that solves a few different issues at once.

jelo’s picture

I just tested the patch in the other issue and it solved my issue as well...

Dom.’s picture

Status: Postponed » Closed (outdated)

Version 7.x is no more really supported. Just provided as is until end-of-life.
Feel free to reopen and update if there are reason we should still invest work on this.