A Migrate plugin that could convert basic <a href="node/123"> links into the required format would be really useful, both because lots of sites used that structure, and it could be useful as an example for people on how to build custom plugins for their own scenarios.
It would need to replace <a href="node/123"> links with the following structure:
<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="f52dbbd3-17cb-4d7f-8d65-f136645298db" href="/node/123">
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | linkit-n3065750-16.patch | 4.79 KB | damienmckenna |
Comments
Comment #2
damienmckennaComment #3
damienmckennaThis appears to work fine.
Before:
<a href="node/123">After:
<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="href="78645291-82d5-475c-8a01-32beb27ebf92" href="/node/123">This is how you use it:
Comment #4
damienmckennaDoh! The output should now be like this:
<a data-entity-substitution="canonical" data-entity-type="node" data-entity-uuid="78645291-82d5-475c-8a01-32beb27ebf92" href="/node/123">Comment #5
damienmckennaRight now the plugin only handles node links, but it could be easily expanded to handle other entities.
Comment #6
damienmckennaAfter running the migration with the patch above I discovered there were a dozen links which had attributes after the href attribute, so searching for a complete tag didn't work.
Comment #7
wim leersComment #8
wim leersComment #9
wim leersWhat about links that
linkitgenerated that use path aliases?This is very problematic :| But I don't see an elegant solution either.
If you have a
foonode that is referring to anotherfoonode, it's impossible to know the UUID of the referred node until it's migrated, but it could be migrated in the reverse order.Even if you could order this "correctly", it would still not solve circular references. Which are definitely allowed in text fields.
Tricky.
I wonder if the migration system maintainers have elegant solutions for this. Basically this process plugin can only be reliably run after the migration has already run once. It's almost like a "post-process" phase.
The only thing I can think of is to make
\Drupal\migrate\Plugin\MigrateProcessInterface::transform()track unresolvable links (time A), and create a new/separatelinkit_post_processormigration whose rows are effectively the ones tracked at time A, so that while the migration at time A is running, the number of rows to process is literally generated during the migration.Then at a later time B, we could in principle reliably update all of the tracked rows!
(Yes, I'm handwaving a lot here. I'm hoping this will trigger a response from one of the migration system maintainers pointing out a much better way to do this 😄)
Comment #10
joel_osc commentedWe do the post-process as you described... in your source plugin for your post-processer you select all nodes inner joined with your migrate map table. And then you convert links to linkit format. It gets even more fun coming from a non-drupal system where you may be converting non-drupal a tags to linkit links that could have image assets inside of the tag that get converter to media entities. ;)
Comment #11
mstrelan commentedIt seems this would be better off extending the
dom_str_replaceplugin in migrate_plus.Care to share example code?
This would be good to have. You could do a lookup on the path_alias table but would you want to do this for all links or just those with /node/123 pattern? Also the aliases may not exist yet (or at all) on the destination site.
It almost seems it would be better to develop this as a standalone batch task that can be run at any time.
Comment #12
damienmckennaI wasn't looking at that, I thought bundling a simple optional plugin could be beneficial as a learning exercise for people who wanted to map custom HTML. Properly mapping Linkit on D7 to D9 should be handled separately.
Comment #13
liam morlandI noticed the examples in this issue all show the site being at the root of their server. This solution should work with sites that are not at the root, for example:
<a href="/site-path/node/123">Comment #14
liam morlandIs there a reason site paths are included at all? See related issue.
Comment #15
damienmckennaThis needs work to make it cover additional scenarios.
Comment #16
damienmckennaThis improves the documentation.
Comment #17
damienmckennaBack to "needs work" per #9, #11, etc.
Comment #18
mark_fullmerComment #19
dalemoore commentedThis hasn't had any traffic in over a year, but I'm running into the same issue. I figured out how to create a migration to fix broken links when the node IDs/aliases changed from a migration a former coworker did, but the links are converted to the node/ID format, and Linkit doesn't seem to do anything with them to make them into their nicer looking alias without those extra data-attributes. I thought if I just resaved the pages it would kick in but it doesn't I guess w/o those attributes.