- Issue created by @TomTech
- Merge request !13017Issue #3541736 by tomtech: EntityBase::toLink() should ensure $text is a string β (Open) created by TomTech
- πΊπΈUnited States TomTech
I've created an MR that simply falls back to the entity id if the label returns NULL, as it is likely that it would at least have an id.
id(), though, can also return NULL, so the MR then falls back to empty string.
The URL would obviously not be visible on a page with no text, but this seems better than the current WSOD. We could also fall back to some placeholder text, if we could agree on the appropriate text.
- πΊπΈUnited States smustgrave
Can you elaborate on why you would do
hard code the entity class to return NULL
. May help drive the tests.
- πΊπΈUnited States TomTech
Well, that's just a brute force way. :)
The definition for label() is:
/** * Gets the label of the entity. * * @return string|\Drupal\Core\StringTranslation\TranslatableMarkup|null * The label of the entity, or NULL if there is no label defined. */ public function label();
so it is documented to return NULL.
But,
toLink()
calls:return new Link($text, $url);
which expects a
string
, not?string
.Another approach:
Implement an EventSubscriber that subscribes to ProfileEvents::PROFILE_LABEL, and in the invoked method, call $event->setLabel(NULL).
Or, implement a custom entity, but do NOT set a
label
entity key.