Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Fields which are "dnd-enabled" are assigned a default context, which is currently unused in "normal" use case.
The patch below implements :
- Default contexts are saved in a variable dnd_context_defaults which is an array[bundle][fileld].
- DnD-enabled textareas are tagged with the default context of their bundle/field-name.
- On client side, atom rendering is deferred from drag event to drop event, where correct context can be selected, and eventually fetched.
Comment | File | Size | Author |
---|---|---|---|
#14 | ie8_daggable-1995238-18.patch | 3.92 KB | dDoak |
#11 | scald_default_context_per_field-2013823-11.patch | 4.39 KB | jcisio |
#10 | scald_default_context_per_field-2013823-10.patch | 4.89 KB | jcisio |
Comments
Comment #1
gifad CreditAttribution: gifad commentedThe patch, attached.
Additionally :
As a performance improvement, all the "normally" usable contexts could be embedded in the library items, but I could not find a way to do it without disturbing dnd architecture on client side...
Please consider,
Regards
Comment #2
jcisio CreditAttribution: jcisio commentedIt is in general a good idea. However the try catch block is there for IE compatibility, it should not be removed. Also pay attention to coding standards.
Comment #3
gifad CreditAttribution: gifad commentedIn the current implementation, the try block uses dataTransfer 'text/html', which is no more used in the patch;
The patch uses 'Text', which was in the catch block;
So what could I try/catch ?
BTW, it doesn't work in IE8, but the same way as the demo site...
I'm sorry I have no IE9 machine to test with..
Comment #4
jcisio CreditAttribution: jcisio commentedYes, it works with IE9+ and we should keep it. Also I think text/html is necessary because it helps to drag and drop to a place where we don't have control on the drop event.
Here is a more thorough review:
- Unnecessary or unrelated CSS change.
- Instead of using dnd_context_defaults, I think it'd be more DX friendly to add an option into field instance settings (like "context_default")
- I don't understand on the legend trick in JS.
- Coding standards: two spaces instead of tab.
Comment #5
gifad CreditAttribution: gifad commented- unrelated CSS change : ok, it's another issue : missing field.css for proper rendering of Authors and Tags in wysiwyg;
- add an option into field instance settings : this option exists, it's just named "Scald Editor Context " and described as "Choose a Scald Context to use for displaying Scald Atoms included in the textarea during editing.";
I added a variable as I am not able to retrieve this vale in the dnd_process_textarea() function, where I need it;
Also, this setting defaults to "Debuging display", so I preferred not to use it until users explicitly specify it...
(Yet another issue : mee.module should filter "hidden" contexts out of this list...)
- legend trick in JS : when an atom is fetched via ajax, the data received contains an empty (not NULL) legend, so the $.extend(true, Drupal.dnd.Atoms[atom_id], data[atom_id]); empties the atom legend (just try "Edit atom properties > Context > Full page")
- Coding standards : done.
Additionally, I managed to embed all "normally available" contexts in scald_dnd_library_add_item() (the "contexts" property of Atoms was already ready to receive it), so I could remove fetchAtom() call in drop callback;
Comment #6
gifad CreditAttribution: gifad commentedFixed the missing hidden context filtering in field settings :
Comment #7
gifad CreditAttribution: gifad commentedTo preserve IE compatibility, the try/catch blocks in drag and drop callbacks have been restored to original state.
The context information is now picked in plugin instanciation, and overrides Drupal.settings.dnd.contextDefault.
The major drawback is that the default context is the same for all textareas of the content-type...
dnd_context_defaults variable has been thown away, leaving mee.module out of the patch;
default context information is now retrieve in dnd_process_textarea() via $form_state['field']['body']['und']['instance']['settings']['context'];
This was obvious, but I'm getting old, and couldn't see it immediately ;)
Other unrelated "minor" fixes removed;
Comment #8
julien_g CreditAttribution: julien_g commentedI applied this patch to be able to configure my delfault contexts per field.
2 issues about this patch :
- the was and IE bug that makes IE only use the general default context (sdl_editor_representation). I fixed this bug.
- I was unable to apply the patch on scald 7.x-1.x-dev because of the improvments in the targeted modules. I have adaptated the patch to the last dev version.
But this idea is a good way to use the field instance setting context for default editor context.
Comment #9
jcisio CreditAttribution: jcisio commentedLooks ok, except:
Should not hardcode the field name and language.
Comment #10
jcisio CreditAttribution: jcisio commentedNew patch introduces another "default context" in the textarea (#4), and correct the other setting on fallback context. It also fixes the hardcoded field name/field language.
However, default context per field should not be stored as a global state (mention in #7). It needs to be fixed.
I also don't think it is a good reason to preload all atoms with all contexts. It unnecessarily fills the cache because usually not all contexts are used for every atom.
Comment #11
jcisio CreditAttribution: jcisio commentedI think it is a quite nice clean up. Didn't test with IE though. So please test & review ;)
Comment #12
jcisio CreditAttribution: jcisio commentedTested again with IE9 and it works. So committed 9f0849d and pushed. Thanks all!
Comment #14
dDoak CreditAttribution: dDoak commentedHere is a new patch due to a regression on atom reference Drag&Drop + A cleanly way to detect native drag behavior
Comment #15
JonesUI CreditAttribution: JonesUI commentedIs the patch in #11 included with the latest dev release (7.x-1.1+67-dev)?
Comment #16
jcisio CreditAttribution: jcisio commentedIgnore #14 because it is already posted at https://drupal.org/node/1995238#comment-8483081