Skip to content
This repository has been archived by the owner on Feb 7, 2021. It is now read-only.

Upgrade wiki example How to modify the form objects used by LmcUser #40

Open
ezkimo opened this issue Sep 11, 2020 · 0 comments
Open

Upgrade wiki example How to modify the form objects used by LmcUser #40

ezkimo opened this issue Sep 11, 2020 · 0 comments

Comments

@ezkimo
Copy link

ezkimo commented Sep 11, 2020

The given wiki example for modifying objects used by LmcUser is not working anymore. With the current implementation of the Service Manager, the Laminas Framework offers a much more elegant way to modify the objects. The given example should be updated using Delegators instead of the onBootstrap method.

The following example adds placeholder attributes to the identity and credential form elements in the login form.

<?php
declare(strict_types=1);
namespace Application\ServiceManager\Factory;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\DelegatorFactoryInterface;

class LoginFormDelegatorFactory implements DelegatorFactoryInterface
{
    public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
    {
        $form = call_user_func($callback);
        
        $form->get('identity')->setAttribute('placeholder', 'username');
        $form->get('credential')->setAttribute('placeholder', 'password');
        
        return $form;
    }   
}

You have to register this delegator in your service manager configuration in the module.config.php file of your custom module, that implements the LmcUser module.

...
'service_manager' => [
    'delegators' => [
        'lmcuser_login_form' => [
            LoginFormDelegatorFactory::class,
        ],
    ],
],
...

The aliases for the delegator array entry can be taken from the Module.php file of the LmcUser module. The Module.php contains the service manager configuration inside the getServiceConfig() method. All used aliases are listed there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant