A rating block for SilverStripe CMS using the Elemental module. This module allows users to rate pages and provide feedback through a customizable rating system.
- SilverStripe Framework ^5
- SilverStripe GraphQL ^5
Install via Composer:
composer require dnadesign/silverstripe-elemental-ratingblock
Run dev/build to create the database tables:
vendor/bin/sake dev/build
- Add the Rating Block to your page through the CMS
- Configure the rating form settings
- Set up star ratings and tags as needed
- The rating form will appear on the frontend for users to submit ratings
You can streamline the CMS experience by hiding unnecessary fields and tabs:
DNADesign\Elemental\Models\ElementRatingBlock:
# Hide specific fields in the CMS
hide_enable_rating_form: true
hide_rating_form_intro: true
hide_enable_rating_comments: true
hide_rating_form_title: false
hide_rating_form_success_message: false
hide_enable_rating_tags: false
# Remove entire tabs
remove_settings_tab: true
DNADesign\Elemental\Admins\RatingAdmin:
# Customize admin interface
hide_main_ratings_tab: true
hide_enable_rating_form
: Hide the "Enable Rating form" checkboxhide_rating_form_intro
: Hide the rating form intro HTML editorhide_enable_rating_comments
: Hide the "Enable Rating comments" checkboxhide_rating_form_title
: Hide the rating form title fieldhide_rating_form_success_message
: Hide the success message HTML editorhide_enable_rating_tags
: Hide the "Enable Rating form tags" checkboxremove_settings_tab
: Remove the entire Settings tab from the CMS
hide_main_ratings_tab
: Hide the main Ratings tab in the admin (useful when you only want to manage rating blocks, not view individual ratings)
You can set up default stars and tags that will be created automatically:
DNADesign\Elemental\Models\ElementRatingBlock:
stars:
poor:
tags:
- poor
- very poor
- extremely poor
fair:
tags:
- fair
- very fair
- extremely fair
good:
tags:
- good
- very good
- extremely good
excellent:
tags:
- excellent
- very excellent
- extremely excellent
RatingTag models now include a UniqueID field that is automatically generated from the Name field. This is useful for frontend integration and API consistency.
The UniqueID is generated by:
- Converting to lowercase
- Replacing "&" with "and"
- Replacing spaces with hyphens
- Removing non-alphanumeric characters (except hyphens)
Example: "Very Good & Great" becomes "very-good-and-great"
The rating block automatically includes the necessary CSS and JavaScript files. The rating form data is available through the getBootData()
method which provides:
- EnableRatingForm
- RatingFormTitle
- RatingFormIntro
- EnableRatingComments
- RatingFormSuccessMessage
- RatingPageName
- RatingPageID
- RatingStars
- SecurityToken
The module includes the following permissions:
VIEW_RATING
: View ratings in the adminDELETE_RATING
: Delete ratings from the admin