Problem/Motivation
Getting an error TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /srv/www/htdocs/drupal/web/core/lib/Drupal/Core/Utility/LinkGenerator.php on line 199 in Drupal\Component\Utility\Html::escape() (line 433 of /core/lib/Drupal/Component/Utility/Html.php).
Steps to reproduce
1. Ensure the website has enough content to support a view with a pager.
2. Add a new view with a pager. Ensure the pager is rendered and configure items per page as per the number of content items.
3. Error is triggered in the view and also when user clicks on 'Update preview'.
mkdir my-drupal-site && \
cd my-drupal-site && \
ddev config --project-type=drupal11 --docroot=web && \
ddev start && \
ddev composer create-project "drupal/recommended-project:^11" && \
ddev composer require drush/drush drupal/devel && \
ddev drush site:install --account-name=admin --account-pass=admin -y && \
ddev drush -y en devel_generate && \
ddev drush devel-generate:content --bundles article && \
ddev launch $(ddev drush uli)
Proposed resolution
Add the required fix in Drupal\Component\Utility\Html::escape() method.
Remaining tasks
Framework manager review on if reverting #3255637 is acceptable See comment 61/64/67
Patch review
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | fix-type-error-null-text-3523317-21.patch | 1 KB | alezu |
| #18 | fix-type-error-null-text-3523317-18.patch | 986 bytes | mighty_webber |
| #14 | fix-type-error-null-text.patch | 1011 bytes | _andrew |
Issue fork drupal-3523317
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
ishani patel commentedI've created MR from the patch.
Thank you!
Comment #5
cilefen commentedAlternatively you have the option of changing your code not to pass a null.
Comment #6
smustgrave commentedIssue summary is incomplete.
But also need some more investigation, what's being passed here that's null. If caused by custom code then seems the custom code is wrong.
Comment #7
cilefen commentedIn fact, in these cases the log messages would make no sense without values in placeholders.
Comment #8
gbyteMay be related: #3352384: Add Exception for TypeError Argument must be String in Drupal Component Utility Html escape{}
Comment #9
ishani patel commentedComment #10
amer cloudy commentedYes the issue related to custom code and i already have production that save logs in database with null it works with D10 and when upgrade to drupal 11 the issue appears
Comment #11
cilefen commentedComment #12
arx-e commentedI had the same error trying to access a simplenews page (admin/config/services/simplenews/settings/subscription) and this patch solves the issue.
Comment #13
uccio commentedI had the same error trying to access to admin/reports/status in a site with a lot of module contrib but only after the upgrade drupal 10.4.7
-> 11.1.7
Comment #14
_andrew commentedPlease see supplied patch which should apply cleanly in 11.1 and probably 11.2 which solves the issue. Relaxes the string requirement allowing for a null argument, and returns an empty string on null.
Comment #15
mighty_webber commented11.2.2 made some changes that made patch #14 not work correctly. These are the same changes in patch 14, just applied to different line numbers.
For whatever reason, though, neither install properly with composer, but install properly when run manually with git apply.
Comment #16
ryan osītis commentedI was attempting to test the patch from #14, but patching is affected as well. Insidious little bug, this one.
Comment #17
mighty_webber commentedI've attempted to apply it using extra.patches.drupal/commerce, extra.patches.drupal/core, extra.patches.drupal/core-recommended, all of which fail.
I have attempted with both patches.
Comment #18
mighty_webber commentedOk, I think I resolved the issue with it. Specifically, the file pointers.
When composer is installing, it's installing from web/core. The patch points to web/core/lib.
It should look like :
Instead of
Comment #19
mighty_webber commentedAs an added note, I think this patch creates issues with fields with "Unlimited" cardinality. When trying to root out the issue (couldn't create new fields with unlimited cardinality or save forms with existing fields with unlimited cardinality and "add another item" would fail, as the index values for the weight/order were coming in as null/empty strings.
Oddly enough, after removing this patch from my installation, I did not continue receiving the error noted in this ticket when attempting to install commerce, and the functionality of fields with unlimited cardinality returned.
Comment #20
johnwtI manually applied the changes in patch at #15, it seems to have worked.
Comment #21
alezu commentedThe problem with the patch from #15 is that it considers zero symbol as empty that breaks sorting of multiple field elements and I believe not only it. So we should check if the input text is 0.
Comment #22
alezu commentedComment #23
johnwtChanges in patch #15 seems to have caused problems with the weight variable throughout the site. Reverted this patch, which seems to have resolved the weight problem, then manually applied patch #21. Seems to work.
Comment #24
smustgrave commentedSummary update and steps to reproduce still appear to be missing
Comment #25
w01f commentedCan confirm manually applying #21 resolves the issue on our test site.
Comment #26
c_archer commentedCan confirm patch in #21 works.
Comment #27
smustgrave commented#24 is still needed and this needs to be reviewed
Comment #28
smustgrave commentedComment #29
alezu commented@smustgrave as for my case the origin of the error was custom entity (extended from EditorialContentEntityBase) that had no label key defined and thus the standard method $entity->label() returned NULL that caused fatal error at least on the entity edit page (method editTitle() from EntityController class). I have not found similar entity types in the core - all entities without label (e.g. PathAlias) provide overriden label() method that allows to avoid the error.
It would be awesome if someone found way to reproduce the error basing on the core only.
Comment #30
alezu commentedAdd https://www.drupal.org/project/drupal/issues/3515019 as a related issue
Comment #31
pbabin commentedUnsure if this helps - I'm trying to debug some issues with Entity Share Client/Server. While enabling/disabling json api extras I got this error while trying to edit the entity_view_display--entity_view_display resource config from disabled to enabled.
(/admin/config/services/jsonapi/resource_types/entity_view_display--entity_view_display/edit?destination=/admin/config/services/jsonapi/resource_types)
I applied #21 to setup and it resolved the issue. Unsure how to debug to find the root cause but this patch did address being able to access that edit field.
Comment #32
djg_tram commented@alezu Same here, probably, but I do havel a label() function for my entities. My log complains about
undefined array key "description".I know. Whatever fields you have with
entity_keys, they need bothsetLabel()andsetDescription()in the field definition, even if you don't need them. Stupid, if you ask me. :-)Comment #33
nicoschi commentedThis is happening adding a view pager following these steps:
- create a view of type block
- delete "Items per block" value during creation
- save the view
- add a pager
- from now on the error will forbid the view editing
Comment #34
lzagata commentedConfirming that #21 worked.
Comment #35
mlzrAfter install module pathauto, go to /config/search/path to get a list of paths. Then I get an error "TypeError: Drupal\Component\Utility\Html::escape():…".
In use: PHP 8.3, Drupal 11.2.4
After install patch #21 the error is no more.
Thanks!! For the hard work.
Comment #36
isalmanhaider commentedJust experience on Drupal 11.2 with PHP 8.3
If I change pagination from all items to full pager I get this error on the view
Could be because of the new heading level or somewhat.
Patch #21 worked for me
Comment #37
gaurav.kapoor commentedComment #38
smustgrave commentedThink we need a test case showing the problem and figure out why the value might be null
Comment #39
gcalex5 commentedDrupal 11.2.4 / PHP 8.3 had this issue on: /admin/config/search/path
Confirming #21 worked for me
Comment #40
sibany commentedHad the same issue after replacing a field under Views Fields...
Drupal 11.2.5 / PHP 8.3.23
Confirming #21 worked for me
Comment #41
jrochate commentedDrupal 11.2.5 / PHP 8.3.6
#21 solved a problem with dblog view, after some custom logs were produced.
Thanks.
Comment #42
bserem commentedThis issue was a worth opponent. In my case it was caused by the "rabbit_hole" form displayed on the sidebar of node add/edit pages.
This commit https://git.drupalcode.org/project/rabbit_hole/-/commit/18b07d6c45f0bcc7... (committed in a dev version) was all it took to fix things.
I'm pasting it here so that other people get to a fix faster than me.
Comment #44
oily commentedI have not yet manually tested the bug. In the IS steps to reproduce it says
Not sure what that means. I took it to mean in the test to create x nodes and set the view pager to x items per page. The test is currently passing, so I could be misunderstanding?
Comment #45
nks04747 commentedThank you @bserem! Our Drupal 11 upgrade was running into this error, but we weren't sure where it was coming from. Ours was also the rabbit_hole module, and it was fixed by resaving our node type configs. Apparently some values were set to null. This comment in the rabbit_hole issues is what fixed things for us.
Comment #46
alyaj2a commentedFor me, the error occurred when accessing my list of fixed blocks.
Comment #47
roshnykunjappan commentedI’m encountering this error in Drupal 11 when attempting to reload the core of the search server using the Search API module. The patch #21 fixed the issue.
Comment #48
dillix commentedI’m encountering this error in Drupal 11 in my custom modules for custom entities. But error message did't say where error was.
Comment #49
norman.lolAdded steps to reproduce with Vanilla Drupal 11. Strange enough error happens only when logged in.
Comment #50
norman.lolIn that Vanilla Drupal DDEV installation from the issue description, as soon as I remove the field_tags from the article teaser view mode the issue is gone.
ddev drush field:delete node article --field-name field_tagsComment #51
gwolf commentedI am also having issues upgrading to Drupal 11, with the custom-made theme we use hitting this bug. I can confirm the patch in comment #21 works correctly for us.
Comment #54
samitk commentedI have added new changes, but I am getting an error in the Spell-checking pipeline job.
It looks like it's an infrastructure issue with moving files between devices during the CI/CD process.
mv: inter-device move failed: '/build/core/node_modules' to '/builds/issue/drupal-3523317/core/node_modules'; unable to remove target: Directory not emptyComment #55
stefan lehmannMore a note to myself than anything else as I ran into this issue already for a second time and it left me scratching my head.
Make sure your custom entity has a label() function!
Comment #56
baysaa commentedEncountered this today and wanted to document what happened on a real life site:
We have remote videos from Youtube as a media entity. Sometimes admins paste wrong URLs, or sometimes videos get taken down, or some are set to private. In such cases the media entity gets saved without a label. This was ok on Drupal 10, but after upgrading to Drupal 11, the media library broke because some of the media entities don't have a label. I've traced the errors back to this issue and the patch at #21 fixes the issue.
Comment #57
baysaa commentedto add to my above comment: The media edit page is getting the same error too.
Comment #58
jaykainthola commentedPatch #21 solved the issue for Drupal 11.3
Comment #59
smustgrave commentedThere’s 2 MRs now but both appear to be failing.
@samit.310 why did you open a 2nd MR? If you’re proposing a different solution it’s good to leave a comment and put into the proposed solution section the different options so reviewers can easily tell
Comment #61
cmlaraThis went through a design decision in #3255637: Deprecate NULL values in Html::escape(), ::decodeEntities(), and FormattableMarkup::placeholderFormat() to make it easier to upgrade to PHP 8 to deprecate and remove NULL as an allowed value.
Comment #64
borisson_The last test is green with this change. As @cmlara said in #61 this was changed in the other issue #3255637
Is there a way we can get feedback from @alexpott @catch or some of the others that worked on that issue?
Comment #65
edgar saumell commentedSuddenly I got this when opening /admin/reports/dblog using Drupal 11.3.3. It didn't happen five minutes ago.
I checked the log with drush watchdog:show
In my setup I suspect webform module is not sanitizing the log. I have a field named Contracta'm and there are some new lines on the log:
ID Date Type Severity Message
10657 10/Feb 11:35 php Error TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in xxx/web/core/lib/Drupal/Component/Render/FormattableMarkup
10656 10/Feb 11:26 webform_submission Error Contracta'm webform remote post (completed) to
10655 10/Feb 11:26 webform Notificació Contracta'm webform sent Correu electrònic email.
10654 10/Feb 11:26 webform Notificació Fibra 1.000 Mbps + Telèfon fix: Submission #26 created.
Comment #66
tdnshah commentedWe upgraded from Drupal 10.5.6 to 11.3.2 and started facing this issue, any content type that had remote video using oembed with media library use to give this ajax error blocking the media library window to open, the patch in #21 did work for us.
Comment #67
cmlaraPrevious issue on this subject was in the Base system which is managed by the Framework Managers. Tagging them to look at this.
Someone may want to comment in #3255637: Deprecate NULL values in Html::escape(), ::decodeEntities(), and FormattableMarkup::placeholderFormat() to make it easier to upgrade to PHP 8 as well if it hasn’t already been done.
IMO reverting the previous work would allow bugs like this to persist, there was time given for deprecation, silently ignoring this would be a step backward and work should instead be put towards identifying flaws. Contrib and Core could potentially detect causes of this by using PHPstan.
Comment #68
andres.torres commentedCame across this issue today after upgrading from D11.2 to D11.3.3 - On the Reports DBLog UI, randomly happening when filtering output with a selection type and when using the pagination (this always triggers the error, making dblog useless).
Comment #69
hongqing commentedEncountered the same error with D11.3 and #21 solved it.
Comment #70
karanmahajan commentedAlso reproducible via scheduled_transitions module with D11.3 and #21 solved it.
Comment #71
oily commentedCan we move this to 'Needs review'?
Comment #72
borisson_The test that is added here is a very, very roundabout way of testing this, we should be able to easily test this method directly? We can keep this one I guess as well.
But this first thing we should do is seek consensus if we should even attempt to do this, since it's a (partial) revert of an earlier issue.
Comment #73
cmlaraMy understanding from https://project.pages.drupalcode.org/governance/core/drupal-core/#faq-ti... is that a Framework Manager is expected to respond within 1 week (7 days) once the “Needs framework manager review” tag is added to an issue.