-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make EntityFieldReflection aware of the book property added by book.module. #523
Conversation
At time-of-writing, the CircleCI Pipeline is failing with "Could not find a usable config.yml, you may have revoked the CircleCI OAuth app." - my gut says this is an upstream issue? |
CircleCI - thanks for heads up, I'll need to see why that broke. Book module - I'm guessing this isn't a computed base field but a generic property set like But we could possibly also fix this via a stub which uses PHPStan's array phpDoc syntax. Something like
This could live on the |
@mglaman thanks for the quick review!
That is correct: it's just a generic property set like
I actually tried this before submitting this merge request, i.e.: I tried writing my own Node stub file in my own project, modifying the stub files in this project, and even adding My impression was that the code in But if you'd like, I can try the stub file approach once more, modifying NodeInterface explicitly. |
You're right. I think another issue captured these reflection helpers override stubs |
👍 Forgive my confusion, but I'm not sure what you'd like me to do next (if anything)! Thanks for your patience with me! |
Oh nothing else needs to be done. I'll review the PR this week |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need isSubclassOf
so that we can account for concrete class of Node
and bundle classes.
Also, we should add a test. I can work on that if you'd like.
Sorry! I forgot about this, I'll make my way back to it this week. |
I have one concern: there are discussions on moving Book to contrib; see https://www.drupal.org/project/ideas/issues/3265493. This extension would then hold on to custom property reflections for just one contrib when many may manipulate node entities this way. Considering this while giving second review |
Okay! I fixed the issue of parsing |
Problem / motivation
As of Drupal 9.5, 10.0, and 10.1, the book module adds a "book" property to Node instances that have been enabled as books.
PHPStan is not aware of this and thus reports messages like
Property Drupal\node\NodeInterface::$book (Drupal\Core\Field\FieldItemListInterface) does not accept array.
Proposed resolution
Tell PHPStan to expect a
book
property on Nodes that is an array.Additional notes
I wanted to be more specific about what's in this array, but I'm not certain how to do that in PHPStan - its API documentation is somewhat minimal. If you have suggestions, I would be happy to update this merge request.
The
book
property is an array that contains the following keys/types:nid
int
(ornumeric-string
)bid
int
(ornumeric-string
)pid
int
(ornumeric-string
)has_children
int
(ornumeric-string
orbool
)weight
int
(ornumeric-string
)depth
int
(ornumeric-string
)p1
int
(ornumeric-string
)p2
int
(ornumeric-string
)p3
int
(ornumeric-string
)p4
int
(ornumeric-string
)p5
int
(ornumeric-string
)p6
int
(ornumeric-string
)p7
int
(ornumeric-string
)p8
int
(ornumeric-string
)p9
int
(ornumeric-string
)link_path
string
link_title
string
... See book_schema() in 10.1.x core for more info. While many of these fields are stored as integers in the database, the book module usually queries them and dumps the query result into the array, and due to the way the database layer works, they come out as strings containing the integers that were stored in the database.