2017-05-17 12 views
1

フロントエンドからリンクをクリックしたときにポップアップでカスタムフォームを表示したいのですが、Webで表示される多くのソリューションを試してみましたが、うまくいきません。Drupal 8カスタムフォーム(ポップアップあり)

ここに私のコードです。

 $response = new AjaxResponse(); 
     // Get the modal form using the form builder. 
     $modal_form = $this->formBuilder->getForm('Drupal\fwsactions\Forms\FwsActionsForm'); 
     $modal_form['#attached']['library'][] = 'core/drupal.dialog.ajax'; 
     // Add an AJAX command to open a modal dialog with the form as the content. 
     $modal_form = render($modal_form); 
     $response->addCommand(new OpenModalDialogCommand('My Modal Form', $modal_form, ['width' => '800'])); 

     return $response; 

リンクをクリックしてこのフォームを開くにはどうすればよいですか。

答えて

3
$content['overlay_link'] = array(
    '#type' => 'link', 
    '#title' => $this->t('Add movie'), 
    '#url' => Url::fromRoute('node.add', ['node_type' => 'content_type_movie']), 
    '#attributes' => [ 
     'class' => ['use-ajax'], 
     'data-dialog-type' => 'modal', 
     'data-dialog-options' => Json::encode([ 
     'width' => 700, 
     ]), 
    ], 
    ); 

詳細については、hereを確認してください。 もう1つはlinkですが、どちらも同じですがまだ共有していますが、助けになるかもしれません。

これが役に立ちます。