The documentation says that the #prefix and #suffix properties are available for the file_managed FAPI element, but ~ line 470 of file.module these properties are overwritten:

<?php
  // Prefix and suffix used for Ajax replacement.
  $element['#prefix'] = '<div id="' . $element['#id'] . '-ajax-wrapper">';
  $element['#suffix'] = '</div>';
?>

It makes sense, but should this be handled in another way?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

WidgetsBurritos’s picture

Assigned: Unassigned » WidgetsBurritos
Issue summary: View changes
Status: Active » Needs review
FileSize
734 bytes

I came across this and saw that this has been an issue for at least 2 1/2 years. To me it seems like the simple fix is to look for an existing #prefix and #suffix and prepend/append them accordingly to the new #prefix/#suffix.

I've attached a patch that does this. All my tests seem to be okay, but it will need further review.

jwilson3’s picture

Not sure, so I'm asking... Should the existing prefix and suffix be included *inside* the ajax wrapper, in case it gets updated by some ajax process, or is this not possible. At the very least, a code comment explaining why we're adding the existing prefix and suffix outside would go a long way for understandability.

WidgetsBurritos’s picture

My reasoning for putting it outside was exactly because of the possibility of Ajax being able to replace things. If I am wrapping this with a div that I can use for styling purposes, I don't really want to worry about Ajax replacing my div somehow.

If it's inside that seems like a risk that could potentially happen, especially if we happen to use one of the same ids or classes used by the Ajax process.

If it's outside of the Ajax wrapper then there's really no risk of that. (Well presuming the Ajax calls are only looking inside the wrapper for things. I haven't inspected that process but I would assume that's the case.)

Also it seems consistent with how existing prefixes and suffixes are handled. The idea of a prefix in my mind means before anything else, regardless of what that thing is. And suffix is after everything else, regardless of what that thing is.

So if someone adds a #prefix or #suffix they would assume their values would be before and after any other data respectively.

Does that make sense? Let me know. If not let me know and we can discuss it further.

I'm not in front a computer right now (writing this from my phone), but will add some comments when I get a chance and upload a new patch.

WidgetsBurritos’s picture

Here's an updated patch with a little bit more explanation on why we are wrapping the prefix/suffix outside of the ajax container instead of on the inside.