Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The build method of BlockContentBlock uses procedural functions as follows
url
entity_view
entity_load_by_uuid
Proposed resolution
Inject the dependencies and implement ContainerFactoryPluginInterface then remove the procedural cruft
Replace url with UrlGenerator
Replace entity_view with EntityViewBuilder->view
Replace entity_load_by_uuid with EntityManager->getStorage()->loadByUuid
Bonus points: write a phpunit test for the build method
Remaining tasks
Patch
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#7 | Cleanup-BlockContentBlock-2342949-7.patch | 3.04 KB | rpayanm |
#2 | Cleanup-BlockContentBlock-2342949-2.patch | 1.19 KB | rpayanm |
Comments
Comment #1
rpayanmComment #2
rpayanmComment #4
rpayanmComment #5
larowlanThanks, but this isn't what I was chasing
using \Drupal is no better than using procedural functions. We need to implement ContainerFactoryPluginInterface and inject the dependencies - updated the OP to make it explicit.
Comment #6
larowlanthis expects 'block_content' not $block for getViewBuilder - thats why the tests fail
Comment #7
rpayanmSorry for that code :) I am a novice and thank you for the comments ;)
Comment #8
larowlanThanks @rpayanm - awesome work!
No need to apologize.
Comment #11
larowlanComment #13
rpayanm