DEV: Add topic_embed_import_create_args plugin modifier (#26527)

* DEV: Add `topic_embed_import_create_args` plugin modifier

This modifier allows a plugin to change the arguments used when creating
 a new topic for an imported article.

For example: let's say you want to prepend "Imported: " to the title of
every imported topic. You could use this modifier like so:

```ruby
# In your plugin's code
plugin.register_modifier(:topic_embed_import_create_args) do |args|
  args[:title] = "Imported: #{args[:title]}"
  args
end
```

In this example, the modifier is prepending "Imported: " to the `title` in the `create_args` hash. This modified title would then be used when the new topic is created.
This commit is contained in:
Sérgio Saquetim
2024-04-05 12:37:53 -03:00
committed by GitHub
parent dd83a07550
commit 175d2451a9
2 changed files with 53 additions and 2 deletions

View File

@@ -81,6 +81,17 @@ class TopicEmbed < ActiveRecord::Base
}
create_args[:visible] = false if SiteSetting.import_embed_unlisted?
# always return `args` when using this modifier, e.g:
#
# plugin.register_modifier(:topic_embed_import_create_args) do |args|
# args[:title] = "MODIFIED: #{args[:title]}"
#
# args # returning args is important to prevent errors
# end
create_args =
DiscoursePluginRegistry.apply_modifier(:topic_embed_import_create_args, create_args) ||
create_args
post = PostCreator.create(user, create_args)
post.topic.topic_embed.update!(embed_content_cache: original_contents)
end