Issue to track Aloha Blocks integration.

CommentFileSizeAuthor
#2 1686568-token_filter-2.patch3.63 KBWim Leers
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Title: Aloha Editor integration » Nested editables: token_filter
Wim Leers’s picture

Title: Nested editables: token_filter » Nested editables: macro filter tags (first: token_filter)
FileSize
3.63 KB

Let's begin with token_filter. I pushed code to the Edit module that prepares it for this: http://drupalcode.org/project/edit.git/commitdiff/227b881. I've also prepared a patch for the token_filter module that allows us to easily experiment with Aloha Blocks for macro filter tags that are editable through Aloha Editor.

Wim Leers’s picture

(I had created a new issue for this comment, which I shouldn't have. #1697594: Aloha Editor + Spark sprint: token_filter fork on GitHub is now closed.)

For prototyping purposes, I have included a modified check_markup() function in the Edit module, so that we could experiment with "nested editables" (i.e. things that are editable *inside* the WYSIWYG editor). I've then modified the token_filter module so that the custom AE plug-in for editing tokens within the AE WYSIWYG would have the necessary API endpoints to call.

My modifications:
- https://github.com/wimleers/token_filter/commit/90a4f33dc73b0b48eac7472c...
- https://github.com/wimleers/token_filter/commit/deb17de7b167990b4f7a60e1...

The initial AE plug-in that was implemented by Tobias Steiner of Gentics/Aloha Editor:
- https://github.com/wimleers/token_filter/commit/232923a2a6ba615f2d4719f2...

Wim Leers’s picture

Wim Leers’s picture

Finally, the generic issue for dealing with "true WYSIWYG" + format/filters compatibility is now #1699722: "True WYSIWYG" and compatibility with Drupal's text formats/filters.

sun’s picture

Wim Leers’s picture

@sun: OMG YES! That's such an awesome issue! Coincidentally, I took nearly the same route here, for the Edit module :)

sun’s picture

Yes. :) And at least automated tests seem to confirm that Inline API works! ;) The latest and greatest code has just been merged into the 7.x-2.x mainline.

I also want to publicly state "Why there is Inline API at all?" — The token system in Drupal core was never architecturally designed for the purpose of producing rich HTML markup. It's architecturally designed to handle plain-text replacements within plain-text. Anything beyond that is out of scope for the token system.

(I personally consider the [existing] $sanitize parameter on token_replace() as a hack already, which attempts to bend a system to something it was never designed for. — which only explains major problems/issues like #974782: Resulting string format of token_replace(..., array('sanitize' => FALSE)) is undefined...)

Furthermore, Filter module's text format + filter system does not seem to be suitable for this desired/intended job. Essentially, what this hacked token_filter implementation is trying to achieve is #226963: Context-aware text filters (provide more meta information to the filter system)... If you happen to read and properly step through that issue and its duplicates, then you'll notice that the feature request actually dates back to the epic d.o node ID #8000: Filter contexts (and fix some small issues in filtering), on which the very author of the filter system said that "the filter system architecturally does not and will not support contexts."

I always agreed with that statement, given the Filter module's current design and involved filter_cache (which ultimately is the reason for why contexts cannot be supported). However, the intended usage/purpose of Edit module (as well as Inline API) is way beyond input filters in the first place. That behavior should not be tied to the actual text being rendered in the first place — it is primarily tied to the context and field the content is rendered in. In fact, the usage doesn't actually care that much that it is dealing with text. The primary relation to "text" is that something (another resource) is rendered within (embedded) in text. Fundamentally, this does not require a text format with filters to be involved at all. (!)

"Leveraging the filter system" has many other unintended/unexpected consequences. Listing and explaining those alone would hi-jack this issue entirely, so see #6 (as well as all the related Inline API discussions linked in there). For the purpose of what we want to achieve, acting on the field level and outside of the filter system is very appropriate.

(This entire comment actually rather belongs onto some core issue, but I'd have absolutely no idea on which one... so this is it)


Regarding Edit + Inline API, I'm still missing information on what this adjusted token_filter implementation is essentially doing.

I glanced over the code multiple times already, but never really recognized what it's actually doing and what its actual difference/effect is?

Wim Leers’s picture

Token vs. Inline API == plain text vs. rich text: agreed. I don't intend to use token_filter for rich text. It's just the most simple replacement system possible, and that's why I chose that as a starting point.

RE: Filter module's text format + filter system not being suitable.
Well, yes and no. #226963: Context-aware text filters (provide more meta information to the filter system) would allow me to not have to hack (or rather: provide an alternative to) the Filter module AFAICT, but at the same time, that issue attempts to do much more than I actually need for just the Edit module. For the Edit module, it's sufficient that we get filters to wrap the expanded/replaced values of macro tags in a standardized way, so that we can show the author the eventual value and still allow the author to change macro tags, while using a WYSIWYG editor. (See more below the horizontal rule.)

And now for the really interesting part…

I always agreed with that statement, given the Filter module's current design and involved filter_cache (which ultimately is the reason for why contexts cannot be supported). However, the intended usage/purpose of Edit module (as well as Inline API) is way beyond input filters in the first place. That behavior should not be tied to the actual text being rendered in the first place — it is primarily tied to the context and field the content is rendered in. In fact, the usage doesn't actually care that much that it is dealing with text. The primary relation to "text" is that something (another resource) is rendered within (embedded) in text. Fundamentally, this does not require a text format with filters to be involved at all. (!)

+9000

I wholeheartedly agree! To me, it seems people in those issues confused two types of context: internal and external. The internal (inherent) context is information that is really just part of the entity of which the text field is being filtered: the author, the language it is written in, etc. The external context is where context-aware filters become problematic: global/request information such as the current user, the current user's language, but also "page context" such as region in which it is rendered, whether it's rendered as part of a view, etc.

(Note that even in the case of external context, there are partial solutions to the problem that would limit the performance impact: render everything except these highly volatile replacement values, cache the result, upon viewing, get the result and only apply filters with highly volatile replacement values.)

So, IMO, internal context should be part of the filter system. Unless I'm missing something, I don't think it would cause a combinatorial explosion. External context could cause that, but there are ways around it. So unless we're willing to build the fairly sophisticated system I briefly described above, I don't think we should do that.


Note that I don't (yet) need the "context awareness" aspect. What I need, is to have … well, a "context" that indicates that all macro tags should be wrapped in some standardized way, to allow the client-side editor to know where exactly these macros live. Then we can show the author the macros as they will be eventually rendered to end users, but still allow the author to change them, WYSIWYG-style.

The changes I made:

Note that for my own "contextual" $wrap_macro_tags parameter, it may not be really necessary to cache the results. Though that would assume only a limited number of users would be able to view the content in this special way, otherwise it may tax the server too much. So it may not be a safe assumption after all. If that's the case though, it's very likely a very advanced site, and developers would be able to override the lack of caching and simply make it cache after all.

sun’s picture

Thanks for pointing out those individual commit diffs. Obviously, I'd love Edit module to switch to Inline API instead of token_filter. ;)

So if I get this right, then all you'd need for Edit is this?

+  $attributes = array(
+    'class'               => 'edit-editable-macro',
+    'data-macro'          => $macro,
+    'data-macro-provider' => $module,
+  );
+  return '<span' . drupal_attributes($attributes) . '>' . $value . '</span>';

(give or take a different class name)

That looks like a no-brainer for Inline API ;)

As well as your 3rd point, which involves:

1) Discovery and administrative UI listing. Is that functionality used by Edit module already? Actually, I'm not sure I understand why the produces a JSON response? Is that merely supposed to let the clientside know, which possible macro tag names may exist and appear at all, and just that?

2) A server callback to pass a macro to, which returns the rendered representation (if permitted). Can you clarify in which UI context this is used?

PS: Note that I had to edit your comment to remove the colons after the commit URLs - they're valid characters for URLs so all of them 404'ed ;)

Wim Leers’s picture

I'm not sure what you mean.

Edit module is not in any way tied to the token_filter module. It's just the most simple example possible. I think it makes perfect sense for it to also support the Inline module. But really, it's not up to the Edit module to implement this. In Edit, there's no token_filter-specific code at all. The Edit module only provides a slightly extended version of the Filter system, that is all! :)

1) Those JSON responses are for the AE plug-in we wrote for token_filter: https://github.com/wimleers/token_filter/commit/232923a2a6ba615f2d4719f2.... We'd need to write a similar plug-in for Inline. But maybe (well, *hopefully*) the Edit module (actually, the edit_aloha module) can provide a generic implementation of that, which can accomodate most of the "macro tags" filter modules :)

2) See 1.

P.S.: heh … oops! I'll make sure to not do that again :) Thanks for pointing that out!

Wim Leers’s picture

An interesting problem with the Inline module + having image captions:
- We wanted to be able to have an "image caption" filter disabled and simply have all the image captions disappear without having to do anything at all. We achieved this by deciding that we were going to have a "data-caption" attribute on the img tag (so: <img src="flower.png" data-caption="Such a beautiful flower!" />).
- This can never work well with an image that is rendered by the Inline module. The above assumes we have an actual HTML tag to work with, whereas the inline module uses a special syntax, in any case not HTML-tag based.
- The only way this could be resolved AFAICT is by having the inline module switch to a HTML-based (custom tag-based) approach, a la <inline type="image" node="345" field="field_main_image" data-caption="Such a beautiful flower!" />. I.e. let modules extend functionality provided by "filter modules" by adding new attributes.

What are your thoughts on this, sun?

Wim Leers’s picture

Ontopic: token_filter has received significant changes on Friday (3 days ago):
- no more Aloha Block handles: https://github.com/wimleers/token_filter/commit/1f1e7442c3ed1ac489b6f5da...
- code clean-up
- only show the <select> when the token (the Aloha Block, really) has focus: https://github.com/wimleers/token_filter/commit/17e1b3ddda75f9d9233b09f5...
- this last change requires a patch to Aloha Editor: https://github.com/alohaeditor/Aloha-Editor/pull/622

Wim Leers’s picture

My patch/pull request for Aloha Editor has been merged: https://github.com/alohaeditor/Aloha-Editor/pull/622. :)

Anonymous’s picture

Regarding the #12, i think i have something like that for inline

http://drupalcode.org/project/inline.git/shortlog/refs/heads/7.x-2.x-xml...

Please review and comment?

Wim Leers’s picture

@javier: the problem is that this is a filter and thus it is executed as part of the filter system, whereas the Inline module would run *after* the filter system, during hook_field_attach_view_alter()… :(

Wim Leers’s picture

Project: Edit » Aloha Editor
Wim Leers’s picture

Issue summary: View changes

.