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