-
Notifications
You must be signed in to change notification settings - Fork 43
improve granular rendering #29
Comments
The following GIST can help to identify the problems linked to the duplicate about attribute: https://gist.github.com/4328016 Problems identified:
|
@adou600: I'm not sure I understand: The gist you linked was rendered by current CreatePHP? If so, could you also post the corresponding PHP or Twig template? Because AFAICT the duplicate about rendering should be fixed since 4060055, so it would be interesting to see if there is a case we missed. the problem with owl:Thing sounds like bergie/create#122, which also has been fixed recently, so maybe, your installation is just slightly behind the times |
@flack: yes, I use the latest createphp, the changes of 4060055 are present in my vendors. I added the twig template and the rdf-mapping in https://gist.github.com/4328016. The special case here is that we have a CollectionPage (with title and description) containing the list of all NewsArticle. The owl:Thing problem is indeed solved for usual cases. But it appears in addition to the real type (CollectionPage in our case), only when the description or title of CollectionPage is modified. |
Looking at your code, I'm a bit unsure about https://gist.github.com/4328016#file-sandbox-mainbundle-document-newsarticle-xml-L9. IIUC, the rev has to be added to the parent type definition, not to the child one, but I might be wrong, @dbu knows this better than I do. But at least in my demo setup, I have rev at the parent entity and it works without problems |
About owl:Thing: @bergie metioned to me once that typeof is a multivalue field, so it might be that it is by design that generic and specialized types are sent in one go. But then again, maybe it's just something that happens because Create.js misinterprets your HTML... |
Looking at your twig, it's kind of unavoidable that the about attribute gets rendered twice: the detection code from 4060055 can only work if you render at least the property's start and end tag through CreatePHP API, but in twig, you only render the property's attributes and content. So createphp has no way of knowing if a collection is rendered inside of a parent container (since the opening/closing HTML tags are hardcoded in the template). It would have to look something like this for the duplicate detection to work: {% createphp cmfMainContent as="rdf" %}
{{ createphp_render_start(rdf) }}
<h2 {{ createphp_attributes( rdf.title ) }}>{{ createphp_content( rdf.title ) }}</h2>
<p {{ createphp_attributes( rdf.body ) }}>{{ createphp_content( rdf.body|raw ) }}</p>
<ul {{ createphp_attributes( rdf.children ) }}>
{% for news in cmf_children(cmfMainContent) %}
{% createphp news %}
<li {{ createphp_attributes(news_rdf) }}>
<a href="{{ path(news) }}" {{ createphp_attributes(news_rdf.title) }}>{{ createphp_content(news_rdf.title) }}</a> ({{ news.publishStartDate | date('Y-m-d') }})
<div class="newscontent" {{ createphp_attributes(news_rdf.body) }}>{{ createphp_content(news_rdf.body) }}</div>
</li>
{% endcreatephp %}
{% endfor %}
</ul>
{{ createphp_render_end(rdf) }}
{% endcreatephp %} Of course, the functions createphp_render_start and createphp_render_end don't exist right now in CreatephpExtension, but I'll open a new ticket for that |
About https://gist.github.com/4328016#file-sandbox-mainbundle-document-newsarticle-xml-L9, the reverse mapping is needed in the child, at least if you want to create new content with PHPCR ODM. If I get it right, it was one of the goal of #34. If you put the rev only in the parent, the RestService::_handleCreate will not be able to get the parent, by mapping the dcterm:partOf in the vocabulary to get the subject. If needed, maybe @dbu can confirm or precise that? |
I'm not sure to get the goal of createphp_render_start and createphp_render_end tags. What would they do exactly? Output the div containing the collection: https://gist.github.com/4328016#file-example-news-html-L74? Couldn't it be included into |
The problem is that if you look at these two cases:
In the first case, the ul should not have an about attribute, but in the second case, it needs it. But if you only call render_attributes, createphp has no way of knowing whether the property is rendered inside a parent node or not. I'm not exactly sure what {% createphp cmfMainContent as="rdf" %} does, but if it doesn't output an HTML node with the correct attributes, it won't help. Create.js takes its information from the DOM tree, i.e. if the collection UL does not have a parent node with an about attribute, it needs the about attribute itself. render_start and render_end set the isRendering flag in the entity's representation, so that by the time we render a collection, we know if it's rendered inside of a parent node or not. The render_attributes call can't decide that, the only thing we could do is give it a second parameter where you can explicitly suppress the rendering of the about attribute. In plain PHP, you could also do the following: <div class="newsoverview" <?= $rdf->renderAttributes() ?>>
<h2 <?= $rdf->title->renderAttributes() ?>><?= $rdf->title->renderContent() ?></h2>
<?php
$rdf->children->unsetAttribute('about');
?>
<ul <?= $rdf->children->renderAttributes() ?>>
<?php foreach ($rdf->children as $child)
{ ?>
<li <?= $child->renderAttributes() ?>>
<!-- output child data -->
</li>
<?php } ?>
</ul>
</div> but I guess this goes against the twig design philosophy a bit, since you would (non-persistently) modify the entity during the output phase |
Regarding your other comment: When I look at the code, I think your assumption is correct. but the strange thing is, in my demo setup, it only works if I set the rev on the parent type. But I think that's really a problem in my demo site somewhere... |
i think this needs nothing new on createphp class level (there is a method to just render the start tag without the whole properties and collections, right?) - but needs extending the twig extension. would that make sense? shall i sit together with @adou600 and see if i can explain him how this can be done? |
@dbu: Yes, I agree that the attributes call gives the designer more flexibility, but like I mentioned in the example two comments above, the getAttributes call cannot detect if it is called inside a parent container (see the two examples for why it's impossible), so with get_attributes you will always have the duplicate about attribute, unless you remove it manually from the object before rendering the attributes. @bergie mentioned once that the duplicate add button for two nested about attributes is actually considered a bug in VIE, so maybe the problem could be resolved this way, too |
what i wanted to suggest is that we change the twig extension to by default render the opening and the closing html tag and optionally disable that for the flexibility, but in that case still tell the entity being rendered that it should consider itself being currently under rendering. maybe just call the opening tag method but not output the result. |
@dbu @flack FYI and to illustrate the case discussed, the second problems explained in #29 (comment) (news added displayed twice) can be seen here: https://saucelabs.com/tests/b91e2610a5284dc0a6ae37b208d8c41c CSS code has been written to hide the duplicated add buttons. This is the reason why you can see only one button in the video. But there are actually 4 add buttons. About the last problem (modifying the NewsCollection page), the issue can be seen here: https://saucelabs.com/tests/91a24f3bed434629b1053ac4933f55ac. I think these problems will be affected by the corrections discussed here. So I'm ready to try! :-) |
follow-up of #27
we should have the hierarchy in the entities and make sure we only render namespaces and the collection about attribute if they are not rendered in the outside hierarchy.
this should even work when using the renderAttributes and renderContent and manually rendering properties and collections of entities.
The text was updated successfully, but these errors were encountered: