Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
node system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
4 Jul 2015 at 04:34 UTC
Updated:
28 Jul 2015 at 07:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
daffie commentedFirst try with the class variable $in_preview set to protected.
Comment #2
dawehnerIn case you think this is justifyable, this needs a CR.
I'm quite sure that for example @xjm would push that back.
Comment #3
berdirThis was done by design in #2498919: Node::isPublished() and Node::getOwnerId() are expensive to document an existing, used property. Defining it as a public property allows for a considerable performance improvement.
I really want to do that to the original property as well, it's better to have a documented public property than one that is not but is still used.
I'm OK with adding methods but I'm against making it protected, that's an API change and we're definitely past the time where we can make API changes just because it's cleaner.
Comment #4
daffie commentedThanks for you replies dawehner and Berdir.
I have left the variable $in_preview public, because of:
The patch now only adds the two getter and setter functions and an extra comment by the definition of the $in_preview variable why it is a public one.
Comment #5
mile23Nice comments added here... But since it's public, this docblock should tell us what value corresponds to what state. Especially since it's not TRUE|FALSE but is instead TRUE|NULL.
Also, the getter and setter never handle NULL, so is the @var annotation correct in the first place?
Again, the interface docs don't match up with the property docs, making no mention of NULL.
So, basically: Let's find out why that NULL is documented in there, and whether it's erroneous.
I'm also inclined to say the property should be completely encapsulated as protected, but @berdir has spoken. :-)
Comment #6
daffie commented@Mile23: Thanks for your review! Let me begin by stating that I fully agree with you. And I have no idea why they those for TRUE|NULL instead of TRUE|FALSE.
I am working on closing the #2016679: Expand Entity Type interfaces to provide methods, protect the properties and for me that is making the variables protected or getting the maintainers approval to let them be public. In the patch there is only the comment added that the variable will stay public and why.
Comment #8
daffie commentedSome how there was something wrong with my previous patch?! :(
Comment #9
naveenvalechaRTBC +1 if green. Already discussed about the in_preview to be public in the issue.Do we need update at other place in Documenation ?
Comment #10
berdirIt is TRUE|NULL for BC.
There is code that's checking it with isset($node->in_preview). That is TRUE if the variable is FALSE.
Comment #11
mile23Yah, that's why we should look it up and find out and then know. :-)
It turns out there are a few places where we see things like
if (empty($node->in_preview)), such as this from statistics.module:That's exactly the sort of unreadable junk we're trying to avoid by encapsulating in an object. But... There we are. :-)
Anyway.... That sort of code will work with either FALSE or NULL, since PHP allows that.
So:
Add to the property docblock that $is_preview should be TRUE if the node is being previewed, NULL otherwise.
Comment #12
googletorp commentedI improved the english a bit in the comment. Otherwise looks good.
#10 + #11 Lets not scope creep this issue.
The issue is about missing documentation, not actually changing the actual usage of the in_preview variable. That should be handle in a separate issue.
Comment #13
googletorp commentedComment #14
googletorp commentedComment #15
mile23It's not scope creep.
Since we're not doing for-reals encapsulation, we need to document the behavior so that it's clear.
Comment #16
daffie commentedAdding the line to document better the behavior of the variable $in_preview.
Comment #17
googletorp commented#15 I see I misread your comment, my bad and I agree.
Anyways, we added the the description in the docblock, so looks all good now.
Comment #18
mile23Cool, thanks. RTBC +1
Comment #19
alexpottCommitted b843b4a and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.