Problem/Motivation

I have just updated to Drupal 11.1.4 and PHP 8.4.3. Since the update I am getting issues with Profiles in Inline Entity Forms.
This used to work fine with the latest D10 and PHP 8.2.

Steps to reproduce

1. Add an entity reference field to a node, which references profiles.
2. Set the form mode of the field to Inline Entity Form - Complex
Settings:
Form mode: Default
Default labels are used.
New profiles can be added.
Existing profiles can be referenced and are matched with the Contains operator.
profiles can not be duplicated.
Always keep unreferenced profiles.

3. Try creating a profile.
4. Get a JavaScript/AJAX error; IEF did nothing.
5. See this error in the log:
TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /home/customer/www/git/web/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 431 of /home/customer/www/git/web/core/lib/Drupal/Component/Utility/Html.php).

Partial stack trace:

#0 /home/customer/www/git/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(238): Drupal\Component\Utility\Html::escape(NULL)
#1 /home/customer/www/git/web/core/lib/Drupal/Component/Render/FormattableMarkup.php(187): Drupal\Component\Render\FormattableMarkup::placeholderEscape(NULL)
#2 /home/customer/www/git/web/core/lib/Drupal/Core/StringTranslation/TranslatableMarkup.php(195): Drupal\Component\Render\FormattableMarkup::placeholderFormat('@type #@id', Array)
#3 /home/customer/www/git/web/core/lib/Drupal/Component/Utility/ToStringTrait.php(15): Drupal\Core\StringTranslation\TranslatableMarkup->render()
#4 /home/customer/www/git/web/modules/contrib/profile/src/Event/ProfileLabelEvent.php(37): Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
#5 /home/customer/www/git/web/modules/contrib/profile/src/Entity/Profile.php(96): Drupal\profile\Event\ProfileLabelEvent->__construct(Object(Drupal\profile\Entity\Profile), Object(Drupal\Core\StringTranslation\TranslatableMarkup))
#6 /home/customer/www/git/web/modules/contrib/inline_entity_form/src/Form/EntityInlineForm.php(120): Drupal\profile\Entity\Profile->label()

Proposed resolution

I suppose the label generation code is returning NULL for some reason.

    $label = $this->t('@type #@id', [
      '@type' => $profile_type->getDisplayLabel() ?: $profile_type->label(),
      '@id' => $this->id(),
    ]);

Providing an explicit label made the error go away and IEF works as it should:

    $label = $this->t('@type #@id', [
      '@type' => $profile_type->getDisplayLabel() ?: $profile_type->label(),
      '@id' => $this->id(),
    ]);

    $label = "test";

Should there be some default value in case the label cannot be generated?

Remaining tasks

Figure out why no label is generated?

User interface changes

API changes

Data model changes

Comments

neograph734 created an issue. See original summary.

  • jsacksick committed 431c242c on 8.x-1.x
    Issue #3512592 by jsacksick: Ensure the profile label generation doesn't...
jsacksick’s picture

Status: Active » Fixed

I believe this is fixed, please reopen if it is not after upgrading to the latest version.

neograph734’s picture

Looked good on a quick test. Thanks for the fast reply!

Status: Fixed » Closed (fixed)

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

andyg5000’s picture

For me this was being caused by #3541746: Profile Label Subscriber should not return NULL even after this update. That issue has been resolved though.