in news

Blog toolbox models

Blog toolbox list of models

  1. BlogPostVisit
  2. CustomPostType
  3. NewsletterSubscriber
  4. NewsletterSubscriberCategory
  5. Settings
  6. Post (Extended)
  7. User (Extended)


At the moment the model itself doesn't contain any methods. All data handling is managed by it's component or controller, and it's data is added to posts columns.yaml file.


This model has a relationship attached, it belongs to RainLab.Blog Post model.


This model has several public methods available. They are small and pretty much self explanatory. This model represents subscribed user to the newsletter.

List of methods:

  • getNewsletterListAttribute – Takes no parameter, returns array of category names of the subscriber.
  • sendNewsletterTokenMail – Takes in parameter, array of values for the email message. Returns nothing.
  • sendNewsletterMail - Takes in parameter, array of values for the email message. Returns nothing.
  • sendWelcomeMail - Takes in parameter, array of values for the email message. Returns nothing.


This model acts as a pivot table which connects NewsletterSubscriber and RainLab.Category values. With this model, we can get information about certain users and their subscribed categories (categories to which they are subscribed).


This model represents the plugin's own settings management. There are no available methods because it only acts as ORM.

Note: These are not settings for the OctoberCMS module as these settings are completely separated from the core and are only relevant for the Blog Toolbox plugin.

Post (Extended)

This model is originally part of RainLab.Blog. We have extended their model inside the Plugin.php file of our plugin. Every part of our extension can be found inside the postExtend method inside Plugin.php.


  • HasMany relation on post types – We have connected CustomPostType with Post model in a way that Post model now has hasMany relation with CustomPostType.
  • HasMany relation on visit count – Same as above. For sake of simplicity and data handling, we’ve added hasMany relation for Post model to our VisitCount model.
  • Event afterCreate – Inside this event, we are checking if the created post is selected as a newsletter. If that is the case, we are gathering and processing data of the model and subscribed user. When everything is collected, sendNewsletterMail method is called with required params.
  • Event beforeSave – We didn't add much to this event at this point in plugin versions. We are simply clearing up tags data so it doesn't have unnecessary spaces before it is being saved into the database.
  • Event beforeCreate – In this event, we are just setting post visits and revisits to be zero by default.

User (Extended)

This model is originally part of the Backend model collection. All our extensions can be found inside userModelExtend and backendUserExtend methods, inside our Plugin.php file. We decided to split the extension in two separate methods.

While userModelExtend is extending events and adding one dynamic method, method backendUserExtend is extending model and adding extra fields in the form widget.


  • Event beforeCreate – We are here preparing default values for two-step authentication procedure
  • Event beforeValidate – Here we’ve added additional validation for a new field we’ve added previously: user_slug, which is a required field for UserProfile component.
  • Event beforeUpdate – In this event, we are checking if two step authentication option is enabled and if the token is set. This was added so that when a user enables two step authentication, he doesn't get logged out immediately, because that would disrupt the user's experience. However, when the user logs out and then tries to log in again, there will be a validation check.
  • Dynamic method getPosts – This method will simply return the collection of RainLab\Blog\Models\Post of the user. It is used by the UserProfile component.

Buy blog toolbox plugin - 13 USD

Prev: Controllers Next: Dynamic methods