2017-05-17 5 views
1

프런트 엔드에서 사용자가 링크를 클릭했을 때 팝업창에 내 사용자 정의 양식을 표시하고 싶습니다. 웹에서 보여주는 많은 해결책을 시도했지만 저를 위해 작동하지 않습니다.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을 확인하십시오. 여기에 하나 더 link이 도움이 될지 모르지만 둘 다 같지만 여전히 공유됩니다.

희망이 도움이됩니다.