Commit 94b76de8 authored by APolitsin's avatar APolitsin
Browse files

reFa

parent 4cb1fc44
......@@ -7,70 +7,11 @@ namespace Drupal\synhelper\Controller;
* Contains \Drupal\app\Controller\AjaxResult.
*/
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\synhelper\Utility\AjaxResult as AjaxResultNew;
/**
* Controller routines for page example routes.
* Deprecated.
*/
class AjaxResult {
/**
* AJAX Responce.
*/
public static function ajax($wrapper, $otvet, $commands = FALSE) {
$output = '';
if ($otvet || $commands) {
$output .= '<pre>';
$output .= $otvet;
if (is_array($commands)) {
$output .= implode("\n", $commands);
}
$output .= '</pre>';
}
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand("#" . $wrapper, $output));
return $response;
}
/**
* AJAX Button.
*/
public static function button($function, $button = "Отправить", $color = 'primary') {
return [
'#type' => 'submit',
'#value' => $button,
'#attributes' => ['class' => ['btn', 'btn-xs', 'btn-' . $color]],
'#ajax' => [
'callback' => $function,
'effect' => 'fade',
'progress' => ['type' => 'throbber', 'message' => ""],
],
];
}
/**
* AJAX Button.
*/
public static function select($function, $options, $default) {
$default_value = FALSE;
if (isset($options[$default])) {
$default_value = $default;
}
else {
$default_value = 'select';
$options['select'] = 'Select';
}
return [
'#type' => 'select',
'#options' => $options,
'#default_value' => $default_value,
'#ajax' => [
'callback' => $function,
'effect' => 'fade',
'progress' => ['type' => 'throbber', 'message' => ""],
],
];
}
class AjaxResult extends AjaxResultNew {
}
......@@ -7,6 +7,7 @@ namespace Drupal\synhelper\Controller;
* Contains \Drupal\synhelper\Controller\Page.
*/
use Drupal\Core\Controller\ControllerBase;
use Drupal\synhelper\Utility\Logo;
/**
* Controller routines for page example routes.
......
......@@ -4,8 +4,8 @@ namespace Drupal\synhelper\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\synhelper\Controller\AjaxResult;
use Drupal\synhelper\Controller\MenuFix;
use Drupal\synhelper\Utility\AjaxResult;
use Drupal\synhelper\Utility\MenuFix;
/**
* Implements the form controller.
......
......@@ -39,9 +39,10 @@ class FormContactMessageFormAlter {
}
}
// Галочка ФЗ-152.
// FZ-152 checkbox.
if ($config->get('fz152') && strpos($form_id, 'contact_message') === 0) {
$url = Url::fromUserInput('/policy');
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
$text = [
'title' => t("I consent to the processing of personal data"),
'description' => t(
......@@ -49,10 +50,12 @@ class FormContactMessageFormAlter {
['@href' => $url->toString()]
),
];
$text = [
'title' => "Даю согласие на обработку персональных данных",
'description' => "<a href='/policy' target='_blank'>Политика обработки персональных данных</a>",
];
if ($lang == 'ru') {
$text = [
'title' => "Даю согласие на обработку персональных данных",
'description' => "<a href='/policy' target='_blank'>Политика обработки персональных данных</a>",
];
}
$form['fz152_agreement'] = [
'#type' => 'checkbox',
'#title' => $text['title'],
......@@ -73,7 +76,7 @@ class FormContactMessageFormAlter {
*/
public static function ajaxCallback($form, FormStateInterface &$form_state) {
$response = contact_ajax_contact_site_form_ajax_callback($form, $form_state);
// Проверяем валидность формы.
// Validate form.
$errors = $form_state->getErrors();
if (empty($errors)) {
$config = \Drupal::config('synhelper.settings');
......@@ -93,7 +96,7 @@ class FormContactMessageFormAlter {
$google = "if (typeof dataLayer != 'undefined') {dataLayer.push({'event': '{$formId}'});}";
if (isset($goals[$formId])) {
if ($counter) {
$yandex = "ym({$counter},'reachGoal','$goals[$formId]');";
$yandex = "ym({$counter},'reachGoal','{$goals[$formId]}');";
}
if ($config->get('debug')) {
$debug = "console.log('{$formId}');";
......
<?php
namespace Drupal\synhelper\Hook;
use Drupal\Core\Render\Markup;
/**
......@@ -34,7 +35,10 @@ class FormFieldConfigEditFormAlter {
if (isset($form['settings']['file_directory']['#default_value'])) {
$dir_path = $form['settings']['file_directory']['#default_value'];
if (!strpos("+$dir_path", $node_type)) {
$msg[] = t("FIX: wrong file_directory! @a=>@b", ['@a' => $dir_path, '@b' => $path]);
$msg[] = t("FIX: wrong file_directory! @a=>@b", [
'@a' => $dir_path,
'@b' => $path,
]);
$form['settings']['file_directory']['#default_value'] = $path;
}
if (empty($form['settings']['file_directory']['#default_value'])) {
......
......@@ -18,8 +18,9 @@ class NodePresave {
public static function hook($node) {
// Set Node-title id empty.
if (!$node->title->value) {
$title = $node->getType() . " - " . \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'long');
$node->title->setValue($title);
$type = $node->getType();
$date = \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'long');
$node->title->setValue("$type - $date");
}
}
......
<?php
namespace Drupal\synhelper\Utility;
/**
* @file
* Contains \Drupal\synhelper\Utility\AjaxResult.
*/
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\HtmlCommand;
/**
* Ajax staff.
*/
class AjaxResult {
/**
* AJAX Responce.
*/
public static function ajax($wrapper, $otvet, $commands = FALSE) {
$output = '';
if ($otvet || $commands) {
$output .= '<pre>';
$output .= $otvet;
if (is_array($commands)) {
$output .= implode("\n", $commands);
}
$output .= '</pre>';
}
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand("#" . $wrapper, $output));
return $response;
}
/**
* AJAX Button.
*/
public static function button($function, $button = "Отправить", $color = 'primary') {
return [
'#type' => 'submit',
'#value' => $button,
'#attributes' => ['class' => ['btn', 'btn-xs', 'btn-' . $color]],
'#ajax' => [
'callback' => $function,
'effect' => 'fade',
'progress' => ['type' => 'throbber', 'message' => ""],
],
];
}
/**
* AJAX Button.
*/
public static function select($function, $options, $default) {
$default_value = FALSE;
if (isset($options[$default])) {
$default_value = $default;
}
else {
$default_value = 'select';
$options['select'] = 'Select';
}
return [
'#type' => 'select',
'#options' => $options,
'#default_value' => $default_value,
'#ajax' => [
'callback' => $function,
'effect' => 'fade',
'progress' => ['type' => 'throbber', 'message' => ""],
],
];
}
}
<?php
namespace Drupal\synhelper\Controller;
namespace Drupal\synhelper\Utility;
/**
* @file
* Contains \Drupal\synhelper\Controller\Page.
* Contains \Drupal\synhelper\Utility\Logo.
*/
use Drupal\Core\Controller\ControllerBase;
/**
* Controller routines for page example routes.
* Syn svg Logo.
*/
class Logo extends ControllerBase {
class Logo {
/**
* Svg.
......
<?php
namespace Drupal\synhelper\Controller;
namespace Drupal\synhelper\Utility;
/**
* @file
* Contains \Drupal\synapse\Controller\Page.
* Contains \Drupal\synhelper\Utility\MenuFix.
*/
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\node\Entity\NodeType;
/**
* Controller routines for page example routes.
* Fix menu items.
*/
class MenuFix extends ControllerBase {
class MenuFix {
/**
* Page Callback.
......
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