I want every category to have an auto-generated topic, much like default “About the [catgegory name] category” at the top of every category. Is there a way I can hitch on the after_create event of Category? I can’t find any plugin that does anything similar, or even how to insert a topic record.
I think you’d need to use the Discourse API to achieve this?
justin
(Justin DiRose)
February 1, 2021, 3:21am
3
There is a DiscourseEvent called category_created.
after_destroy :reset_topic_ids_cache
after_destroy :publish_category_deletion
after_destroy :remove_site_settings
after_create :delete_category_permalink
after_update :rename_category_definition, if: :saved_change_to_name?
after_update :create_category_permalink, if: :saved_change_to_slug?
after_commit :trigger_category_created_event, on: :create
after_commit :trigger_category_updated_event, on: :update
after_commit :trigger_category_destroyed_event, on: :destroy
after_save_commit :index_search
belongs_to :parent_category, class_name: 'Category'
has_many :subcategories, class_name: 'Category', foreign_key: 'parent_category_id'
has_many :category_tags, dependent: :destroy
has_many :tags, through: :category_tags
You’d want to tie into that event and follow this example:
Hope that helps!
This is exactly what I needed! I just KNEW there had to be an event I could catch, I just couldn’t find it. Many thanks!