This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » eZ Publish 5 Platform » How can I match against an embed class?
expandshrink

How can I match against an embed class?

How can I match against an embed class?

Wednesday 11 February 2015 4:43:51 am - 7 replies

In ezp 4 you could have

<span>[embed]
</span><span>AvailableClasses[]=month_view_event_calendar
</span><span>ClassDescription[month_view_event_calendar]=Month calendar</span>

and use a separate embed view for this class.

How do you accomplish this in ezp5?  There is no matcher for the class.

Thursday 12 February 2015 7:41:34 pm

This was a nice feature in eZ Publish 4. I too would like to know how to handle it.

Although you can set the class of the embed in eZOE so it should exist in the internal XML, it is lost by transformation in eZXml2Html5_core.xsl (see https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Publish/Core/FieldType/XmlText/Input/Resources/stylesheets/eZXml2Html5_core.xsl#L181)

The stylesheet processes the 'class' attribute for some tags such as <p>, but ignores it for <embed>.

For the simplest case (the class just drives some CSS or Javascript) I think the approach is to override eZXml2Html5_core.xsl and make it include the class when it converts <embed> into HTML5.

In your case you want to do more interesting work and need to access the repository so my guess is you need to create and register a Pre-converter as described at https://doc.ez.no/display/EZP/How+to+implement+a+Custom+Tag+for+XMLText+FieldType

This would entirely circumvent the need for an override.

Do you think this is the appropriate way to handle it? It's on my list of ideas to try out but not near the top so let me know how you get on.

Or are there some experts out there with time to put me on the right track?

Thanks!

Andy

Friday 27 February 2015 5:06:49 am

That may be the correct way.  At the moment I now have extended the content controller for embedded content and grab the template to use based on the class passed in the parameters to the controller. 

Tuesday 03 March 2015 1:20:12 pm

I'm rarely sure what is the 'correct way' in eZ Publish 5. No doubt over time a body of "Best practice" will build up. Your method sounds appropriate because it is simpler and (I guess) requires less sub-requests. How did you pass the class from the embedding content's XML block into the controller? Would you be able to share your code? I'd really appreciate that.

Tuesday 03 March 2015 4:31:04 pm

The embedded content parameters get passed to the controller in $params['objectParameters']

Some of interest may be:

 public function showEmbedAction( Content $content, $viewType, $layout = false, array $params = array() ) {      
        $params['objectParameters']['class'];
        $params['objectParameters']['size'];
        $params['objectParameters']['offset'];
        $params['objectParameters']['limit'];
        ...

Saturday 14 March 2015 1:44:29 pm

Hello there. Interesting conversation.

If anybody's willing to implement this in the kernel, feel free to. I can try to answer questions if any (or go hunt the answer down).

I'm not very experienced in that particular layer, but I'd think that as long as there is a sub-request, we should be able to use the View Provider config (override). Unless I'm missing something, we could add a custom matcher, like Embed\ClassAttribute or something. I'm not saying it's simple, but it doesn't sound impossible.

Once we have that, as long as the stylesheet sends the argument along, and as long as it is available for the View Provider, we should have a working thing. Does it sound like a way to you guys ?

Saturday 14 March 2015 2:23:54 pm

I believe a matcher would be most appropriate.  I looked at implementing one myself, the issue if I remeber right is that the objectParameters are not available to the matcher as they are created when the xml from the filed of the content object is processed.

Currently I use another matcher specific to the embed object I want and use my custom controller that then used the objectParameters to select the correct template etc.

Saturday 14 March 2015 2:49:59 pm

Doing this from the controller is clean enough. But I'm really thinking that it would be cool if this could be native... I'm just not sure what the implications are in terms of performances, since this would require that the ViewManager reads the Content from the database.

But I can definitely see use-cases to this...

About what is sent from the XML, I'm sure we can figure that one out happy.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from