021
Well-known member
.in order to extend the fields for saving, you need to extend a controller. For example:
I propose to add an event for this in FormAction:
Fire setup code
Hint will be like this:
Arguments:
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