|
|
Hi When I have read Orchard documents I didn't understand ActivatingFilter can anyone explain it more? ( I'm new in Orchard sorry!...)
|
|
|
|
It just attaches a part to a content item. For example, in the Orchard.Roles module they attach the UserRolesPart to the "User" content type...
[UsedImplicitly]
public class UserRolesPartHandler : ContentHandler {
private readonly IRepository<UserRolesPartRecord> _userRolesRepository;
public UserRolesPartHandler(IRepository<UserRolesPartRecord> userRolesRepository) {
_userRolesRepository = userRolesRepository;
Filters.Add(new ActivatingFilter<UserRolesPart>("User"));
OnLoaded<UserRolesPart>((context, userRoles) => {
userRoles.Roles = _userRolesRepository
.Fetch(x => x.UserId == context.ContentItem.Id)
.Select(x => x.Role.Name).ToList();
});
}
}
|
|
|
|
Thank you but what is the difference between this and using migration class I have seen some third party modules use both of them for attaching a contentpart. for example for attaching UserPart module they first add it to a contenttype in migration class
then use this filter to add it again.
|
|
Jan 3 at 10:23 PM
Edited Jan 3 at 10:53 PM
|
The migration way, as I understand it, would just be a more data-driven approach. With the ActivatingFilter, you could apply some more logic to it if you wanted. You don't need to do both though. That wouldn't be necessary as far as I can
tell. For example, in the Orchard.Users module they only use the filter method.
|
|
|
|
They add UserPart with ActivatingFilter because UserPart doesn't implement driver interface is it true? Also can I imagin that both approch have the same result but they do it in two different ways? Or in specific situation I have to choose one of
them
|
|
|
|
The UserPart has a driver, but it's not using display methods for another reason. I think both approaches will accomplish the same end result. One approach is just data-driven and the other attaches the part on the fly as the item is being activated.
|
|