Closed (fixed)
Project:
Viewfield
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 Feb 2011 at 01:13 UTC
Updated:
6 Dec 2011 at 20:59 UTC
Jump to comment: Most recent file
Comments
Comment #1
keithm commentedMoving this item to the 7.x branch.
Comment #2
keithm commentedtheme_viewfield_select() and theme_viewfield_formatter_default() are gone.
theme_viewfield_select() only existed to provide a bit of css to ensure that help text for multiple-value viewfields wrapped correctly. It has been replaced with a small addition to the field settings form render array. I was tempted to turn to inline css here but I don't know any guidelines for this sort of thing so I left it as a file include.
theme_viewfield_formatter_default() wasn't a real theme function, consisting primarily of data access operations. The data access part has been relocated, and the theme part has been removed since D7 core provides field-level theming support already.
Comment #3
keithm commentedOne other note: because the D7 branch pushes to
$_viewfield_stackbefore token replacement (this is reversed in 6.x), it is unnecessary to perform an addition recursion check within token replacement. See how$replacing_tokensis used in the old_viewfield_get_view_args()vs. the new_viewfield_get_token_values().Comment #4
keithm commented@sun Do you have time to review this? I'd appreciate it.
Comment #5
sunI like the other changes concerning the theming/rendering, but I think we should keep this consistent with other field formatters and use a theme function.
In D7, we can offload the heavy technical preprocessing into a template_preprocess_viewfield_formatter_default() function, so the actual theme function can only deal with theme variables, as usual. This also allows us to provide the raw $view object as variable to the theme function (by assigning it in the preprocess function).
In the end, each item should use the #theme property (instead of #markup).
It looks like we're storing the args as a comma-separated string? We should store the args in a way that's ready for usage; e.g., a serialized array.
The field widget then has to care for imploding/exploding those args in whatever way makes sense for it. (In the long run, we should replace that textfield with a #ajax-driven widget that allows to enter the individual args into separate textfields or whatnot.)
I additionally have the impression that this argument parser can be heavily simplified by using a combination of strtok() with preg_match(). It's also looking extremely complex, so we should add unit tests for it. While d.o doesn't allow us to test functionality depending on third-party modules yet, we can definitely write tests for low-level helper functions like this. Do you know how to write tests?
I'm not sure whether this entire function makes sense -- it looks like premature optimization to me - whereas it's not clear to me whether entity ID token replacements are able to work without a properly loaded entity.
Additionally, since these tokens are used within the context of a field of an entity, it's very likely that the entities referred in the tokens have already been loaded through other means.
In the end, I'm not sure whether this optimization makes sense, and whether it really buys us a huge performance gain -- compared to the possible bugs it might cause.
Also, minor: Duplicate leading space in the phpDoc.
Powered by Dreditor.
Comment #6
sunNote: I've added a test file + also cleaned up some other minor stuff: http://drupalcode.org/project/viewfield.git/commit/093c3d0
Comment #7
keithm commented@sun Thanks for your review.
I had looked at retaining the theme function but in the end discarded the idea for three reasons. First, core fields (number, list, text) don't use them, they go straight to #markup. I thought if it's good enough for core, it's good enough for viewfield. Second, themers have field.tpl.php and views*.tpl.php available already. Third, I experimented with a theme function and ended up with a function that did nothing but call
drupal_render(), which didn't seem very helpful. (Calling drupal_render seems like the only good option because views can't produce a render array, just markup (see http://drupal.org/node/1096286), so the input to the theme function looked likearray('content' => array('#markup' => '<views stuff>')).I might change my opinion about this though if we decide enhance viewfield to include the view title in the output (see #281409: Show view title in viewfield output).
$view->preview()doesn't supply it, and while it's easy enough to dig the title out of the view, there would be viewfield specific markup to handle it, and we would want to allow themers to override that markup. In addition to a theme function, including the title would require some sort of administrative interface to at least enable/disable it. Certainly if we support a theme function, the formatter should use #theme rather than #markup.Thanks too for the tip on template_preprocess_viewfield_formatter_default(). I think the new Drupal slogan should be "Drupal: We Think of Everything." (Though as a core developer you might not agree!)
Having gotten all this out, I suppose it wouldn't be a bad idea to continue support a theme function in case we need viewfield-specific markup in the future.
Yes, though I've tried to keep the changes in this patch limited to the rendering structure. How about handling this in a separate issue?
I've used TDD in java and .net but not php or Drupal. From what I've seen it doesn't look too hard. Adding some unit tests probably makes sense. (From what I've seen however, the prospect of creating the views, nodes, and tokens to thoroughly test viewfield looks like a significant piece of work.)
Well that's interesting. I've observed that entity ID token replacements are able to work without a properly loaded entity but I don't know that's guaranteed in all cases. I'm not even sure how to find that out. In the end
_viewfield_token_requires_load()smells a little strange, and if indeed it doesn't produce a significant performance gain I'm fine with losing it if you want.Comment #8
sunComment #9
sunComment #10
sunPosting my patch from #1216684: Merge include files into .module, since it probably makes sense to just deal with the include over there, and do the heavier render lifting here.
Comment #11
sunRe-rolled against latest branch HEAD.
Comment #12
sunsorry, lost a hunk
Comment #13
keithm commentedIn #11 it looks like the old version of theme_viewfield_formatter_default() was left in.
This should read:
I took a crack at this since theme_viewfield_formatter_default() should be open to modification by themers, and we want to keep private functions out of it anyway.
Comment #14
sunActually, #access should just simply be the value of $view->access() - i.e., we unconditionally add the $view.
The downside of this is that we're always extracting/parsing the args, but we need to store those serialized anyway, and as soon as we do that, it's no longer an issue.
Comment #15
keithm commentedBTW, nice patch :)
In #13 that is the value of #access: FALSE unless $view is defined and $view->access() is true. We could also go ahead and add the $view even if access is denied, but no one will ever see it. I NULLed it out because of consistency with argument handling (see next).
_viewfield_get_view_args() is misnamed. It not only parses the argument string, it also performs entity loading and token replacement. If access is denied, we shouldn't do those things, which is why I gave $views_arguments a NULL value under in the no-access case.
Am I missing something?
Comment #16
sunIn that case, let's directly assign 'vargs' as #view_arguments and do a delayed argument loading in the #pre_render? (replacing #view_arguments)
Comment #17
sunso... attached patch incorporates the last comments, and also...
makes "viewfield" available as a stand-alone element #type :)
Comment #18
keithm commentedCool!
Have to actually get the view :)
This still has to be conditioned on nonempty valid entity_id.
Has to be conditioned on nonempty entity id.
Otherwise looks good to go.
Comment #19
sunwrong status then? ;)
Note that #entity_id can be NULL, and that's perfectly fine:
Comment #20
sun...and just to double-confirm, we're also not hitting a PHPWTF ;)
Comment #21
keithm commentedWell, it's really a question of semantics. We're using the entity id to uniquely record the presence of an entity in the viewfield rendering process. NULL isn't really suitable for that job unless we can argue that there will only ever be at most one entity being previewed at a time, and thus that NULL is it's (temporary) unique identifier. Even if we can make that argument I somehow think the logic is clearer with the !empty() checks :)
Comment #22
sunOk, short form is: I starred like 5 minutes at #pre_render and tried to think of the proper conditional logic to perform when special-casing NULL, in which case we want to render, but skip the stack, but also perform argument loading/replacement ;) If you can figure that logic out, be my guest :)
Comment #23
keithm commentedI stared for more than 5 minutes :) and concluded it would considerably hair up #pre_render for practically no benefit. So... attaching your latest patch with a tweak: $view assignment in viewfield_field_formatter_view().
Comment #24
sunheh, thanks! :)
Comment #25
keithm commentedCommitted: http://drupalcode.org/project/viewfield.git/commit/9c7fcfd.
Comment #27
zloutenka commentedRight now, is there a way how to display the view title in the viewfield? Even a hackish one... Would have to use some ugly jQuery magic if not.
Thanks in advance,
zloutenka
Comment #28
keithm commented@zloutenka: Please check #281409: Show view title in viewfield output for this issue.