Integrating with Lightbox2 module, i reached this point:
* Lightbox requires that images are rendered wrapped in an anchor <a href="..."> <img /> </a>
* Inline has a global setting that handles how inline renders the images: as a link, or as a image tag.
In my website, i use inline to embed images on places where i dont want anchors on them (decorative images).
In my blog posts, i use inline to embed images for examples/tutorials, etc, and here i want my website users to be able to click on the "mini" image, and then get a nice lightbox2 bigger image (to see details of that image better, etc)
So im stuck with:
* If i change the global setting to "as anchors", lightbox2 works fine on my blog posts, BUT inline also renders my custom decorative images as anchors (ugly)
* The other way, my custom decorative image are rendered just fine (without a wrapping anchor) BUT my blog posts dont work (cause lightbox2 depends on an anchor, which was not wrapped around that image)
I would like to add some optional parameters to inline filter syntax, so a user can force it to render certain images as links or as image (overriding the global setting).
If it makes sense, please tell me and i can start working on the patches.
| Comment | File | Size | Author |
|---|---|---|---|
| #49 | inline.architecture.49.patch | 5.22 KB | sun |
| #46 | inline.patch | 2.09 KB | Anonymous (not verified) |
| #26 | inline.coding-standards.26.patch | 8.17 KB | sun |
| #8 | Issue-1671276.patch | 2.97 KB | Anonymous (not verified) |
Comments
Comment #1
sunerr. What happened to Lightbox'
rel="lightbox"support?Comment #2
Anonymous (not verified) commented@sun: support is there, but it works just for images wrapped on anchors (i 've tested it, and also docs for lightbox2 stands so http://drupal.org/node/144469.
Automatic Image Detection: configurable automatic re-formatting of image node thumbnails, so there is no need to add 'rel="lightbox"' to each image node link on your site
Note the final part ... "image node __link__ on your"...
Comment #3
sunI see.
I'd strongly suggest the following, before starting to implement something:
The lack of this language feature is actually what caused the most trouble for Inline in the past. But who really cares for HTML4 today?
Nowadays, I would expect that any modern *box implementation is able to work with data- attributes (and potentially an additional class for selector performance, but that's unimportant):
Comment #4
sunIf possible, please also make sure to check for existing issues in the queue. :) I'm relatively sure that this is not the first feature request along these lines. ;)
Comment #5
Anonymous (not verified) commentedI' ve checked the issue queue. There is a request with a patch for integration with thickbox #227816: Thickbox integration
Also, i' ve looked at Colorbox javascript logic, and it seems them also search for
<a>with a certain class for activating the *box on clicking those, displaying the "full" image.On the HTML5 side, i agree. But AFAIK, all *box current implementations seem to work with the same logic. When those *box projects start working with HTML5 attributes, i think inline changes should be pretty easy.
So, i don't see any other option than extending inline to let the user choose (force) where to use (or not) links.
Comment #6
sunSo what you're essentially saying is that each inline tag needs to decide how it gets rendered.
That is, because there is no solid context system in Drupal yet, which you could rely on. It's therefore not possible to figure out at which point which contextual setting would have to be applied. (e.g., node vs. block)
And at that point, we're essentially reaching the general problem space of that the current Inline filter syntax is too limited and does not allow further parameters. ;)
Which, in turn, is the exact same problem space of #394682: CCK fields (filefield,imagefield,emfield) and fieldgroups for Inline API :)
This is why I started to work on #80170: Inline API - which apparently lives in the master branch - and which introduces a whole new macro syntax for inline filters. The current support for "uploaded attachments" turns into just one use-case with that, and hence, has been separated out into a inline_upload.module sub-module.
The whole concept is also explained in sun's vision for handling embedded/inline content and Wysiwyg in Drupal - which explains the architecture, and apparently still makes sense, even 4.5 years later ;)
Some people are even actively using that master branch code already, despite being in-development code only -- e.g., #286792: Allow to define ImageCache preset and image position per inline tag is a patch to extend it.
Needless to say, the master branch code is 6.x-2.x and would have to be moved into a corresponding branch and upgraded into 7.x-2.x afterwards.
I would love, love, love if you would get your hands dirty with that 2.x Inline API code, and could even see myself jumping on the gun to resolve the initial barrier of porting the code to D7. :)
But of course, I do not and totally cannot force you into working on a completely different thing... ;) So far, the plan/roadmap was to retain Inline 1.x with its current, limited feature-set as long as that is needed, and develop the entire new world of 2.x in parallel.
Comment #7
Anonymous (not verified) commentedMay be i've not expressed well. Really when i said "let the user choose..." i was not talking about a new setting, but let him decide on the place where he uses inline, to write what he needs on that exact node.
For example, if global setting is to NOT use links for inline:
On node 123, he knows is creating a blog post, where he needs lightbox enabled, then he will write:
[inline:myimage.png=Screenshot|aslink]
That way, we handle that special aslink parameter (specifically near the call to _inline_decide_img_tag()) so we can force the call to theme('inline_img'...) or to theme('inline_as_link'...)
Similarly, if the global setting is YES to use links for all inline'd images, and in a certain node he dont want it as a link, he would write:
[inline:myimage.png=Screenshot|nolink]
I hope i expressed well on the solution i think.
Anyway, if the Inline API you pointed can help on something related to this, or to inline in general, i could get my hands on it!
Comment #8
Anonymous (not verified) commentedMy patch for a implementation. Please review! Waiting green flag to push to head... or to make it better?
Comment #9
sun1) The new regex doesn't look correct to me.
- There's a bogus comma added within the old expression.
- The optional comma between the old and the new addition makes a tag valid, which happens to only have a comma after the filename or equal sign.
2) The option names "aslink" and "nolink" are highly confusing, because Inline already supports theme_inline_as_link(), and one would assume that those options refer to that, but in fact, they are not. The options need better names.
- That's more or less essentially why I pointed you to Inline API 2.x... with the 1.x syntax, it's almost impossible to design new parameters for the macro tag that are clean and make sense. (In 2.x, you'd simply refer to an image field formatter name to use, but/and you have a solid macro syntax at hand that allows to specify custom additional parameters, so this would turn into
|link=0.)The two conditions should be combined, since you cannot render an image if the helper function decides that it cannot be rendered as image, even if the inline macro tag contains the additional parameter.
Trailing white-space.
The added code does not adhere to coding standards for control structures; see http://drupal.org/coding-standards
Comment #10
Anonymous (not verified) commented@sun: If u think i' m losing my time with this patch, and it is better to focus on inline api, i can get my hands on it just to make inline have the options i need :)
I'll leave the decision on your hands, as you know the inline api code, and can better estimate the time and effort needed to implement that api on D7 branch. (I would love to use it on my website really soon)
Comment #11
sunIn general, I don't think that Inline 1.x has a prospering future. It's architecture does not allow any more than nasty hacks.
FWIW, I've renamed master into 6.x-2.x, and ported it to D7:
http://drupalcode.org/project/inline.git/shortlog/refs/heads/7.x-2.x
You can test and see it in action with the built-in default plugin for nodes, by placing this macro tag into a (second) node:
The inline_upload sub-module has not been ported yet, as it needs to be redone, since Upload module no longer exists.
Upload module is File module now, which is a field. In general, Inline API 2.x should probably be refactored to mainly act on entities and fields (i.e., entity types, and field widget forms + formatters) instead of the random Form API mess it's trying to integrate with now ;)
As a (hypothetical) result, inline.node.inc would become inline.entity.inc, and the inline_upload sub-module would be removed in favor of a generic inline.field.inc implementation. As the names imply:
[$entity_type|id=123]; e.g.:[field|name=$field_name|type=$entity_type|id=$entity_id|formatter=$formatter]; e.g.:For entities, you can globally configure the view modes (and a custom ones). For fields, you can leverage all formatters that exist on your site and the inline macro syntax allows you to specify custom settings for a particular formatter.
But to clarify again, all of that entity + field stuff doesn't exist in 2.x yet. It needs to be developed. :)
Also, as one of the commit messages suggests, Inline API 2.x has (basic) built-in support for Wysiwyg API/module, as envisioned in that years-old g.d.o page. ;) Inline API was and still is the driving force behind that idea and effort, so possibilities are still quite limited. In fact, working on this D7 port revealed a blatant oversight in Wysiwyg module, which I fixed in parallel. If you want to try the (demo) integration, use Wysiwyg with TinyMCE 3, and enable the "Inline node" editor plugin for it.
HTH :)
Comment #12
Anonymous (not verified) commentedNice! I will try to get first the field plugin (so i can embed images as previous version) then continue with entities in general, etc.
Sad i didnt know you was working on porting it, as i last night was doing the very same ;)
Comment #13
Anonymous (not verified) commented@sun: from #11, i need clarify on
"...the random Form API mess..."
Which idea do you have on doing it "the right way"? May be that should be fixed first, then advance with something more "solid" on the entity/field default plugins
Comment #14
sunI'm not exactly sure on that myself right now -- apparently, I wrote all of this code like 2 years ago ;)
However, this is my general train of thought:
Then, on a completely different end, it tries to integrate with hook_entity_insert() and hook_entity_update() in order to record whether the entity/field that was added/edited has actually been saved into the database (so the contained inline tags can be marked as permanent).
Lastly, the inline tags are tried to be processed and rendered as an input filter...
So there are a lot of arguments for not making Inline an input filter at all. Instead, it should integrate with the field view/rendering process of text fields, which inherently gives us 1) context and 2) proper content maintenance (just simply relying on the existing field cache; Inline does not even have to do anything about caching).
Especially the context allows us to properly track $entity_type, $bundle, $entity_id, $field_name, and $langcode. (The idea of tracking inline tags originates from http://drupal.org/project/img_assist module and turned out to be a very good one -- a CMS should know where a content is used - even if it appears only in an embedded form.)
The one possible pitfall with moving from an input filter to a text field integration is that text formats support a security/access concept, so it is currently possible to decide whether inline tags are allowed for, say, the Filtered HTML format, which might be the default for comments and is allowed for anonymous users. Perhaps Inline needs to remain an input filter for that reason - but perhaps also not; availability and access to inline tags could as well be configured on a field/widget basis.
IIRC, the current code attempts to do that by integrating with the form submit handler and entity insert hooks, and searching for all inline tags that need an entity ID, but specify the ID 0 (zero). However, the entity only gets an ID after it was written to the database. And in hook_entity_insert(), there's no way to get back to the text field values that contain the inline tags, so they cannot be updated to include the proper/actual entity ID.
IIRC, that was the primary reason for introducing the
{inline}.iid-- the iid is added to each inline tag during form validation already, so all inline tags have an iid. The hook_entity_insert() then goes ahead and reloads all inline macros being stored in {inline} according to the recorded iids and injects the proper/actual entity ID into those {inline} database records. This means that the inline tags that are contained in text values do not necessarily contain all the parameters that the corresponding {inline} record in the database contains...This is a huge mess. :)
By moving to a field workflow integration, I'm relatively sure that we could eliminate almost all of that. That is, because Field API itself basically has the same problem with its own field values: They are attached to the entity, so they can only be written after the primary entity record has been inserted. And alas, the {field_data_*} tables contain the correct entity IDs :) so Field API properly accounts for that already, which means that if Inline would integrate with field widgets, then it could automatically rely on all of that and wouldn't have to do anything on its own.
Does that make sense to you?
Comment #15
Anonymous (not verified) commentedThanks for the long intro to the actual code implementation.
I think it makes sense, as far as u have more expertise than me on drupal internals and capabilities. Then i will start working on that Fields API integration. Any thing i get stuck i will post here so you can help me on this.
Comment #16
sunDo you want to create and use patches against 7.x-2.x and post them here for review?
You could as well branch 7.x-2.x into a 7.x-2.x-field topic/feature branch, so you can commit atomic changes to that branch, and only create patches for review here via
git diff 7.x-2.x...7.x-2.x-fieldComment #17
Anonymous (not verified) commentedI prefer working on that 7.x-2-x branch if u are ok with that? I 've some code already working. Give me the ok then i commit and we can discuss further changes?
Comment #18
Anonymous (not verified) commentedBy looking at the best hooks from the Fields API, I think we should go the "no input filter" way you pointed previosly.
The input filter arch from drupal gives little chance to give more power to inline (missing context... etc)
I'll continue going this way then post here for more advice.
Comment #19
Anonymous (not verified) commentedBy moving to field integration, i think the whole inline iid thing (including the table) may not be needed. I think we can leave the plain macros on the text field itself. I think of an alternative to this question.
In body of node nid=2 I write:
This macro will render the first image on the field 'field_image' of node nid=1. But, if i want to reference just the 'current node' ?
I think we can use the $context from
hook_field_attach_view_alter(), pass it to the macro invoke , so the macro itself can assume, when nid parameter is not present, nid = current node (which we can get on $context)Basically i'm propossing radical changes on the code to achieve that.
Any thoughts on this?
Comment #20
sunFor now, I'd prefer if you'd use a feature/topic branch for this major refactoring.
That is, because we cannot change the git commit history of the main branch(es), so whatever development commits and debugging you do would appear very visibly for everyone. Contrary to that, a feature/topic branch can be changed, rewritten, heck, even deleted and recreated at any time. :)
If you already have commits on your local 7.x-2.x branch, just simply do this:
The first two will copy all your local commits on 7.x-2.x into a new 7.x-2.x-field branch, and then push it upstream, automatically adding the upstream branch as branch to track.
The second two commands will hop back to 7.x-2.x and reset it to the upstream 7.x-2.x, losing all local changes in 7.x-2.x.
Comment #21
sunre: #19:
Yes, that's definitely in line with my thinking and what I wrote in #14. Two possible pitfalls though, which really need more investigation and probably can't be answered out of the blue:
Essentially, by removing the parameters that (basically) point to "$this", you're also removing the possibility for everything that might integrate with inline macros to figure out what $this is. Bear in mind that the raw inline macros will appear in the field widgets, and one of the primary consumers is going to be a wysiwyg editor that is purely working in the frontend/JavaScript side of things, which does not have the implicit knowledge you are presuming. Hence, an implicit $this can easily cause troubles on these other ends.
If the implicit is merely preferred over the explicit to make the macro tag shorter, then I would recommend to punt on that. In an ideal world, these macro tags should not be visible to the end-user in the first place; they are way too cryptic. The inline macro tags exist for machines only, and a machine does not care for how long a tag is, and in fact, a machine will always be much happier when it can deal with explicit things, because that inherently means less magic, less special conditions, less code, etc.
The iid might still be required for tracking, but I'm not 100% sure. I'm thinking of the case where one might have multiple references to another resource.
But perhaps it is irrelevant how many times entity+field A references entity/field B. Perhaps we do not have to track the actual macro parameters at all, and change and reduce the {inline} table to basically be a simple "reference tracking" table.
In that case, we likely want to change the schema to be a full set describing origin and destination:
...whereas revision, langcode, and field values can be NULL, in case the involved entities do not support revisions or are not multilingual, or in case an inline macro tag references an entire entity (instead of a field).
This, however, leaves the question of what to do about inline macros that do not reference an entity. Perhaps we just don't care at all (and perhaps that even makes sense).
Oh, and since we're mostly tracking data of other modules, we most probably should have a 'module' column (or even two) in there, so records can be properly cleaned up in case a module is uninstalled.
Comment #22
Anonymous (not verified) commentedI create a node, the in the body i type some text, with an embeded [field|type=node|name=field_image...], which points to "the current node" (nid=0?). then i upload some image on the field_image... then i click Preview
Preview doesn' t saves the node, nor the fields to DB yet, so the nid is not there yet, so the Preview for the [field|...] cant be rendered.
May be in this case we must simply state "inline macros can't be previewed when referencing the node itself"
Anyway, once the node is saved, we can get the nid and update those (nid=0 "special case") macros to reflect the nid (replace nid=0 with nid=123)
This way, wysiwyg editors must explicitly put nid=0 when referencing the "yet unsaved" node, or the "current node id" when the node is being edited and self referenced (i mean a field, not the very node itself to avoid infinite recursion!) ;)
I think you referred to this? Any other use case for that inline tracking table?
Comment #23
Anonymous (not verified) commentedFirst commit on 7.x-2.x-field branch: work in progress!
http://drupalcode.org/project/inline.git/commitdiff/54c2b1df877e0513d691...
Please be kind on observations! ;)
Basically:
Questions to define:
Comment #24
sunJust a quick comment for now:
Larger parts of the code does not adhere to the http://drupal.org/coding-standards which makes it hard to review. Most noteworthy issues are on control structures (if/else/etc) and (Mac?) line-endings. Cleaning that up and ensuring it for all further changes would dramatically help :)
Also, (apparently your second question) there's a lot of commented out code. But this is yet another benefit of feature/topic branches: All code is versioned, and at minimum the main branch still has it. No one will notice the removals until they're final (in the main branch). Instead of commenting out, just remove it. :) That will make it a lot easier for me and everyone else to review :)
Aside from that, these changes already start to make a lot of sense! :)
Your first question is tough. I've to admit I don't have a quick/easy answer. I usually approach such questions from a contextual user perspective, whereas that would be the "typical end-user" (content author/editor/publisher) in this case. But even from that perspective, I don't know what I'd expect... On one hand, I'd of course expect something to be rendered. But on the other hand, I clearly configured the field to not render anything at all. But alas, I may not be the entity/field administrator on the site, so I don't even know how the fields are configured. In turn - if there is no visible (i.e., hidden) default config for the field I'm referencing, then I guess I'd expect that some sane defaults are applied.
In any case, I think the field macro tag should always allow me to supply the formatter + settings for the formatter to explicitly specify the formatting.
So the question boils down to the case in which I'm not specifying a formatter at all. In that case, I'd expect reasonable defaults. However, I'm not sure whether Field API has any concept of a default formatter + default formatter settings in the first place. So. If that concept exists, let's leverage it. If not, let's punt on that and just render nothing.
Comment #25
Anonymous (not verified) commentedI've made fixes with help of Coder module, I've even fixed comments ;)
Hope codes is better now. I'must investigate the 1) point from #23 to advance more.
Comment #26
sunThank you! Here are the remaining coding standards/style fixes. :) I didn't commit them directly, as I didn't want to potentially produce a push conflict with your ongoing local changes.
Comment #27
sunre #22:
1) We definitely need to support previews. :) The current code uses explicit ID references, and for the entity preview case, it uses the special value 0 (zero) to refer to the (new) entity that is currently being added/edited. I think that makes some sense.
2) Yes, the tracking table's primary purpose is to answer the question of "Is this piece inlined anywhere and if so, where?" A primary use-case for this information is indeed a confirmation before deleting an entity; e.g., to ask the user whether he really wants to delete (and thus potentially "break" the expected content in some other entities/fields). And in the long term future, I could also imagine a dedicated site report page that performs a site-wide lookup and validation of inline macros and tells you whether any became stale.
Comment #28
Anonymous (not verified) commentedDo you use some tool for checking coding standards? Coder didnt gave me those warnings at all....
Comment #29
Anonymous (not verified) commentedDefining #23 is top priority for me now.
If i want to inline some field on the node body text, and the field itself is also displayed before/after that body, it does not make sense to me (an area is completely duplicated on the page). Also, i like the idea of configuring the display for the field on its settings, and not doing a 'force display inside inline module' for that field just cause it was inlined...
I think 2 options by now:
Comment #30
larowlanNote also wysiwyg_fields which I think grapples with similar problem.
Comment #31
sunre: #23 / #29:
Good point. My current stance/consideration would be this:
I.e., these do not affect the rendering/output of the remote field/entity/whatever at all:
I.e., this does not affect the regular/configured output of the referenced field, because it uses a custom formatter (and possibly even custom formatter settings):
I.e., this affects the regular/configured output of the referenced field, because the field gets essentially inlined/embedded into the content already:
The technical way to handle this would probably be to set a flag on the $entity or possibly when the referenced field within the $entity, to prevent it being rendered when it would normally be rendered.
E.g., something along the lines of this:
Usually, many/most fields are set to hidden for the teaser view mode. So my above assumption that we could make this decision based on whether a formatter and/or settings have been specified might not work out, because when viewing a node as teaser and referencing the image field on it that is set to hidden for the teaser view mode, then the default formatter would actually output nothing...
In turn - unless we can come up with a different and really intelligent/smart solution - this likely means that we always have to specify the field formatter (and possibly even all required formatter settings) in all macros that reference a field. Whether to render the original field (on the same entity) or not can only be controlled by the additional render_original parameter, which would use a sane default (most probably 0; i.e., muting the original field).
Note: hook_page_alter() is way out of scope for Inline API. If we need to defer the macro expansion to a later point in time, then the last possible time would be hook_entity_view_alter(). For now, the goal should be to always stay within the entity/field context.
Comment #32
Anonymous (not verified) commentedCommited changes according to ideas from #31
What works:
Also i must point, i had to use node_view instead of the commented propossal node_build_content, because of the logic for removing duplicate fields (render_original=false option)
Now i would love to define how we do this use case:
With
[field|type=node|id=X|name=field_image|render_original=false]now we can render a simple image. but if i want that image to be rendered as a link? (as it was in previous inline code) Also, i would want to solve the need for the rel="lightbox" integration in the same solution.If "formatter=X" argument is the way to follow, we must then define some formatters right inside inline, which in time can use drupal default formatters inside? For example, if i write:
[field|type=node|id=X|name=field_image|render_original=false|formatter=lightboxlink]then we can haveinline_lightboxlink_formatter_view(), which calls the defaultimage_formatter_view()on the field, and then wraps that output in an anchor? Just an idea... waiting better ones from sun!Comment #33
sunSounds great! (Didn't have a chance to look at the code yet.)
The built-in 'image' formatter of Image module has settings for the image style to use as well as basic link options already. We're primarily interested in the former.
That said, we could leverage the existing, basic link options of the image formatter to form_alter/inject a new, custom setting that allows to specify a custom URL and stuff. However, that's very custom and advanced already, so I'd prefer to leave that for later.
Back to your primary concern - and this is where this entire concept starts to shine :) - check Lightbox2 module:
http://drupalcode.org/project/lightbox2.git/blob/refs/heads/7.x-1.x:/lig...
Apparently, it seems that module badly needs some help, since its entire code-base looks horrible with tons of commented out code... not even sure whether it works... But anyway, if you want a lightbox, use the lightbox formatter:
(Lightbox2 developers do not seem to be aware yet that formatter settings are possible ;))
A better example would be Colorbox:
http://drupalcode.org/project/colorbox.git/blob/refs/heads/7.x-1.x:/colo...
Its formatter settings needlessly duplicate "colorbox_" all over the place and generally aren't very intuitively named, but regardless of that, you can specify all the fancy dancy options :)
(wrapped for clarity)
Comment #34
Anonymous (not verified) commented@sun: i' m almost there. Formatter selection is in place. Now i want to pass some settings. Please give me a hand con the #multiple setting for macro arguments?
I dont think this maps to current macro structures:
Because arg "colorbox_node_style" is not defined on the inline_field_args() hook. I dont think we must get "any unknown" argument as a formatter setting by default if that is the idea (no magic at all as you posted)
I' m thinking of a generic "formatter settings" argument, which is some kind of array? So that is why i' m asking you about the #mutiple setting on the macro argument info.
May be something like:
|formatter=image|formatter_settings={setting1=value, setting2=other}Any advice ?
Comment #35
Anonymous (not verified) commentedAn idea, for easier integration with other tools/modules, we can use json notation there:
|formatter=image|formatter_settings={"setting1":"value", "setting2":"other"}If u like it, i implement it, using the #mutiple flag right?
Comment #36
sunNote: I'm committing some changes and clean-ups.
Comment #37
Anonymous (not verified) commentedCommited formatter & formatter_settings first bits ;)
http://drupalcode.org/project/inline.git/commitdiff/191cac9cd8c68ec6ff01...
Waiting for #34, #35 directives from @sun
Comment #38
sunAlright. Lots of clean-ups. First stab at solid tests. They're very basic and definitely need to be rewritten at some later point, but for now they should keep us in good shape while we're adding new assertions.
TDD (test-driven development) has proven itself, not only for explicitly thinking about and clarifying hard-coding expectations right from the start, but also to avoid repetitive manual testing of the identical functionality.
Especially for modules like Inline with its parametrized macros, the amount of possible test scenarios and test cases very quickly becomes so massively large that it's close to impossible to test the full stack manually. Even with the very basic code we have right now, it wasn't possible to cover all scenarios/cases yet.
That said, the current tests are failing - due to some weird handling of the text format for the summary of a node body field in teaser view mode. Essentially, despite having a text format assigned that allows URLs, the summary appears in plain-text. I'm not sure what the problem is and can't really believe that this is a bug in core as that sounds a bit hilarious. I suspect it's our own code that hi-jacks the field rendering.
In any case, we should try to get that fixed, so tests are passing (again). My own general rule of thumb is that I always run the tests to make sure they're still passing, before committing a new change.
I'd recommend us to do that :)
Regarding parameters for formatter settings:
The current inline macro syntax does not really support nested sub-keys. IIRC, I once implemented code that allows the #multiple flag for a parameter to work, but as the name implies, that only means multiple values, not nested keys.
That said, it is possible that PHP $_GET HTTP query parameter alike structure would work, since I think I once refined the macro parser regex to make it not error out on brackets within brackets; e.g., this might work:
In general, that question actually hits the macro syntax topic and problem space though. I will say that it is entirely possible that we're going to change the syntax to a completely different format. Previous discussions on that topic in the past mainly played with the idea of replacing it entirely with JSON, based on the idea and main benefit that JSON supports at least some data types natively and can also be parsed in the front-end; e.g.:
However, it must also be said that JSON has its own problems as serialization language.
And now that I said the above, a pure URI standards based syntax would even be possible, too; e.g.:
i.e.,
[path?query=string];) Equally simple to parse. :)But all of that being said, I'd prefer to defer this topic entirely to later, if possible.
For now, I'd just simply put (merge) the parameters for the formatter's settings on the top-level parameters. Yes, I'm aware that this means potential name clashes, but as mentioned, the serialization language/syntax is a very big topic on its own, which I'd like to discuss with others first, so as to move into the right direction. I think we can punt on that topic for now and focus on the main architecture and entity/field integration instead to make that fully work. Once there's an agreed-on direction, the actual switch to a different macro syntax/format is a very small step compared to that (alas, in both of the above cases, we'd simply replace ~100+ lines of code with a single line ;)).
Comment #39
Anonymous (not verified) commentedImplemented very basic formatter settings: pass every macro parameters as a possible formatter setting
Comment #40
sunI think we're making very good progress. :)
For everyone else following at home: @Javier and I are collaborating over IM/Skype to eliminate the comment/reply lag. The latest code lives in the 7.x-2.x-field branch. Comments are highly welcome! :)
The revamped module code requires the Class Loader module, which is a 1:1 backport of the PSR-0 class loader in D8. ["D8" is the keyword here ;)]
The code looks extremely appealing already and tests confirm that the basic functionality works. I just committed another round of clean-ups.
The next steps we should focus on:
A) Untangle ::getParameters() from a UI/form definition, or B) turn ::getParameters() into ::getForm() and ::validate() into a #element_validate Form API callback.
I'm not yet sure which direction is better and more appropriate. Technically, the pure macro processing does not need the overhead of the extra definitions for parameter labels, descriptions, etc.
OTOH, when splitting parameters and the form/UI definition, then there's a high chance we'll end up with a considerable amount of "duplicate" validation code. The bare macro processing and validation basically follows the rules of Form API anyway -- it processes user input for a set of predefined elements. We will need form constructors and form validation at some point either way, so users are able to construct and embed a macro through the UI (within a Wysiwyg context, ideally without actually seeing the raw macro string at all).
Comment #41
Anonymous (not verified) commented5, 6, 7 and 8: Much more 'advanced' for me now.... leaving for later discuss :)
Comment #42
Anonymous (not verified) commented3. Done & pushed
Comment #43
wim leersVery nice progress indeed! Thanks, Javier, for pushing this forward! :)
Comment #44
Anonymous (not verified) commentedYour welcome Wim! It is my pleasure to code for Drupal.
Anyway, i would love more people getting involved, at least with discussing ideas or give some fresh ones. I'm available for coding those ideas and pushing forward this and anything else i can help.
Hey sun: I'm waiting for more directions to continue. Cheers. (4. from #40, #41 maybe?)
Comment #45
sunFWIW, this code has been merged into the 7.x-2.x mainline. :)
Comment #46
Anonymous (not verified) commented@sun: Patch to current 7.x-2.x-field.
Comment #47
andypostекфшдштп-цршеуызфсу
Comment #48
Anonymous (not verified) commentedFixed code is already on 7.x-2.x-field , please ignore patch from #46
Comment #49
sunSo... in another chat about Edit/Wysiwyg-in-core today, @Wim Leers described the "ideal macro system architecture." He wasn't really aware of the actual Inline API 2.x code.
What he wrote down happens to be exactly the architecture of Inline API. ;)
So I went ahead, polished his description, enhanced it with some first documentation about essential architectural design decisions, and committed that to the README. (This can and should be improved later; some of it might rather belong into inline.api.php even.)
Comment #50
wim leers:)
An interesting consequence is that the http://drupal.org/project/token_filter module should now just become an API implementation of the Inline module…
Q:
- Is Inline core-worthy?
- What about existing "macro filters" that are implemented as filters?
- Because this is not part of the filter system, it automatically becomes impossible to apply filters to the rendered/expanded macros of the Inline module. So, using e.g. http://drupal.org/project/caption_filter becomes impossible. Captioning images is (arguably) a much-needed feature, for Inline module to be as attractive as possible it also needs to support that. How do you propose that would work?
Comment #51
Anonymous (not verified) commented@Wim: I think we are expanding macros just through the drupal system. I think that way the filters are applied as usual?
Suposse field B has filters, where i use the mentioned token_filter and write something like [user:name].
Then in field A i embed that field B, it gets embedded by calling field_default_view, which goes through all drupal modules (including filter) and the output already is filtered at the moment when it is embedded in field A.
Comment #52
wim leersThat's not what I meant. I'll give a stupid example:
Input:
Filtered (filters: filter_autop, an image caption filter that transforms the title tag into a caption):
Macros applied in hook_field_attach_view_alter():
But I wanted:
Comment #53
Anonymous (not verified) commented@sun: We should solve #52 next, right?
BTW, 7.x-2.x-parser branch already contains the shiny new HTMLParser, JSONParser and URIParser (also DefaultParser is the container for the already working syntax)
Please review and point me any advice.
Comment #54
wim leers#53: It's impossible to solve. If you use macros, you can't apply filters to the result of macros. IMO the best you could do is offer the ability to *extend* macros, i.e. add attributes, so you can add any kind of functionality :)
Comment #55
sunMerged the 7.x-2.x-parser branch into 7.x-2.x :)
Will have a look at the new tests in the -field branch shortly.
Next step: #1787066: Port to D8
Comment #56
Anonymous (not verified) commented@sun, i want to begin using 7.x-2.x on my site (www.nexion.com.ar), my doubt is: how can i render for example a field which has multiple values, choosing the index to render.
Example: i have a blog content type which has a field_image, multiple values, which i use to attach lots of images for that blog page. Then i want to render those images on different places. I remember the syntax was something like:
[field|name=field_image|id=0|formatter=colorbox| ... extra |params |are |formatter |settings... ]
So i would like to embed the first image at top... then some text, then embed the second image there... some text.. third image at bottom...
It is possible right now? Do we need some special parameter for that?
Cheers.
Comment #57
Anonymous (not verified) commentedAlready solved with a new colorbox formatter setting :)
Comment #57.0
Anonymous (not verified) commentedUpdated issue summary.