Created
April 15, 2015 00:54
-
-
Save larowlan/0e55ccee31be29d77639 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains Drupal\modal_test\Controller\ModalForm. | |
*/ | |
namespace Drupal\modal_test\Controller; | |
use Drupal\Core\Ajax\AjaxResponse; | |
use Drupal\Core\Ajax\CloseModalDialogCommand; | |
use Drupal\Core\Form\FormBase; | |
use Drupal\Core\Form\FormStateInterface; | |
class ModalForm extends FormBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getFormId() { | |
return 'modal_test_context_configure'; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function buildForm(array $form, FormStateInterface $form_state, $context = NULL) { | |
$form['context'] = [ | |
'#type' => 'value', | |
'#value' => $context | |
]; | |
$form['label'] = [ | |
'#type' => 'textfield', | |
'#title' => $this->t('Label'), | |
]; | |
$form['description'] = [ | |
'#type' => 'textarea', | |
'#title' => $this->t('Description'), | |
]; | |
$form['submit'] = [ | |
'#type' => 'submit', | |
'#value' => $this->t('Save'), | |
'#ajax' => [ | |
'callback' => [$this, 'ajaxSubmit'], | |
'event' => 'click', | |
], | |
]; | |
return $form; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function submitForm(array &$form, FormStateInterface $form_state) { | |
// Do stuff if JavaScript is disabled. | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function ajaxSubmit(array &$form, FormStateInterface $form_state) { | |
// Do stuff to save via JavaScript. | |
$response = new AjaxResponse(); | |
$response->addCommand(new CloseModalDialogCommand()); | |
return $response; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment