By xjm on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.0.x
Introduced in version:
8.0.0-rc4
Issue links:
Description:
In order to make the URL and link generation APIs easier to understand and use correctly, many methods of generating URLs and links have been deprecated.
Two new methods have been added to EntityInterface to support this change: EntityInterface::toLink() and EntityInterface::toUrl(). These methods replace EntityInterface::link(), EntityInterface::url(), and EntityInterface::urlInfo(). This is a BC break for any entities that implement EntityInterface directly. Entities which extend from the Entity base class or ConfigEntityBase are not affected, as these base classes already provide implementations of those methods.
Be aware of the following changes between these methods
- EntityInterface::link() returned a string, EntityInterface::toLink() returns a Link object, call toString() on it to get a string
- Same for EntityInterface::toUrl(), which also returns a URL object and is a direct replacement of urlInfo(), existing ->url() calls need to all ->toUrl()->toString() to get the same result
- EntityInterface::toUrl() will throw an exception if called on an entity that has no ID or no canonical link template, unlike url(), which returned an empty string in that case.
- ConfigEntityBase::toLink() does not override the default relationship to edit-form like it does for toUrl() and link(), make sure to check and call it with the correct relationship.
- For files, see this change notice.
Impacts:
Module developers