Closed (fixed)
Project:
Scald: Media Management made easy
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
13 Mar 2015 at 10:17 UTC
Updated:
21 Apr 2015 at 11:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
nagy.balint commentedThe following patch should be applied to the module before starting work on this, to avoid future conflicts. https://www.drupal.org/node/1978828
Comment #2
gifad commentedHi nagy.bálint,
Attached is a patch I would have submitted to Local caption on atom reference, if the issue had not been closed…
It provides, instead of a 'caption' text column, a 'options' (serializable array) column (which solves the storage problem of generalized options)
By now, there is just an options['caption'], but it's fairly easy to add an options['context'] : just step by the '// TODO: ' comments…
BTW, I had no conflict developping this on a code base where #1978828 was already applied…
Comment #3
nagy.balint commentedHi :)
awesome,
Maybe there was no issues as the other patch is mostly changing JS stuff.
There seems to be a typo at
Comment #4
nagy.balint commentedWe should check if we need that many changes in the formatter.
Isnt it like we only need to check for the context to not display the context defined in the field display but the one defined in the override if one exists?
And then the caption is handled by the representation, as usually all options are.
But then maybe im missing something.
Comment #5
gifad commentedMost changes are not about the caption itself, but about the way to store something in the field storage…
Now about the context : attached is a working patch, which is facing a severe issue :
The selected context will be used in every view mode of the container node; specifically, it will apply in teaser mode, while the user was thinking of the full mode...
To make it worse, the atom_reference_field_formatter_view() function used to render the atom has no information about the actual view mode (the $display argument contains the scald rendering context…)
I'll have a look at hook_field_attach_view_alter() ?
[setting needs review, just to pass the tests, but obviously needs work]
Comment #7
nagy.balint commented@gifad:
I meant for example this part:
Isnt figcaption handled by the image provider's representation?
Comment #8
gifad commented@bálint:
It's handled by the Image Player, and we could use another player;
More importantly, atom referenced could be a scald_gallery atom, or whatever;
This caption is more like the caption embedded in the div class="dnd-caption-wrapper"…
Back to the representation context : I managed to limit the scope of the overriden context to the "full" view mode (using debug_backtrace, shame on me !)
Definitely needs work !
Comment #9
nagy.balint commentedThe typo is still there though from my comment #3 the description is there twice.
Comment #11
nagy.balint commented@gifad : can you explain to me in more detail why we need to limit the display mode?
As far as i understand if i dragged an atom into a reference field, and i change the default representation set up in the field display settings, then it should be overriden in all displays. Cause its defined by the user on the field. And then on any display it should be displayed like how the user wanted.
So it seems to me that we simply have to override the representation value to the one in the options when it exists, and thats it.
Because otherwise this option would be confusing if it only worked for the full display.
But then the problem is that we should not provide a selection for each existing display, as that would be a UX fail i guess.
Maybe this need more thought into it...
Comment #12
gifad commented@bálint:
On my test site, atom reference are represented in a medium size in full mode, and in the 'title' context in teaser mode (the home page, search results, ...)
For a given atom on a given page, a user would like the atom represented in a larger size context - but of course keep the 'title' representation on the home page...
OK, I could have specified
mode != 'teaser'rather thanmode == 'full'Comment #13
nagy.balint commentedFor me it produced the following reject when applying on scald code with the following patches
- https://www.drupal.org/files/issues/atom_reference-1978828-61.patch
- https://www.drupal.org/files/issues/2393425-scald-widget-false-drop-72.p...
atom_reference.js.rej
Can fix that later of course.
Comment #14
nagy.balint commented@gifad:
Seems like there is no way to query the view mode from the formatter_view function.
http://drupal.stackexchange.com/questions/39224/how-to-get-view-mode-fro...
And checked other sources as well.
Seems like this issue is not as easy as i thought :(
Comment #15
nagy.balint commentedMaybe a good idea could be to create a separate formatter for the atom reference field.
Basically it would duplicate each format with something like "Overridable Title", "Overridable Editor Representation" and so on.
And then the site builder can select on which view modes he wants to enable this option. And then of course the context override would only work on this overridable formatter.
(The rest of the options can be carried through in either formatter though).
Maybe something along this line could be a good solution.
Comment #16
nagy.balint commentedThough im not sure why we have each representation as a separate format, instead of having a format like "Representation" and "Overridable Representation" and then select the representation in the formatter settings.
Though changing it like that would surely require an update hook the least...
(Or maybe some trouble with the views integration?)
Comment #17
gifad commentedAfter having a look at the source code of field_default_view(), I got it with :
About "typo" from #3 : the field description is indeed present twice :
one for the schema
second for the update
I did not change my mind about view_mode == full : think of RSS feeds with 'random' representations...
Fixed minor cosmetic issues, try to pass test :
Comment #18
gifad commentedComment #20
nagy.balint commented@gifad:
Have you read comment #15, and #16?
As i think thats the only way to make this work properly.
Doing it with debug_backtrace is not an option, pretty ugly.
And putting in a hard coded limit will not work generally anyways, what if i want this override to work for a custom view mode, what if i dont want it to work for custom view mode.
There is no way to do it properly without an extra formatter like i wrote in 15, or 16.
Comment #21
nagy.balint commentedComment #22
gifad commented@bálint:
Yes, but I could not understand "create a separate formatter"; could you point me to some sample code, or api reference ? (or is it just a translation issue ?)
Anyway, I introduced the "Allow context override" in the formatter settings, so get rid of the pretty debug_backtrace /;
and more importantly, remove hardcoded option…
Comment #24
gifad commentedfixed typo
Comment #25
nagy.balint commentedMy comment was just about creating another formatter for the field type and then the site builder can select which formatter to use, the overrideable formatter or the non overridable formatter.
But your solution seems to be better with the formatter setting.
Comment #26
nagy.balint commentedSo then according to #17
This array is perfectly fine?
The description array key is there twice, basically the second one will override the first one, i see no point in it...
Comment #27
nagy.balint commentedAlso there is one more task to do:
Currently we are altering the context names by drupal_alter('scald_wysiwyg_context_list', $contexts);
So in wysiwyg you see a customized list, where the labels can be different.
And for most of our clients it needs to be customized.
We should harmonize that, to also apply the same way for this new context selection. Of course changing the name would be problematic for backward compatibility. But at any rate there should be a way to make sure that the same list comes up for the user here than in the wysiwyg.
Comment #28
gifad commentedin reply to #25 : by 'formatter' you mean 'context' (or 'representation') ?
Yes, I've been thinking of that, but I have already too many 'formatters'…
in reply to #26
Fixed (my working code base has the 'edit view' patch applied, so there are a lot of copy/paste to the git version, and this one failed..)
in reply to #27
Yes, I already use scald_wysiwyg_context_list_alter(), and will implement a similar atom_reference_context_list_alter()
(the context lists should be similar, not be strictly identical)
For now, added a top level checkbox "allow override" in admin/structure/types/manage/{bundle}/fields/{atom_reference_field}
so that:
if not globally allowed for the content-type
Comment #29
nagy.balint commented1. As i see we will have to change a test in scald core cause of the link setting value changes.
Then we either have to ignore that part failing and also change the test in the patch,
or have to make a separate patch that changes the test, and then commit that before the other to be able to test.
Or maybe there is a better way of doing it.
2. As i see the caption is currently a textfield. Maybe a text area would be better.
But I think this will be confusing for the user on certain areas, like in the scald_gallery to have a caption text field in addition to the description and other stuff there.
However this cant be the description of the scald_gallery either cause (apart from not being a textarea) the render would use this caption to produce a figcaption for the atom (in the current patch), while in scald_gallery the description is used for the galleria player to display a description below the images.
Otherwise the patch seems to work fine, nice work!
Of course more testing is required, and cleaning on the patch.
Comment #30
nagy.balint commentedPatch can be recreated based on latest dev.
Comment #31
nagy.balint commentedSeparated out the wysiwyg context list alter problem : #2457005: Generalize hook_scald_wysiwyg_context_list_alter
Comment #32
gifad commentedPatch rerolled against current dev
Included a
drupal_alter('atom_reference_context_list', $contexts);, as I think there should be different sets of contexts, depending on the atom is embedded in a textarea ("wysiwyg"), or attached in a form (atom_reference, views, ...);Another key distinction is that, in the current implementation, the atom type, and even the atom itself, is not known by the (server side) source code;
It would make more sense if context selection were handled by javascript...
Comment #33
gifad commentedComment #34
nagy.balint commentedYes its the same in wysiwyg the server does not know what atoms you drag into the wysiwyg, so the list there is populated from JS, and its dynamic, as you open the dialog for a given atom.
Of course a different set of JS is needed for the other cases, but its the same there, we have the context list per type in the variables, we just have to use that to limit the items in the select list (and to rename them)
Comment #35
gifad commentedSide thought, back to the original issue title :
What's the point of having an atom reference field ?
Why not just a textarea, dnd and mee enabled, with specific input format and ckeditor profile ?
This solves all representation problems...
What would you miss ?
Comment #36
nagy.balint commentedYou would miss mostly content architecture.
- In a wysiwyg you cannot limit what types of atoms you can drag.
- In a wysiwyg managing multi value fields would be really a UX fail.
- In a wysiwyg you can put anything which you might not supposed to add. Like putting all kinds of text and other wysiwyg stuff next to the atom.
- You cannot say display only the first item of the multi value field, cause that would mean displaying the first atom of a wysiwyg?
There are countless problems :)
Its i guess the same argument as why dont we have a single textarea field, instead of having separate fields. Mainly due content architecture.
Often we have separate image fields, (like main image of a content type) instead of putting the whole render as a wysiwyg.
Comment #37
nagy.balint commentedAlso if the question is that we could create a multi value textarea to replace a multi value atom reference, then we have the following problems:
1. Even with specific ckeditor settings, we cannot deny the user from entering text or new lines or whatever into the editor on top of dragging any number of atoms into a single textarea. This is quite a big problem, as you will have no idea what is in a given field unless you parse it each time. And probably additional filters are also needed.
2. Previews cannot be properly guaranteed as they might not always fit into the ckeditor initial display.
3. It can potentially introduce a lot of separate ckeditor instances on a single page, which is a huge performance impact.
Generally when i add an atom reference field, i add it because id like if the user dragged some atom into that field, and then from code or on the display i could be sure that i have an atom, and i can display it or do whatever with it. Its a lot clearer and strait forward situation.
Comment #38
nagy.balint commentedAnd about the need, we actually already had an occasion, where we had a main image for a node display, and the requirement was to let the user define the context or image style of the image in the atom reference field. There we've done it with custom code using a new image style reference field (https://www.drupal.org/sandbox/york/2383353) and a custom representation, but the atom reference was limited to images, and it would be nice to have a general solution for these cases.
And since we need this also for scald_pane linked above, i think its a nice to have feature in fact.
Comment #39
nagy.balint commentedIn order to get this into the upcoming scald 1.4, i ve decided to separate out and rework only the part that is relevant for the task description, which is the new options field and the context switching ability with the new javascript code.
I've removed the alters, as discussion about that can continue at #2457005: Generalize hook_scald_wysiwyg_context_list_alter
And because the altered list is already available for javascript, as shown in scald_pane, so now the list in atom reference field overrides and in wysiwyg on the same page going to be the same which is good.
I've also removed the title, link, and caption parts. To change as little as possible in this patch for now, also I'm still not sold on the idea of having another figcaption around the atom markup on top of the figcaption in the image provider. Plus having an extra caption is a problem for scald_gallery too, so likely we should not do that yet.
Adding those further fields can happen in followup issues.
I've tested the update hook, works fine. Testing the fresh install is still to be done, but will do that with simplytestme.
The identation of the atom_reference.js is wrong, but i did not want to change it in this patch, as that would ruin the diff, can do in a follow up commit.
I've added a use_the_default option in the representation selector on the atom reference, because actually that field cannot have a default value from anywhere, as the default value can be different per display formatter, also its easier for the user to select this option when he wants to get back the default, instead of remembering what was the default setting.
Otherwise the attached patch works fine for me, will need more testing.
Comment #40
nagy.balint commentedTested new install on simplytestme, seems to be fine.
Comment #41
nagy.balint commentedAdded one more check, even though there was no JS error.
Comment #43
nagy.balint commentedCommitted. Further work can be done in followup issues.
Comment #44
gifad commented"options" array was recursively inserted in itself at each update...
Fixed.
Comment #45
nagy.balint commentedThanks! Committed.