Problem/Motivation

In the past, it was possible to create path_file entities with an empty Name. These entities were saved in the database with a null value for the "name" column. With Drupal 11 and strict type checking, a null name (which is the entity label) now breaks Entity->toLink() with the following error on the admin/structure/path_file_entity page:

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/docroot/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

Reproducing is a little tricky because you need an existing path_file entity with name = null, which was possible in earlier versions of Drupal. However, if you have one or more such path_file entities, when you go to /admin/structure/path_file_entity, you'll see the above error.

You can reproduce a related error by attempting to add a path_file entity with an empty name.

  1. Go to /admin/structure/path_file_entity/add
  2. Leave the Name field empty, but populate the other fields
  3. Save and Publish it
  4. Observe the error

Proposed resolution

- Provide a database update that sets all null names to something like "[unnamed]".
- Make Name required on the /admin/structure/path_file_entity/add form and on the edit form.

Remaining tasks

See above.

User interface changes

With the above changes, "Name" will now be a required field for all path_file entities. This aligns with other entities where the label is required.

API changes

n/a

Data model changes

"Name" will now be required, consistent with other entity labels.

CommentFileSizeAuthor
#4 path_file_3614703.patch28.16 KBpaulmckibben

Issue fork path_file-3614703

Command icon 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

paulmckibben created an issue. See original summary.

paulmckibben’s picture

Status: Active » Needs review
paulmckibben’s picture

StatusFileSize
new28.16 KB

Here's a patch against the 2.1.0 release that contains the latest changes from the 2.0.x branch as well as the code from the MR.

batigolix’s picture

Status: Needs review » Reviewed & tested by the community

I could reproduce the error. I tested your solution and it works fine. Thanks

batigolix’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • b103a843 committed on 2.0.x
    Issue #3614703 by batigolix: Swap update hooks so NULL names are...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.