I am using Search API Solr and Search API attachments so my results page returns both node and file entities.
However, when a file entity is returned in the matched results, I get a "No link template "canonical" found for the "file" entity type" error because of the $entity->toUrl()->toString() call in template_preprocess_search_api_page_result.
I realize this is a core issue (see related discussions #2402533: Provide File::createFileUrl() as a replacement for the deprecated File:url() implementation and #2922487: Follow-up for #2910211: fix all deprecation warnings), but attached is a first pass at an interim patch which prevents the fatal error.
Comment | File | Size | Author |
---|---|---|---|
#9 | search_api_page-2965839-9.patch | 605 bytes | Ki |
#3 | search-api-page-check-entity-is-file.patch | 613 bytes | zanvidmar |
search-api-page-check-entity-has-link-template.patch | 772 bytes | hitfactory | |
|
Comments
Comment #2
whiplashomega CreditAttribution: whiplashomega commentedI ran into this same error hitfactory, and think I have an easier fix, though my git-foo is bad. If you simply replace the line
$variables['url'] = $entity->toUrl()->toString();
with
$variables['url'] = $entity->url();
it should work. That particular method is overridden on the file entity type to return the files actual path, and for all other entities calls $entity->toUrl() within its own code.
Comment #3
zanvidmar CreditAttribution: zanvidmar as a volunteer commentedWhat if we simply check if entity is file?
Comment #4
legolasboSetting to the correct status.
Comment #5
borisson_Seems like a good solution.
Comment #6
borisson_Comment #9
Ki CreditAttribution: Ki as a volunteer and at Urban Insight commentedHere's checking if the entity is a paragraph.