https://github.com/a2nt/silverstripe-member-profiles
SilverStripe extendable profile areas. Provides registration page and extendable profile page area.
https://github.com/a2nt/silverstripe-member-profiles
Last synced: about 1 year ago
JSON representation
SilverStripe extendable profile areas. Provides registration page and extendable profile page area.
- Host: GitHub
- URL: https://github.com/a2nt/silverstripe-member-profiles
- Owner: a2nt
- License: other
- Created: 2016-10-25T13:43:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-12T22:47:55.000Z (almost 9 years ago)
- Last Synced: 2025-03-27T15:21:21.617Z (over 1 year ago)
- Language: PHP
- Size: 50.8 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# SilverStripe Profile Area Module
## Maintainer Contact
* Anton Fedianin
## 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:
```php
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:
```php
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 = ''; // optional icon
private static $menu_title = 'My Profile Area'; // optional title otherwise My Profile Area title will be used
}
```
Requirements config example:
```yml
ProfileController:
requirements_css:
- site/css/ProfileController.css
requirements_javascript:
- site/css/ProfileController.js
```
### Profile CRUD
```php
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 = ''; // 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:
```yml
MemberRegistrationForm:
extensions:
- MyMemberRegistrationFormExtension
```
```php
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:
```yml
MemberEditProfileForm:
extensions:
- MyMemberEditProfileFormExtension
```
```php
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:
```yml
ProfileCRUD:
extensions:
- BootstrapItemEditForm
```
```php
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);
}
}
```
[My personal website](https://tony.twma.pro)
[Buy me a Beer](https://www.paypal.me/tonytwma)