Commit 7bafa033 authored by APolitsin's avatar APolitsin
Browse files

allow blank title

parent d280ac53
<?php
namespace Drupal\synhelper\Hook;
/**
* @file
* Contains \Drupal\synhelper\Hook\EntityPresave.
*/
use Drupal\Core\Controller\ControllerBase;
/**
* Controller routines for page example routes.
*/
class EntityPresave extends ControllerBase {
/**
* Page Callback.
*/
public static function hook($entity) {
if ($bundle = self::checkBundle($entity)) {
if (!$entity->name->value) {
$title = "$bundle - " . format_date(REQUEST_TIME, 'long');
$entity->name->setValue($title);
}
}
if ($type = self::checkNode($entity)) {
$type = $entity->getType();
if (!$entity->title->value) {
$title = "$type - " . format_date(REQUEST_TIME, 'long');
$entity->title->setValue($title);
}
}
}
/**
* Check Bundle.
*/
public static function checkBundle($entity) {
$result = FALSE;
if (method_exists($entity, 'bundle')) {
if (property_exists($entity, 'name')) {
$result = $entity->bundle();
}
}
return $result;
}
/**
* Check node.
*/
public static function checkNode($entity) {
$result = FALSE;
if (method_exists($entity, 'getType')) {
$result = $entity->getType();
}
return $result;
}
}
<?php
namespace Drupal\synhelper\Hook;
use Drupal\Core\Controller\ControllerBase;
/**
* AjaxContactForm.
*/
class FormSynmailSettingsAlter extends ControllerBase {
/**
* Hook.
*/
public static function hook(&$form, &$form_state, $form_id) {
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
$header = '';
if ($lang == 'ru' && isset($form['contact']['header']['#default_value'])) {
$header = $form['contact']['header']['#default_value'];
if (substr($header, 0, 26) == '<h2>Mail from website</h2>') {
$form['contact']['header']['#default_value'] = self::getRuHeader();
}
}
}
/**
* Ru Header.
*/
public static function getRuHeader() {
$ru_header = "
<h2>Вам письмо от сайта</h2>
<ul>
<li>Заявка пришла с технического адреса, не стоит нажимать 'ответить' и отправлять ответ нам.
E-mail клиента (если он его оставил) находится где-то в письме.</li>
<li>До того как начать писать e-mail посмотри - может клиент оставил телефон,
в таком случае лучше прямо сейчас ему позвонить, сообщить что заявка получена, и передана в работу.</li>
<ul>
<hr>
<h2>Содержимое заявки</h2>
";
return $ru_header;
}
}
......@@ -9,3 +9,31 @@ synhelper.settings:
parent: synhelper.page
description: 'Synapse Helper'
route_name: synhelper.settings
# Set synapse link.
synhelper.synapse-settings:
title: 'Synapse Settings'
parent: synhelper.page
description: 'Synapse Settings'
route_name: synapse.settings
# Set synmail link.
synhelper.synmail-settings:
title: 'Synmail Settings'
parent: system.admin_config_system
description: 'Synapse Settings'
route_name: synapse.settings
# Set synlanding link.
synhelper.synlanding-settings:
title: 'Synapse LP Settings'
parent: synhelper.page
description: 'Synapse Landind Settings'
route_name: synlanding.settings
# Set syntheme link.
synhelper.syntheme-settings:
title: 'Syn Theme Settings'
parent: synhelper.page
description: 'Syn Theme Settings'
route_name: syntheme.settings
......@@ -13,6 +13,15 @@ use Drupal\synhelper\Hook\FormContactMessageFormAlter;
use Drupal\synhelper\Hook\FormMenuEditFormAlter;
use Drupal\synhelper\Hook\FormNodePageFormAlter;
use Drupal\synhelper\Hook\FormNodePageEditFormAlter;
use Drupal\synhelper\Hook\FormSynmailSettingsAlter;
use Drupal\synhelper\Hook\EntityPresave;
/**
* Implements hook_entity_presave().
*/
function synhelper_entity_presave($entity) {
EntityPresave::hook($entity);
}
/**
* Implements hook_ENTITY_TYPE_presave().
......@@ -63,6 +72,13 @@ function synhelper_form_contact_message_form_alter(&$form, &$form_state, $form_i
FormContactMessageFormAlter::hook($form, $form_state, $form_id);
}
/**
* Implements hook_form_alter().
*/
function synhelper_form_synmail_settings_alter(&$form, $form_state, $form_id) {
FormSynmailSettingsAlter::hook($form, $form_state, $form_id);
}
/**
* Implements hook_form_alter().
*/
......
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