バージョン選択

フォーラム

メニュー

オンライン状況

84 人のユーザが現在オンラインです。 (74 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 84
もっと...

サイト内検索

プラグイン > 開発について > form 内の choices をプラグイン側で変更したい

開発について

新規スレッドを追加する

フラット表示 前のトピック | 次のトピック
投稿者 スレッド
h_tanaka
投稿日時: 2017/6/13 11:12
対応状況: −−−
登録日: 2016/7/22
居住地: 愛媛県
投稿: 1646
Re: form 内の choices をプラグイン側で変更したい
フックポイント直後でchoicesを出力させるために次のように実装しましたがエラーになりました。
UndefinedMethodException in ShoppingController.php line 144:
Attempted to call an undefined method named "getConfig" of class "Eccube\Entity\Delivery".

src/Eccube/Controller/ShoppingController.php

$app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_SHOPPING_INDEX_INITIALIZE, $event);
$form = $builder->getForm();
$Shippings = $form->get('shippings')->getData();
if (!empty($Shippings)) {
    foreach ($Shippings as $key => $Shipping) {
        $Delivery = $Shipping->getDelivery();
        if ($Delivery) {
            $options = $Delivery->getConfig()->getOptions();
            $choices = $options['choices'];
            $choice_list = $options['choice_list']->getValues();
            var_dump($choice_list);
        }
    }
}


なお、プラグインは他に何も入れていません。

それから、FormEvents::POST_SET_DATA でのchoicesの変更も試してみましたが選択肢は変わらなかったです。

app/Plugin/Test/Form/Extension/ShoppingTypeExtension.php

class ShoppingTypeExtension extends AbstractTypeExtension
{
    public $app;

    public function __construct($app)
    {
        $this->app = $app;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $app = $this->app;
        if ($app->isGranted('ROLE_ADMIN')) {
            return;
        }

        $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($app) {
            $delivery_id = null;
            $form = $event->getForm();
            $Shippings = $form->get('shippings');
            if (!empty($Shippings)) {
                foreach ($Shippings as $key => $Shipping) {
                    $deliveries = null;
                    $Shipping->remove('delivery');
                    $Shipping
                        ->add('delivery', 'entity', array(
                            'class' => 'Eccube\Entity\Delivery',
                            'property' => 'name',
                            'choices' => $deliveries,
    //                        'data' => $delivery,
                            'constraints' => array(
                                new Assert\NotBlank(),
                            ),
                        ));
                }
            }
        });
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
    }

    public function getExtendedType()
    {
        return 'shopping';
    }
}


----------------
EC-CUBE 《プラチナ》ランクパートナー
トエビス株式会社 田中 宏典
EC-CUBEの機能やデザインのカスタマイズ承ります。

フラット表示 前のトピック | 次のトピック


題名 投稿者 日時
   form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/12 17:02
     Re: form 内の choices をプラグイン側で変更したい hata 2017/6/12 19:16
       Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 10:14
         Re: form 内の choices をプラグイン側で変更したい hata 2017/6/13 10:23
           Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 10:31
             Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 10:38
             Re: form 内の choices をプラグイン側で変更したい hata 2017/6/13 10:56
             » Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 11:12
                 Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 11:27
                   Re: form 内の choices をプラグイン側で変更したい hata 2017/6/13 11:58
                     Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 12:35
                       Re: form 内の choices をプラグイン側で変更したい hata 2017/6/13 12:55
                         Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 14:27
                           Re: form 内の choices をプラグイン側で変更したい hata 2017/6/13 14:43
                             Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 14:53
                               Re: form 内の choices をプラグイン側で変更したい hata 2017/6/13 15:17
                                 Re: form 内の choices をプラグイン側で変更したい h_tanaka 2017/6/13 15:28

 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,973名です
総投稿数は110,019件です

投稿数ランキング

1
seasoft
7367
2
468
3217
3
AMUAMU
2712
4
nanasess
2314
5
umebius
2085
6
yuh
1819
7
h_tanaka
1646
8
red
1570
9
mcontact
1296
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
799
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.