Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
book.module
Priority:
Normal
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
9 Mar 2013 at 18:52 UTC
Updated:
29 Jul 2014 at 22:00 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
damienmckennaComment #2
disasm commentedAttached is a patch that migrates book_admin_overview to new-style Controller.
Comment #3
disasm commentedComment #4
damienmckennaComment #5
Crell commentedWe're not actually using the database in this controller, so we don't need this dependency. (Yes, the example on the change notice has it, because I just needed an example.)
However, book_get_books() should turn into a service of its own I suspect. Then *that* can be a dependent service of this controller.
The service that book_get_book() becomes will, I think, have a DB dependency.
Comment #6
Crell commentedComment #7
Crell commentedAlso, stupid me, "route_name" is the key, not "route".
Comment #8
disasm commentedroute -> route_name
Comment #9
disasm commentedremoving database dependency in controller
Comment #10
disasm commentedComment #11
disasm commentedadding return of static() to create method.
Comment #12
Crell commentedbook_get_books() should either turn into a protected method on this class or a separate service that we inject, depending on whether it's useful elsewhere. I think it is, which means service.
That should be an easy enough refactor that we can/should go ahead and do it while we're here.
If you disagree :-), then we should remove the constructor as it's not doing anything.
Comment #13
disasm commentedmoved book_get_books() to a service injected. All book tests passed locally.
Note: I can't remove the book_get_books() method (yet) because it's in use in other callbacks that would fail.
Comment #15
disasm commentedabsolutely no idea how tests passed locally... Attached fixes the syntax error in the controller.
Comment #16
disasm commentedadded an arguments with a Reference to the database in BookBundle.php. Also, tests are passing, because test coverage doesn't cover this callback. It just does a GET on it, but never verifies that the page is okay, so an error page passes.
Comment #18
disasm commentedAdded use PDO to BookManager class.
Comment #19
disasm commentedfirst reroll! That's right, we got one committed a few minutes ago!
Comment #21
disasm commented#19: drupal-book_admin_overview-1938296-19.patch queued for re-testing.
Comment #22
disasm commentedAttached patch merges issue: #1938312: Convert book_render to a new-style Controller. Credit goes to robmc for this!
Comment #23
disasm commentedComment #24
Crell commentedWe don't really have a convention for putting services in \Service at this point. Whether we should or not I don't know, but we can probably skip that for now.
This needs a @var line to specify what the class of the variable is.
Comment #25
disasm commentedAttached addresses comments in #24.
Comment #26
disasm commentedFixed doctags to have full class instead of object.
Comment #27
Crell commentedEr, no. :-) The @var needs to be \Drupal\Core\Database\Connection, so that IDEs can auto-complete it properly.
Eep. No. No drupal_static inside of classes. No.
The way to do that in an object is with an object property.
protected $books;
Then have a protected loadBooks() method, which populates that property.
Then in getAllBook():
if (!$this->books) {
$this->loadBooks();
}
return $this->books;
Same comment here about @var.
Comment #28
disasm commentedattached removes static drupal function from BookManager.
Comment #29
disasm commentedComment #30
Crell commentedIf the bot's happy, I think we're good here.
Committers: Please be sure to credit both disasm and robmc!
Comment #31
aspilicious commentedThere is a space to much
Intendation is a bit off here. Makes it hard to read.
We added a "book_get_books" service but we didn't remove the original code?
Btw, the code is a perfect example how to create services and how to use them in combination with other services.
Great reading material.
:D
Comment #32
bookmarvel commented#28: drupal-book_admin_overview-1938296-28.patch queued for re-testing.
Comment #33
bookmarvel commentedi got this error when i tried to apply the patch:
$ git apply --index drupal-book_admin_overview-1938296-28.patch
error: patch failed: core/modules/book/book.admin.inc:8
error: core/modules/book/book.admin.inc: patch does not apply
Comment #35
disasm commentedRerolled and fixed doc tags and indentation aspilicious pointed out. There's still too many other references to book_get_books at this time to all roll into this one patch, so I left the method there temporarily:
core/modules/book/book.module: foreach (book_get_books() as $book) {
core/modules/book/book.module: drupal_static_reset('book_get_books');
core/modules/book/book.module: drupal_static_reset('book_get_books');
core/modules/book/book.module: drupal_static_reset('book_get_books');
core/modules/book/lib/Drupal/book/Plugin/block/block/BookNavigationBlock.php: foreach (book_get_books() as $book_id => $book) {
I also added a TODO to the doctag for the book_get_books() to remove it.
Comment #36
Crell commentedLet's add a follow-up issue to finish converting from book_get_books() to BookManager, as this can be a great example of "old to new" conversion.
Committers: Please be sure to credit both disasm and robmc! :-)
Comment #37
yesct commentedthis is Contains now
http://drupal.org/node/1354#file
I think these start with \ in comments.
http://drupal.org/node/1353118
So I guess there are some either way.
Symfony:
We can leave this for now I think.
missing @file doc block.
See http://drupal.org/node/1353118
and http://drupal.org/node/1354#file
missing newline?
function does not specify public or protected. which should it be?
class should have a newline before the final closing bracket.
missing newline.
missing newline at end of class.
------
some of this is non-blocking
but the @file is a core gate: http://drupal.org/core-gates#documentation-block-requirements
Comment #38
bookmarvel commentedill make a new patch for those concerns
Comment #39
disasm commentedAttached is a patch fixing coding standards. I guess I need to reinstall drupalcs on this dev box ;-)
Comment #40
disasm commentedforgot to rebase. here's the real patch.
Comment #41
disasm commentedComment #42
Crell commentedComment #43
xjm#40: drupal-book_admin_overview-1938296-40.patch queued for re-testing.
Comment #44
ParisLiakos commentedI am not gonna unRTBC this but we stopped doing this.
Instead remove use statement and turn constant to \PDO::FETCH_ASSOC
Comment #45
webchickYep.
Comment #46
disasm commentedAttached patch makes suggested change in 44.
Comment #47
disasm commentedComment #48
ParisLiakos commentedComment #49
yesct commentedLooks like this patch has the book manager service, so can we just take care of this todo now?
Comment #50
Crell commentedNo, because other code that's not in scope for this patch is also calling that function. That would be unwanted scope creep.
Comment #51
yesct commentedhere is the issue: #1963894: remove function book_entity_view_mode_info in favor of BookManager Service
and here is the patch which fixes the TODO -> @todo standard and links to that issue.
http://drupal.org/node/1354#todo
also updating issue summary.
Comment #52
Crell commentedComment #53
alexpottI know this is a direct copy of book_get_books - but $result2 is a weird variable name when there is no $result1 or $result... how about we change it to $book_links?
Also I think this is an oddly named function since it does not load books at all... it creates an array of book links... but I'm okay with fixes the function names in a follow up.
Comment #54
Crell commentedThis will need rerolling anyway to use yaml services. *sigh*
Comment #55
disasm commentedWow, that was easier than writing the bundle in the first place!
Attached is a patch and interdiff using the new YAML services syntax.
Comment #56
disasm commentedAttached patch and interdiff renames result2 -> book_links.
Comment #57
disasm commented+Stalking Crell so if this goes green can be RTBC'd again.
Comment #58
Crell commentedI have been Stalked!
I'll update the conversion docs, too, since this issue is our example case.
Comment #59
catchCommitted/pushed to 8.x, thanks!
Comment #60
alexpottFor a followup..
I think the commentary can be improved further...
Could be "Manages a list of books."
Could be "The database connection." see Drupal\Core\Cache\DatabaseBackend
"Books Array" not that helpful. How about "Array of books keyed by book id."
Missing type on @return could be
Here's an example of what this method actually returns... isn't it beautiful?
For everyones information... here is an example of the array returned for a single book from BookManager::getAllBooks()
Could be... "Loads books array."
The book manager.
Could be "Injects the book manager."
And missing @return - for example:
missing @param
This method doesn't actually print anything.
Comment #60.0
alexpottadded follow-up issues section and issue
Comment #61
disasm commentedRemoving tags. Crell doesn't need to be stalked anymore.
Comment #62
yesct commentedtrying to unstick the stalking tag.
Comment #63
alexpottThe code cleanup from #60 is being done here #1971206: Cleanup of Book Manager Service
Comment #64
yesct commentedHere is the follow-up #1971412: Improve docs after Convert book_admin_overview and book_render to a new-style Controlleroops. #1971206: Cleanup of Book Manager Service was already made.
Comment #65.0
(not verified) commentedUpdated issue summary.