読み込みが終了しない場合は、しばらく待つか、リロードを行なってください。
If loading does not finish, wait for a while or reload.
エンジニア向けの情報を発信するブログです。
どなたでも発信できます。
お好きに利用していただれば幸いです。
📁 app\Customize\Controller\Admin\AdminController.php <?php namespace Customize\Controller\Admin; use Eccube\Controller\AbstractController; use Eccube\Event\EccubeEvents; use Eccube\Event\EventArgs; use Eccube\Form\Type\Admin\LoginType; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; class AdminController extends AbstractController { private $authorizationChecker; private $helper; public function __construct( AuthorizationCheckerInterface $authorizationChecker, AuthenticationUtils $helper ) { $this->authorizationChecker = $authorizationChecker; $this->helper = $helper; } /** * @Route("/%eccube_admin_route%/login", name="admin_login", methods={"GET", "POST"}) * @Template("@admin/login.twig") */ public function login(Request $request) { if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) { return $this->redirectToRoute('admin_homepage'); } /* @var $form \Symfony\Component\Form\FormInterface */ $builder = $this->formFactory->createNamedBuilder('', LoginType::class); $event = new EventArgs( [ 'builder' => $builder, ], $request ); $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ADMIM_LOGIN_INITIALIZE, $event); $form = $builder->getForm(); return [ 'error' => $this->helper->getLastAuthenticationError(), 'form' => $form->createView(), ]; } }
// ~~ 省略 public function login(Request $request) { if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) { return $this->redirectToRoute('admin_homepage'); } /* @var $form \Symfony\Component\Form\FormInterface */ $builder = $this->formFactory->createNamedBuilder('', LoginType::class); // 👈 こいつ // ~~ 省略
use Eccube\Form\Type\Admin\LoginType;
📁 src/Eccube/Form/Type/Admin/LoginType.php <?php /* * This file is part of EC-CUBE * * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved. * * http://www.ec-cube.co.jp/ * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Eccube\Form\Type\Admin; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\PasswordType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints as Assert; class LoginType extends AbstractType { /** * @var SessionInterface */ protected $session; public function __construct(SessionInterface $session) { $this->session = $session; } /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('login_id', TextType::class, [ 'attr' => [ 'maxlength' => 50, ], 'constraints' => [ new Assert\NotBlank(), ], 'data' => $this->session->get('_security.last_username'), ]); $builder->add('password', PasswordType::class, [ 'attr' => [ 'maxlength' => 50, ], 'constraints' => [ new Assert\NotBlank(), ], ]); } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'csrf_protection' => false, ]); } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'admin_login'; } }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('login_id', TextType::class, [ 'attr' => [ 'maxlength' => 50, ], 'constraints' => [ new Assert\NotBlank(), ], 'data' => $this->session->get('_security.last_username'), ]); $builder->add('password', PasswordType::class, [ 'attr' => [ 'maxlength' => 50, ], 'constraints' => [ new Assert\NotBlank(), ], ]); }
// ~~ 省略 use Symfony\Component\Form\Extension\Core\Type\PasswordType; 👈 追加 use Symfony\Component\Form\Extension\Core\Type\TextType; 👈 追加 // ~~ 省略 $this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ADMIM_LOGIN_INITIALIZE, $event); $form = $builder->getForm(); // 👇 ここから $login_id_form_type = $form->get('login_id')->getConfig()->getType()->getInnerType(); $password_form_type = $form->get('password')->getConfig()->getType()->getInnerType(); if ($login_id_form_type instanceof TextType) { echo 'こんにちお'; } if ($password_form_type instanceof PasswordType) { echo 'こんばんお'; } // 👆 ここまで追加 return [ 'error' => $this->helper->getLastAuthenticationError(), 'form' => $form->createView(), ]; // ~~ 省略