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
When a text field uses a not-existing config entity, rendering fails with a fatal error.
Fatal error: Call to a member function filters() on a non-object in core/modules/text/text.module on line 83
Steps to Reproduce
Create a file called test.php in root with the following:
$node = entity_create('node', array(
'type' => 'article',
'title' => 'test',
'body' => array(
'value' => md5(uniqid(rand(), true)),
'format' => 'filtered_html_invalid',
),
'uid' => 1,
));
$node->save();
Followed by the drush command
drush scr test.php
Try to view the entity then.
Proposed resolution
Write a test to show this doesn't work as expected.
Put in a safeguard if incorrect declaration of a text format or fix the missing filter() method.
Remaining tasks
- Write tests.
User interface changes
API changes
-
Comment | File | Size | Author |
---|---|---|---|
#22 | Details My Dev.png | 35.54 KB | sureshcj |
#21 | interdiff-18-21.txt | 601 bytes | harsha012 |
#21 | 2359389-21.patch | 1.52 KB | harsha012 |
#18 | interdiff-13-18.txt | 1.5 KB | harsha012 |
#18 | 2359389-18.patch | 1.59 KB | harsha012 |
Comments
Comment #1
podarokCan't reproduce within current dev
The same via devel/php
I see no notices. Node test successfully created.
Comment #2
fagoI ran into the same issue while working on a site migration. The fatal error only appears when the content is rendered as it tries to call the filters() method on a non-existing config entity. Attached patch fixes the issue.
Usually, we do no support broken configuration like this but clean-up the config instead. However, in the special case of filter formats I think this support of broken configuration is pre-existing but got broken. There is even already a comment for this case, but the check fails.
Agreed, this needs tests also.
Comment #3
fagoTestbot, go.
Comment #4
fagoComment #6
BrightBoldI just ran into this upgrading to Drupal 8.1. The solution turned out to be that the Typogrify module, which does not have a D8 version yet, needed to be completely uninstalled, not just disabled, in D7. So if anyone else is reading this issue because you've into this problem, make sure you uninstalled any modules that provide input filters that aren't available in D8.
Comment #7
Dan_RogersJust experienced this during an upgrade, and #6 pointed me in the right direction. For me, the quick fix was to add a text format with the same machine name as a custom one added to the D7 donor site.
Comment #8
hgoto CreditAttribution: hgoto as a volunteer commentedI confirmed that this error occurs. And the patch #2 works for me.
I created a simple test for this and would like someone to review it.
Comment #13
jeqqI've rerolled the patch, the issue is still actual in Drupal 8.4.x. When the filter is invalid, I have this error:
Error: Call to a member function filters() on null in .../core/modules/text/text.module on line 84
Comment #15
kmoll CreditAttribution: kmoll at Appnovation for Pfizer, Inc. commentedI have tested this and I can confirm it is working and fixes the error.
Comment #16
kmoll CreditAttribution: kmoll at Appnovation for Pfizer, Inc. commentedComment #17
larowlanThe word formatter has a different meaning in Drupal. We're testing an invalid filter format, we should name the test method
testInvalidFilterFormat
I don't think we need inline variables here, so
would suffice.
But I think we should name the invalid filter format 'non_existent_format' to better reflect what is being tested here.
Sorry to be pedantic, but can we name this variable
filter_format
as that better reflects what we're working with?Comment #18
harsha012 CreditAttribution: harsha012 as a volunteer and at Red Crackle commentedfixed the nit picks as per #17
Comment #19
douggreen CreditAttribution: douggreen at Appnovation for Pfizer, Inc. commentedI agree with @fago in comment #2 that we normally wouldn't fix this, however the comment makes the code incorrect. So we should either fix it or remove the comment. Since the fix is trivial, and already here, I think we should fix it.
Comment #20
larowlanWe're now changing the behaviour of this function.
Previously, if we found the format, but it had no configured filters, we returned ''. Now we only return '' if the format doesn't exist.
I note however that the comment indicates it was supposed to be checking for the format, not the presence of filters on the format. So it is likely that the existing behaviour is unintended.
However, I think we should reinstate the previous behaviour.
So make the code
We can then remove the
$filters =
line.It is unlikely that someone was relying on this behaviour, but we can't be sure, so we should err on the side of caution.
Comment #21
harsha012 CreditAttribution: harsha012 as a volunteer and at Red Crackle commentedImproved the patch
Comment #22
sureshcj CreditAttribution: sureshcj at DrupalPartners commentedHi harsha012,
I have tested with above patch, which has posted in comment #21. The node creates and node view working fine.
But I got following error on the reports.
"Missing text format: filtered_html_invalid."
Comment #23
mohit1604 CreditAttribution: mohit1604 at Google Summer of Code commentedFixed typo in issue summary.
Comment #24
joelpittet@sureshcj thanks for testing, that is expected and glad there is still reporting for that in the logs.
There is an extra space in the test that could be removed on commit.
Not a super big fan of assignments in conditionals but it was recommended by @larowlan in #20 so don't want to make a big fus there.
Thanks for everybody's help on this!
Comment #26
larowlan@sureshcj that error is not related to this patch, but is the expected behaviour.
Whilst we normally don't give credit for screenshots unrelated to the patch, it does demonstrate that effort was spent manually testing the patch, so I'm going to add credit for @sureshcj in this instance.
for more information please see https://www.drupal.org/core/maintainers/issue-credit
Committed as 72c76b7 and pushed to 8.5.x.
Leaving at RTBC on 8.4.x.
Will cherry-pick to 8.4.x tomorrow after commit freeze for 8.4.4 is over.
Comment #27
larowlanCherry-picked 8baec3f and pushed to 8.4.x
Comment #30
larowlanAs per https://www.drupal.org/core/release-cycle-overview#current-development-c... 8.4 is in 'critical fixes only', so I reverted this from 8.4