Commit 6558fd45 authored by Telenkov Ruslan's avatar Telenkov Ruslan

this is modal window task

parent 3f784168
<?php
/**
* Implements hook_theme().
*/
function formApi_theme($existing, $type, $theme, $path) {
return [
'form_theme' => [
'variables' => [],
],
];
}
/**
* Implements template_preprocess_HOOK().
* Обработчик переменных для первого примера.
*/
function template_preprocess_form_theme(&$variables) {
$myConfigPage = \Drupal\config_pages\Entity\ConfigPages::config('custom_config');
$variables['string_modal'] = $myConfigPage->get('field_modal_title')->value;
$current_user = \Drupal::currentUser();
$user = \Drupal\user\Entity\User::load($current_user->id());
$name = $user->get('name')->value;
$user_last_name = $user->field_last_name->value;
if ($name == NULL){
$variables['result'] = $variables['string_modal'].", гость!";
}
else {
$variables['result'] = $variables['string_modal']. ', ' . $user_last_name. ' ' .$name;
}
}
......@@ -14,7 +14,7 @@ use Drupal\Core\Ajax\RedirectCommand;
use Drupal\Core\Ajax\RemoveCommand;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\OpenModalDialogCommand;
class FormApiTask extends FormBase {
/**
* {@inheritdoc}
......@@ -189,7 +189,11 @@ class FormApiTask extends FormBase {
])
->execute();
$response->addCommand(new AlertCommand('Спасибо за заполнение, нажмите "OK" для продолжения'));
$content1['#attached']['library'][] = 'core/drupal.dialog.ajax';
$content1['#theme'] = 'form_theme';
$title = 'Сообщение';
$response->addCommand(new OpenModalDialogCommand($title, $content1, ['width' => '200', 'height' => '200']));
//$response->addCommand(new AlertCommand('Спасибо за заполнение, нажмите "OK" для продолжения'));
$url = '/';
$response->addCommand(new RedirectCommand($url));
......
......@@ -30,7 +30,7 @@ function myservice_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form
if ($form_id == 'contact_message_contact_form_form') {
$current_user = \Drupal::currentUser();
$user = \Drupal\user\Entity\User::load($current_user->id());
$name = $user->name->value;
$name = $user->get('name')->value;
$user_last_name = $user->field_last_name->value;
$form['field_last_name']['widget'][0]['value']['#default_value'] = $user_last_name;
$form['field_name']['widget'][0]['value']['#default_value'] = $name;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment