Play CMS is shipped with DefaultParty as a default implementation of party, DefaultPartyRole as a default implementation of role, DefaultPartyManage, DefaultRoleManager  and default user interface for their management.

Each of the elements can be extended and customized in main project. 

Customizing Party class

The Party objects are managed by the PartyManager which can be overridden to support customized Party implementation. The overridden PartyManager can be enabled by providing a custom Dependency Injection Module binding (see play.api.inject.Module#Module) or by defining a custom play.inject.guice.GuiceApplicationLoader with overridden bindings.

Example:

// CustomPartyManager.java
public class CustomPartyManager extends ch.insign.playauth.party.support.DefaultPartyManager {
    @Override
    public Class<? extends Party> getPartyClass() {
        return User.class;
    }
}
// CustomApplicationLoader.java
public class CustomApplicationLoader extends GuiceApplicationLoader {
    @Override
    public GuiceApplicationBuilder builder(Context context) {
        return super.builder(context)
                .overrides(
                        bind(PartyManager.class).to(CustomPartyManager.class));
    }
}
# Take control of how the application is initialized
play.application.loader = "CustomApplicationLoader"

Customizing Party's edit and create forms

Create class which extends PartyFormManager and implement it's methods:

  • editForm:  returns the rendered edit form for the custom party
  • createForm: returns the rendered create form for the custom party

Register new class in registerPartyFormManager() method of a setup class

Example:

public class DefaultPartyFormManager implements PartyFormManager {
    @Override
    public Html editForm(Form editForm, DefaultParty party) {
        return editForm.render(new AdminContext(), editForm, (User)party);
    }
    @Override
    public Html createForm(Form form) {
        return createForm.render(form);
    }
}

 

Note: create and edit templates can use default party's templates as a base template and only extend it with new fields.

Example:

@ch.insign.cms.views.html.admin.party.editForm(a, userForm, user) {
    <div class="form-group">
        @inputText(
            userForm("lastName"),
            'class -> "form-control",
            'placeholder -> Messages.get("backend.user.lastName"),
            '_label -> Messages.get("backend.user.lastName")
        )
    </div>
    <div class="form-group">
        @inputText(
            userForm("phone"),
            'class -> "form-control",
            'placeholder -> Messages.get("backend.user.phone"),
            '_label -> Messages.get("backend.user.phone")
        )
    </div>
}

 

Customizing Party's events

Create class which extends PartyEvents and implement it's methods:

  • onCreate: triggers when party is created. All custom party fields should be copied from form class to party class in this method, otherwise they wouldn't be saved.
  • onUpdate: triggers when party is updated.
  • onDelete: triggers when party is deleted.

Register new class in registerPartyEventHandler() method of a setup class.

Example:

public class DefaultPartyHandler implements PartyEvents {
   @Override
    public void onCreate(Form form, DefaultParty party) {
        User user = (User) party;
        User userForm = ((Form<User>) form).get();
        user.setLastName(userForm.getLastName());
        user.setPhone(userForm.getPhone());
    }
 
    @Override
    public void onUpdate(Form form, DefaultParty party) {
    }
 
    @Override
    public void onDelete(DefaultParty party) {
    }
}

 

 

Customizing Party's controller actions

Customizing party's controllers actions is not really necessary but can be easily done by creating new class, that extends from RouteResolver.

Register new class in registerResolver() method of a setup class and implement it's methods.

Each of it's method should return the call to appropriate action of your own Party Controller.

Example:

public class DefaultRouteResolver implements RouteResolver {
    @Override
    public Call login() {
        return routes.AuthController.login();
    };
    @Override
    public Call logout(String backURL) {
        return routes.AuthController.logout(backURL);
    }
    @Override
    public Call listParties() {
        return routes.PartyController.list();
    }
    @Override
    public Call editParty(String id) {
        return routes.PartyController.editParty(id);
    } 
    //...
}

 

Note: Default RouteResolver is already implemented in play-cms module.