New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/non js #1

Open
wants to merge 4 commits into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+17 −9
Diff settings

Always

Just for now

View
@@ -1,7 +1,8 @@
custom_modal.modal:
path: 'modal-example/modal'
path: 'modal-example/modal/{js}'
defaults:
_title: 'Modal'
_controller: '\Drupal\custom_modal\Controller\CustomModalController::modal'
requirements:
_permission: 'access content'
js: 'nojs|ajax'
@@ -10,16 +10,23 @@
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\OpenModalDialogCommand;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Response;
class CustomModalController extends ControllerBase {
public function modal() {
$options = [
'dialogClass' => 'popup-dialog-class',
'width' => '50%',
];
$response = new AjaxResponse();
$response->addCommand(new OpenModalDialogCommand(t('Modal title'), t('The modal text'), $options));
public function modal($js = 'nojs') {
if ($js == 'ajax') {
$options = [
'dialogClass' => 'popup-dialog-class',
'width' => '50%',
];
$response = new AjaxResponse();
$response->addCommand(new OpenModalDialogCommand(t('Modal title'), t('The modal text'), $options));
}
else {
$response = new Response();
$response->setContent('The modal text (Javascript is not enabled)');
}
return $response;
}
@@ -23,7 +23,7 @@ class ModalBlock extends BlockBase {
* {@inheritdoc}
*/
public function build() {
$link_url = Url::fromRoute('custom_modal.modal');
$link_url = Url::fromRoute('custom_modal.modal', ['js' => 'nojs']);
$link_url->setOptions([
'attributes' => [
'class' => ['use-ajax', 'button', 'button--small'],
ProTip! Use n and p to navigate between commits in a pull request.