Everything is in the title: Wysiwyg assumes that #access on format means there is only one filter available, this is wrong and breaks format default value in hidden field.

This code:

  // Use a hidden element for a single text format.
  if (!$format_field['format']['#access']) {
    $format_field['wysiwyg'] = array(
      '#type' => 'hidden',
      '#name' => $format_field['format']['#name'],
      '#value' => $format_id,
      '#attributes' => array(
        'id' => $format_field['format']['#id'],
        'class' => array('wysiwyg'),
      ),
    );

Is both conceptually and alrorithmically wrong.

  • Conceptually because #access to false is also valid when another module wants to force a format to be used
  • Algorithmically because you should reuse the current #value or #default_value instead of the latest $format_id, which comes from a random loop and does not respect the current value.

What happens here is that this algorithm takes the element with the higher weight, erase the previsously set value and set this one instead.

CommentFileSizeAuthor
#1 2210523-wysiwyg-wrong-format-value.patch546 bytespounard
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pounard’s picture

Here is a patch supposedly working with the 7.x-2.2 version (manual diff, sorry).

TwoD’s picture

You're looking at old code, this was changed in the 7.x-2.x branch (and is thus in the 7.x-2.x-dev snapshots).
Wysiwyg now does $format_id = $format_field['format']['#value']; (and makes sure #access was explicitly set) just before adding the hidden field.

We don't use the #default_value because a module would have to set #format to change the format to be used for a text_format field, which once it reaches the #pre_render callback has already been moved into #value (and #default_value, but since #value exists, it's ignored).

pounard’s picture

Status: Active » Closed (works as designed)

Oh right, my bad, I was sure I looked at the right code using drupalcode's gitweb, but I think now I must have clicked the wrong branch. Thank you for the detailed explaination, this is a non issue then.

TwoD’s picture

No problem, it happens. :)