Lack of interest FormAction setup code event listener

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

021

Well-known member
.in order to extend the fields for saving, you need to extend a controller. For example:
PHP:
class UserUpgrade extends XFCP_UserUpgrade
{
    protected function upgradeSaveProcess(\XF\Entity\UserUpgrade $upgrade)
    {
        $form = parent::upgradeSaveProcess($upgrade);

        $form->setupEntityInput($upgrade, $this->filter([
            'field' => 'uint'
        ]));

        return $form;
    }
}

I propose to add an event for this in FormAction:

PHP:
....
foreach ($this->setup AS $setup)
{
    $setup($this);
    $this->fireSetup($setup);
}
$this->doneSetup();
....

Fire setup code
PHP:
protected $setupFired = [];

protected function fireSetup(\Closure $setup)
{
    $funcVariables = (new \ReflectionFunction($setup))->getStaticVariables();

    $entities = array_filter($funcVariables, fn($v) => $v instanceof \XF\Mvc\Entity\Entity);

    $app = \XF::app();
    $request = $app->request();
    $controllerAction = $app->router()->getControllerAction(); // must return "XF\Admin\Controller\Example@action" | "XF\Pub\Controller\Example@action"

    /** @var \XF\Mvc\Entity\Entity $entity */
    foreach ($entities as $entity) {
        $hint = $this->setupHint($entity, $controllerAction);
        if (isset($this->setupFired[$hint])) {
            continue;
        }

        \XF::fire('form_action_setup', [$this, $entity, $request], $hint);
        $this->setupFired[$hint] = true;
    }
}

protected function setupHint(\XF\Mvc\Entity\Entity $entity, $controllerAction)
{
    $rootClass = \XF::extension()->resolveExtendedClassToRoot($entity);
    return $controllerAction.':'.$rootClass;
}

protected function doneSetup()
{
    $this->setupFired = [];
}


Hint will be like this: XF\Admin\Controller\UserUpgrade@save:XF\Entity\UserUpgrade
Arguments: \XF\Mvc\FormAction $form, \XF\Mvc\Entity\Entity $entity, \XF\Http\Request $request
 
Last edited:
Upvote 2
This suggestion has been closed. Votes are no longer accepted.
Back
Top Bottom