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
Core should not use direct db calls to entity tables because they are managed by the table mapper entity API.
Proposed resolution
All ::query()
call and similar should be replaced with \Drupal::entityQuery()
or with injected entity storage, and updates/deletes should be done via the Entity API.
Remaining tasks
replace all usage
User interface changes
no
API changes
no
Data model changes
no
Comment | File | Size | Author |
---|---|---|---|
#32 | 3015855-32.patch | 3.38 KB | Neslee Canil Pinto |
Comments
Comment #2
mondrakePatch.
Comment #3
mondrakeComment #4
mondrakeActually this one is probably more in tune with the objectives of the test.Edit: incorrect, this is not the logic of the test.
Comment #6
mondrakeI am not really sure what this is meant to test, so it's unclear how to convert this query. Looking at earlier versions, the code used to be
then it was changed to the current version in #1916790: Convert translation metadata into regular entity fields. The first patch doing the change is @ #1916790-76: Convert translation metadata into regular entity fields, but I cannot figure out what the intention was.
Comment #7
goodboyAs I understand it, this test does not verify what is declared.
$enabled_block_content->id()
is not equal$disabled_block_content->id()
and for enabled block the query will be return 1 anyway.And the last test checks correctly but it does not passed. If 4 years ago the current test was correct, we would see the moment when changes were made, after which the test would cease to pass, as is happening now. So it seems we catch the bug of https://www.drupal.org/project/drupal/issues/1916790 and we have to wait until this new test will be passed after the issue bug will be fixed.
Comment #9
andypostThe test should be converted to using table mapping to get table name in this kind of testing to keep logic same
Comment #10
gigiabba CreditAttribution: gigiabba at Ibuildings commentedThis issue should be closed.
Calls to db_query function are already replaced and pushed in 8.8 branch.
See https://www.drupal.org/project/drupal/issues/2875394#comment-13123165
Comment #11
gigiabba CreditAttribution: gigiabba at Ibuildings commented-duplicated comment-
Comment #12
mondrake@gigiabba nope it's a different thing - here we are talking about moving from ::query() to Entity query API. #2875394: Replace all calls to db_query, which is deprecated just replaced db_query with ::query without further consideration.
Comment #13
volegerComment #14
gigiabba CreditAttribution: gigiabba at Ibuildings commented@mondrake so sorry! :)
Comment #15
vacho CreditAttribution: vacho at Skilld commentedThis issue is out of time. Core doesn't have any call to db_query except at the tests that cover it and functions. So I think that this issue can be closed
Comment #16
volegerExactly this is a reason why we need a reroll on this issue.
db_query
functions were just replaced by thequery
method calls on the database connection instance. So the scope of this issue is still the same.Comment #18
neel24 CreditAttribution: neel24 at Google Code-In commentedI've rerolled the patch from #4.
Comment #20
hash6 CreditAttribution: hash6 at QED42 commentedComment #21
hash6 CreditAttribution: hash6 at QED42 commentedBelow are my observations towards the implementation.
- Earlier code was fetching from block_content_field_data table with condition of block id which will always return value 1 since we are passing id of block created.
- Above code is added in the patch which will generate a count which shows the block having language English
- In the code hereafter, we have
- Language Code when added for
$disabled_block_content
should not have langcode as english- Adding langcode as en by default will always give the count to be 2
- hence i have added an addiational parameter langcode to the createBlockContent()
so that the first block will create a count of block with en as the language and second block created will have language not specified, which eventually passes the test.
Comment #22
hash6 CreditAttribution: hash6 at QED42 for Drupal India Association commentedComment #23
daffie CreditAttribution: daffie commentedThe patch looks good. I have just 1 minor point:
For all 3 places: use the same value. Either "en" or LanguageInterface::LANGCODE_NOT_SPECIFIED.
Comment #24
Neslee Canil Pinto@daffie, will change it to en everywhere
Comment #25
daffie CreditAttribution: daffie commentedAs nobody seams to understand what the test Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::testDisabledBundle() is supposed to test. Can we just remove the test?
Comment #26
Neslee Canil PintoComment #27
daffie CreditAttribution: daffie commented@Neslle: I think you can also delete the helper method createBlockContent(), when you delete testDisabledBundle().
Comment #28
Neslee Canil PintoComment #29
daffie CreditAttribution: daffie commentedThese lines will then also not be needed. The same for use statements for Drupal\block_content\Entity\BlockContent and Drupal\Core\Database\Database.
Comment #30
Neslee Canil PintoComment #31
daffie CreditAttribution: daffie commentedThis patch has to go first to 9.1.
Comment #32
Neslee Canil PintoPatch for 9.1.x
Comment #33
daffie CreditAttribution: daffie commentedAs nobody seems to understand what the test Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::testDisabledBundle() is supposed to test. Lets remove the test.
All code changes look good.
All database queries of the block_content module that can be changed, have been changed to an entity query.
For me it is RTBC.
@Neslee: Thank you for all of your patches.
Comment #34
andypostIt looks like testing block content with revisions disabled, but it looks strange
Comment #35
catchCould we double check why
Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::testDisabledBundle()
was added via git blame? Agreed it's an odd looking test that doesn't seem to match its documentation.Comment #36
daffie CreditAttribution: daffie commentedThe removed test
Drupal\Tests\block_content\Functional\BlockContentTranslationUITest::testDisabledBundle()
was added in #1871772: Convert custom blocks to content entities. I think we can assume that all custom blocks are now content entities.Comment #39
catchCommitted 219df57 and pushed to 9.1.x, cherry-picked to 9.0.x. Thanks!