Closed (fixed)
Project:
Token Filter
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
30 Sep 2017 at 13:40 UTC
Updated:
5 Apr 2018 at 16:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
kingfisher64 commentedA workaround as a temporary solution is to create a new Token Type and assign the filter for this.
Of course, some ckeditor functionality is lost but with html code knowledge it can be applied manually.
Would be great if it could work with ckeditor enabled.
Comment #3
martijn de witBy default Dupal core hides all guidelines for textarea's that have widgets enabled. (see https://www.drupal.org/node/2098071)
I think there are two possible solutions:
The second one is my favorite.
Comment #4
martijn de witComment #5
martijn de witComment #6
kingfisher64 commentedThe 2nd idea is my favourite too.
Comment #7
martijn de witGreat, I'm making a patch with a CKeditor pluign for this module.
I will keep you all posted.
Comment #8
martijn de witMade a patch. It's creating a CKEditor button that is opening the token browser in a model.
Big thanks to Beljaako for helping me with getting the right token browser url.
Now i'm facing only one problem. The modal has an overlay and the modal is not drag-able. Already spent some evenings to try and search for the right approach to fix this. The standard options I'm using don't seems to work. jQuery.ui.dialog diolog.js and diolog.ajax.js are using different option names. Maybe someone can help a hand.
You need the patch supplied here to enter tokens in a editor: https://www.drupal.org/files/issues/token-wysiwyg-2235581-10.patch
If you remove the overlay via the inspect tool in the browser the functionality is working.
Comment #9
martijn de witComment #10
martijn de witA zip because it are 3 new files and it seems the patch is not working well with a new image file.
Comment #11
kingfisher64 commentedThanks Martijn, i'm not a dev to propose a fix but will test once completed :)
Comment #12
darvanenNice.
However, clicking on the link to add a token in the token browser triggers an alert:
Comment #13
andriy khomych commentedHello! I found a small issue related to this patch:
https://www.drupal.org/files/issues/broken_icon.jpg
The toolbar icon for CKeditor plugin is broken, I think you could put any simple image and fix this issue. This very confused on editing content.
Regards, Andrii.
Comment #14
andriy khomych commentedComment #15
martijn de wit@Andriy Khomych, The image is in the zip in this issue. If you can help me to apply a image to a patch it will be great. I couldn't find a method to do so.
Comment #16
colanHere's a proper patch file for #10, including the image.
Reviewing now...
Comment #17
colanHere's some PHP code clean-up and coding standards fixes.
I'm confirming #12: Clicking one of the tokens in the list yields the pop-up, even though the text field was selected before opening the box. So it's currently not possible to click or drag these from the modal.
Typing the text in manually works, but that's a huge UX hit. Copying & pasted doesn't work well because it includes the link.
So getting #12 fixed is imperative.
Now, that pop-up shouldn't be necessary to begin with. Given that you're clicking on a specific text area's token button, the token should simply go into that text area. It wouldn't make sense for them to go anywhere else. So we need to tell the JS what field to use, and drop that check entirely. Not sure if we need to add anything to the Token module to make that happen.
Comment #18
andriy khomych commentedSorry, @Martijn de Wit, I was busy a small, seems it is fixed without my help.
Comment #19
colanI think the second problem we're having is that context-specific tokens aren't showing up in the list. Even though I'm on a node form, I'm not seeing the any of the Node tokens showing up in the token browser list. They do, however, show up on my site's
/admin/help/token. So we need to pass in the context as well.Comment #20
colanThis fixes #19. As the context isn't always available, it's better to present all available tokens. It takes several seconds to load the entire tree, but there's a "Loading..." message.
I also switched over to using dependency injection so there's no more
\Drupalaccess.So we're now left with fixing #12.
Comment #21
darvanen#1229568: Token UI 2.0 should help with the loading time.
Comment #22
darvanenI think CKEditor support is broken in the Token module. Here's the line that is supposed to insert the text:
There's no
Drupal.ckeditorActiveId, is that something that was working in D7 but now doesn't?Comment #23
darvanenHere we go. There's a few code standards changes in the plugin.js file but the magic is at line 38:
This fixes #12.
I was wrong about the support being broken, we just weren't using it correctly.
Comment #24
darvanenBy the way @colan, what did you mean by "the context isn't always available"? That sounds like something that might be fixable, have you got any specific examples where the context isn't available?
Comment #25
colan#24: I don't have an example. You're absolutely right. I put some time into trying to figure out the context, i.e. the entity we're currently in, and kept running into problems. So I took a shortcut. The
token_typesarray was empty initially so I set it toallas that's a magic term there.But if you're interested in trying to fix this, please go ahead. I'd welcome the change. It would shrink the table, which would be better for UX.
I believe the best way to go forward with this is to populate that array with entities from the route parameters, which can be fetched using a method described in the forums.
You can then add a
getTokenTypes()method to generate them like so:I believe it wasn't working in my case because I was having trouble figuring out the exact format for this. So there may be more work to do here. Good luck!
In my particular case, I've got a content type that's used as a template. Its values (including tokens) get injected into another content type with Prepopulate. So if we limit the token list in the first context, the ones needed for the second may not be available. But this is done per entity, and they're both nodes, so it probably doesn't matter.
Comment #26
martijn de witThank you all. @Darvanen I will review the patch soon!
Comment #27
martijn de witComment #28
darvanen#25: My biggest concern is that a high proportion of the issues I've been reading for this module are people not understanding the context - "why doesn't a node token work in a block?".
I'll give it a go if I have some time in the next few days. If this gets committed before I get to it we can start a new issue.
Comment #29
darvanenHoly cow, you weren't wrong @colan. I think it's more a case of "when IS the context available", not "when is it not".
The Plugin class and manager, and the CKEditor main class all have absolutely no idea which entity they are operating on because they are added in the theme layer on render. Add to this that it seems like none of the available services in the container can tell you which entity the form being built belongs to (on render) and you've pretty much got no context at all. Even the request stack only has paths which are pretty unreliable for implying entity type.
I hesitate to use the methods described in your linked page because they're based off the internal path which only works for the top level form. Nested forms such as comments on a node or media entities inside a node will have different contexts in addition to those available to the parent.
Unless there is some way of making CKEditorPluginManager aware of the parent entity of the element it's being attached to I don't see a way to bring context into this.
Comment #30
colanLet's assume this is as good as it gets for now then, and wait for someone else to test #23. (I haven't had a chance yet.) If that's all good, we can RTBC it, and then see what the maintainer(s) think(s).
Comment #31
mekal commented#23 (with the image from the zip) worked for me on Drupal 8.5.0, for both 8.x-1.0-beta1 and 8.x-1.x-dev.
Comment #32
colanComment #34
darvanenComment #35
colan@Darvanen: Thanks for committing, but it would also be nice to provide credit to the rest of us that worked on the issue. See below.
Comment #36
darvanenI did?:
https://www.drupal.org/commitlog/commit/8312/e7ea8cbacd1572f69c4c4ba26f2...
If you're talking about the form down the bottom of the screen, it doesn't reflect what's actually in the commit.
Comment #37
colanRight, but I think that only gets recorded in the commit (and thank you for that). I don't believe the credits show up in profiles from there; the form at the bottom would need to be filled out. Basically, there seems to be a discrepancy between commit credit and issue credit. For my projects, I always do both.
For example, I should be seeing credit on my profile for Token Filter, but there isn't any. Normally when I assign credit to others using that form, it show up immediately on their profiles. Sorry for the trouble, but the UX for this stuff isn't great.
Comment #38
darvanenWell that explains a few things if true, sorry mate had no idea about that.
Certainly won't hurt to change it!
Comment #39
colanThanks! Worked.