a2nt / silverstripe-member-profiles
SilverStripe extendable profile areas. Provides registration page and extendable profile page area.
Installs: 91
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 2
Type:silverstripe-module
Requires
- silverstripe/cms: >=3.1
- silverstripe/framework: >=3.1
This package is not auto-updated.
Last update: 2024-12-21 21:25:39 UTC
README
Maintainer Contact
- Anton Fedianin <tony (at) twma (dot) pro> https://twma.pro
Requirements
- SilverStripe 3.2
Overview
A simplified light-weight alternative for frontend member profile areas.
- Registration page
- Profile page for updating details.
- Extendable profile area
Registration Page
Create member Registration Page at the CMS or run /dev/build?flush after module instalation
Member Profile Page
Create member Profile Page at the CMS or run /dev/build?flush after module instalation
Profile Area
By default profile area has only profile information and profile editing form controller to add extra profile areas use this example:
class MyProfileArea extends MemberProfilePage_Controller { /* ... your code * private static $allowed_actions = [ * 'MyAction' * ]; * * public function MyAction() {} * */ }
Profile information will use /profile URL, sub-controllers will use sub-URLs of this page for example: /profile/myprofilearea /profile/myprofilearea/action
/profile/myprofileareaCRUD/MyItemClassName/new/ /profile/myprofileareaCRUD/MyItemClassName/view/11 /profile/myprofileareaCRUD/MyItemClassName/edit/11 /profile/myprofileareaCRUD/MyItemClassName/delete/11 /profile/myprofileareaCRUD/extraaction/ID/OtherID
New area will be automatically added to frontend member profile area navigation menu, but you can add hide ancestor to keep it hidden:
class MyProfileArea extends ProfileController { private static $hide_ancestor = false; // it's optional if you want to hide this controller set to true private static $menu_icon = '<i class="fa fa-pencil-square-o"></i>'; // optional icon private static $menu_title = 'My Profile Area'; // optional title otherwise My Profile Area title will be used }
Requirements config example:
ProfileController: requirements_css: - site/css/ProfileController.css requirements_javascript: - site/css/ProfileController.js
Profile CRUD
class MyProfileObjectsController extends ProfileCRUD { /* * This controller will let you create, view, edit and delete objects */ private static $hide_ancestor = false; // it's optional if you want to hide this controller set to true private static $menu_icon = '<i class="fa fa-pencil-square-o"></i>'; // optional icon private static $menu_title = 'My Profile Area'; // optional title otherwise My Profile Area title will be used private static $managed_models = [ 'MyObject', 'MyObject2', ]; private static $allowed_actions = [ 'ExtraAction' ]; public function ExtraAction() {} }
-
to make "MyProfileArea" template create templates/profile/controllers/MyProfileArea.ss
-
it will be used as sub-template of MemberProfilePage.ss by using $ProfileArea variable just like $Layout requires sub-template of Page.ss
-
to create a specific action template of "MyProfileArea" create templates/profile/controllers/MyProfileArea_MyAction.ss
Use following code to customize MemberRegistrationForm:
MemberRegistrationForm: extensions: - MyMemberRegistrationFormExtension
class MyMemberRegistrationFormExtension extends Extension { public function updateMemberRegistrationForm() { /* your code, ex: * $fields = $this->owner->Fields(); * $fields->push(TextField::create('MyField')); * BootstrapForm::apply_bootstrap_to_fieldlist($fields); * BootstrapForm::apply_bootstrap_to_fieldlist($this->owner->Actions()); */ } public function onRegister($member) { /* your code to execute on register for an instance extra notifications */ } }
Use following code to customize MemberEditProfileForm:
MemberEditProfileForm: extensions: - MyMemberEditProfileFormExtension
class MyMemberEditProfileFormExtension extends Extension { public function updateMemberEditProfileForm() { /* your code, ex: * $fields = $this->owner->Fields(); * $fields->push(TextField::create('MyField')); * BootstrapForm::apply_bootstrap_to_fieldlist($fields); * BootstrapForm::apply_bootstrap_to_fieldlist($this->owner->Actions()); */ } }
Use following code to extend Profile CRUD item forms:
ProfileCRUD: extensions: - BootstrapItemEditForm
class BootstrapItemEditForm extends Extension { public function permissionDenied() { // your code, for example: Page_Controller::setSiteMessage('You must log in to view your profile.', 'warning'); } public function updateItemRemoved(DataObject $item) { // your code } public function updateItemRemoveDenied() { // your code } public function updateItemEditDenied() { // your code } public function updateItemEditSuccess(DataObject $item, array $data, $new = false) { if ($new) { $success_msg = 'New Item Created'; } else { $success_msg = 'Item was updated'; } // your code } public function updateItemForm($form) { $fields = $form->Fields(); // setup bootstrap classes BootstrapForm::apply_bootstrap_to_fieldlist($fields); $fields = $form->Actions(); // setup bootstrap classes BootstrapForm::apply_bootstrap_to_fieldlist($fields); } }