我有一个实体,我在登录页面上扩展但在下一页上扩展不存在(实体在两个页面上都存在)。有没有办法让我的扩展在下一页可用?
<?php
namespace RegistrationExtension\Subscriber;
use ...
class RegisterExtensionSubscriber implements EventSubscriberInterface{
private $company;
/**
* @var EntityRepositoryInterface
*/
private $mailTypeRepository;
/**
* @var EntityRepositoryInterface
*/
private $mailRepository;
/**
* @var EntityRepositoryInterface
*/
private $customerRepo;
public function __construct(
EntityRepositoryInterface $customerRepo,
EntityRepositoryInterface $mailTypeRepository,
EntityRepositoryInterface $mailRepository
) {
$this->customerRepo = $customerRepo;
$this->mailTypeRepository = $mailTypeRepository;
$this->mailRepository = $mailRepository;
}
public static function getSubscribedEvents(): array{
return [
AccountLoginPageLoadedEvent::class => 'extendCustomer',
AccountOverviewPageLoadedEvent::class => 'onCustomRegister'
];
}
此函数在登录页面完成加载时触发。
public function extendCustomer(AccountLoginPageLoadedEvent $event){
// if (isset($_POST['submit'])) {
if(isset($_GET["email"])){
$company = $_GET["email"];
}else{
$company = null;
}
$mailEntity = $this->mailTypeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template_type.technicalName', "customer_register")),
$event->getContext()
);
if ($mailType = $mailEntity->getEntities()->first()) {
$mailEntity = $this->mailRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template.mailTemplateTypeId', $mailType->getId())),
$event->getContext()
);
$mailEntity->getEntities()->first()->addExtension('file_does_exist', new ArrayEntity(['company' => "blub"]));
dump($mailEntity->getEntities()->first());
}
// }
}
此函数在用户登录并且页面完成加载后触发。
public function onCustomRegister(AccountOverviewPageLoadedEvent $event){
$mailEntity = $this->mailTypeRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template_type.technicalName', "customer_register")),
$event->getContext()
);
if ($mailType = $mailEntity->getEntities()->first()) {
$mailEntity = $this->mailRepository->search(
(new Criteria())->addFilter(new EqualsFilter('mail_template.mailTemplateTypeId', $mailType->getId())),
$event->getContext()
);
dump($mailEntity);
// $mail = $mailEntity->getEntities()->first()->addExtension('file_does_exist', new ArrayEntity(['company' => $company]));
}
$customerEntity = $this->customerRepo->search(
(new Criteria())->addFilter(new EqualsFilter('customer.customerNumber', $event->getSalesChannelContext()->getCustomer()->getCustomerNumber())),
$event->getContext()
);
}
}
难道是AccountOverviewPageLoadedEvent事件加载了beo?