Example-Pagein English, as well as e.g.
frontend.example.example, as well as the route itself:
/example. Make sure to remember those for the next step.
seo_urltable. For thise case, we're making use of the
ImportTranslationsTrait, which comes with a helper method
seo_urltable like a translation table, since it also needs a
language_idand respective translated SEO URLs. You'll have to pass a German and an English array into an instance of the
Translationsclass, which is then the second parameter for the
getSeoMetaArraymethod, that we implemented here. Most important for you are the columns
path_infohere, which represent the values you've defined in your controller's route annotation.
array_merge, we're then also adding our translated SEO URL to the column
Fooshould be accessible using the route
yourShop.com/Entities/Fooor whatever you'd like. Now, everytime you create a new entity, a SEO URL has to be automatically created as well. When you update your entities' name, guess what, you'll have to change the SEO URL as well.
SeoUrlRouteclasses, which hold all necessary information about your dynamic route and will then create the respective
SeoUrlRouteInterface, which comes with three necessary methods:
getConfig: Here you have to return an instance of
SeoUrlRouteConfig, containing your entity's definition,
prepareCriteria: Here you can adjust the criteria instance, which will be used to fetch your entities.
activefield and therefore only generate SEO URLs for active entities. Also you can add associations here,
getMapping: In this method you have to return an instance of
SeoUrlMapping. It has to contain the actually
example.namein the SEO URL template, you have to
getMappingmethod, since you don't want to provide mappings for other entities than your custom one.
writtenevent. Everytime your entity is written, you then have to execute the
updatemethod of the
writtenevent of our custom entity by providing the entities' technical name with the
.writtensuffix. Everytime it is executed, we're just using the said
updatemethod of the
SeoUrlUpdater. Here you'll have to provide the technical route name and the IDs of the entities, that need to be updated. And that's it for the subscriber.
SeoUrlUpdaterwill need one more thing in order to work properly: An entry in the table
seo_url_template, which is done in the next step.
route_name: We've defined this multiple times already. Use the constant from your
entity_name: The technical name of your custom entity. In this guide it's
template: Once again use the constant
is_deletedof the respective entry in the
seo_urltable has to be set to
.deletedand then executing the
DynamicSeoUrlsServicewith a method
writeSeoEntries. This method will get an array of entries to be written, including their respective payload, such as a name for the SEO URL. It also needs the current context.
SeoUrlPersisterand its method
updateSeoUrlsin order to write entries to the
writeSeoEntrieswill look for a Storefront sales channel and return its ID. It's then iterating over each provided entry, which in this example will need a method called
getIdand method called
getName. Using this data, an array of URLs to be written is created. Make sure to change the values of the following keys:
routeName: The technical name of your route, configured in your controller
pathInfo: The technical, non-SEO, path of your route, also configured in your controller
seoPathInfo: The actual SEO path you want to use - in this case the name of the said content
SeoUrlPersister. And that's it for your dynamic content.
1of the respective
seo_urlentry. This can be achieved with a new method, in this example we'll call it
deleteSeoEntries. It will receive an array of IDs to be deleted. Those IDs have to match the value of the column
seo_urltable. Also it needs the current context. It will take care of setting the generated SEO URLs to
deleted. It will not delete an entry from the table
is_deletedfor the system. However, this SEO route will remain accessible, so make sure to implement a check whether or not the content still exists in your controller.
Contextinstance, for whichever language that is. You can be more specific here though, in order to properly define the language ID yourself here and therefore ensuring it is written for the right language.