When creating a custom form and attaching a wysywyg like:

    '#type' => 'text_format',
    '#format' => 'panopoly_wysiwyg_text',

You get the errors below:

Warning: preg_match_all() expects parameter 2 to be string, array given in _media_generate_tagMap() (line 240 of /var/www/aaaa/www/profiles/panopoly/modules/contrib/media/includes/media.filter.inc).
Warning: Invalid argument supplied for foreach() in _media_generate_tagMap() (line 241 of /var/www/aaaa/www/profiles/panopoly/modules/contrib/media/includes/media.filter.inc).
Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1545 of /var/www/aaaa/www/includes/bootstrap.inc).

Comments

mschudders’s picture

a temp fix is to hook_submit the form and;:

  $form_state['values']['professional_txt'] = $form_state['values']['professional_txt']['value'];
  $form_state['values']['particulier_txt'] = $form_state['values']['particulier_txt']['value'];

So the error is produced because :
$form_state['values']['particulier_txt']The field is an array instead of an normal string

thirdender’s picture

I don't know if this is an issue with the Media module. The last error is an error that can be related to the text_format text field. Without seeing the rest of the OP's code, it's hard to say.

hargobind’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

I ran into the same problem, and I confirmed that it's not an issue with the media module ... well, at least not when your form has been coded properly.

Here's example code that implements a system_settings_form() that causes this error:

  $signature = variable_get('mymodule_email_signature', '');
  $form['mymodule_email_signature'] = array(
    '#type' => 'text_format',
    '#title' => t('Signature for emails'),
    '#description' => t('This signature will be added to the bottom of emails that get sent to customers.'),
    '#default_value' => $signature,
    '#format' => filter_default_format(),
  );

When the variable is empty, you see no errors. As soon as you save the form and the variable gets a value, media.filter.inc will throw an error in _media_generate_tagMap() when it tries to use the value of $signature (which is an array) as a text string when it calls preg_match_all().

Here is what your code SHOULD look like. Notice that '#default_value' and '#format' are using the respective keys of the $signature array.

  $signature = variable_get('mymodule_email_signature', array('value' => '', 'format' => filter_default_format());
  $form['mymodule_email_signature'] = array(
    '#type' => 'text_format',
    '#title' => t('Signature for emails'),
    '#description' => t('This signature will be added to the bottom of emails that get sent to customers.'),
    '#default_value' => $signature['value'],
    '#format' => $signature['format'],
  );

The workaround provided by @Mschudders is incorrect because it does not store the '#format' of the field. So if a user chooses a different text format, it will be reset to the default one next time they visit the form. It's hard to determine whether this is an issue with Panopoly, or with custom code created by @Mschudders, so feel free to modify this issue and assign it to Panopoly if needs be.

hargobind’s picture

Title: Errors when using custom WYSYWIG. » Errors when using a field of '#type' => 'text_format'