I did read this answer ZF2, what's the best practice for working with Vendor Module's Form classes?. So it's mainly clear how to change configurable parts of the vendor module, but what do I do if in zfcUser module I want to add new functionality to the Entity/User?
In short I want to check user role, I've added to DB field, what's the best way to do that? Maybe I should do it somewhere else and not in zfcUSer if so where?
I won't be claiming this is a best practice, but this is how I managed to handle the situation! First - big thanks to answer in this question ZF2: Custom user mapper for ZfcUser module.
So, I did:
zfcUser/Entity
in zfc-user.global.php
autoload:
'zfcuser' => array( 'tableName' => 'users', 'user_entity_class' => 'Application\Entity\User' ),
Entity\User
, Mapper\User
and Mapper\Hydrator
into my src/Application
Entity and Mapper subfolders.Application\Entity
and Application\Mapper
Added this configuration to getServiceConfig
function of my Module.php
:
'factories' => [
'zfcuser_user_mapper' => function ($sm) {
$mapper = new Mapper\User();
$mapper->setDbAdapter($sm->get('Zend\Db\Adapter\Adapter'));
$mapper->setEntityPrototype(new Entity\User());
$mapper->setHydrator(new Mapper\UserHydrator());
return $mapper;
},
]
ZfcUSer
and started my Entity\User
as extends \ZfcUser\Entity\User implements \ZfcUser\Entity\UserInterface
.