Commit 6021812e authored by APolitsin's avatar APolitsin
Browse files

add syndev hooks

parent 31b8cc8d
<?php
namespace Drupal\synhelper\Hook;
use Drupal\Core\Controller\ControllerBase;
/**
* FileValidate.
*/
class CssAlter extends ControllerBase {
/**
* Hook.
*/
public static function hook(&$css) {
// Embede CSS files as <link> elements.
$system_css_preprocess = \Drupal::config('system.performance')->get('css.preprocess');
if (!$system_css_preprocess) {
foreach ($css as $key => $value) {
if (strpos($value['data'], 'core/') !== 0) {
$css[$key]['preprocess'] = FALSE;
}
}
}
}
}
<?php
namespace Drupal\synhelper\Hook;
use Drupal\Core\Controller\ControllerBase;
/**
* AjaxContactForm.
*/
class FormFieldConfigEditFormAlter extends ControllerBase {
/**
* Hook.
*/
public static function hook(&$form, $form_state, $form_id) {
$current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $current_path);
// File.
if (isset($form['settings']['max_filesize']['#default_value'])) {
drupal_set_message('Это Файл! syndev.module\form_alter');
$form['settings']['max_filesize']['#default_value'] = '25 MB';
if (isset($form['settings']['file_directory'])) {
$node_type = $path_args[5];
$path = $node_type . '/[date:custom:Y]';
$form['settings']['file_directory']['#default_value'] = $path;
}
if (isset($form['settings']['file_extensions'])) {
$file_types = 'txt, jpg, jpeg, png, doc, docx, pdf, ods, xlsx, xls, zip, rar';
$form['settings']['file_extensions']['#default_value'] = $file_types;
}
}
// Картинка.
if (isset($form['settings']['max_resolution'])) {
drupal_set_message('Это Картинка! syndev.module\form_alter');
if (isset($form['settings']['max_resolution']['x']['#default_value']) && $form['settings']['max_resolution']['x']['#default_value'] == '') {
$form['settings']['max_resolution']['x']['#default_value'] = '2000';
}
if (isset($form['settings']['max_resolution']['y']['#default_value']) && $form['settings']['max_resolution']['y']['#default_value'] == '') {
$form['settings']['max_resolution']['y']['#default_value'] = '1300';
}
if (isset($form['settings']['min_resolution']['x']['#default_value']) && $form['settings']['min_resolution']['x']['#default_value'] == '') {
$form['settings']['min_resolution']['x']['#default_value'] = '800';
}
if (isset($form['settings']['min_resolution']['y']['#default_value']) && $form['settings']['min_resolution']['y']['#default_value'] == '') {
$form['settings']['min_resolution']['y']['#default_value'] = '600';
}
$form['settings']['alt_field_required']['#default_value'] = FALSE;
if (isset($form['settings']['max_filesize']['#default_value']) && $form['settings']['max_filesize']['#default_value'] == '') {
$form['settings']['max_filesize']['#default_value'] = '5 MB';
}
if (isset($form['settings']['file_extensions'])) {
$file_types = 'gif, jpg, jpeg, png';
$form['settings']['file_extensions']['#default_value'] = $file_types;
}
}
if ($form['label']['#default_value'] == 'Прикрепленные файлы' && isset($form['settings'])) {
drupal_set_message('Прикрепленные файлы: кастом конфиг ' . __FUNCTION__);
$form['settings']['description_field']['#default_value'] = TRUE;
}
if ($form['label']['#default_value'] == 'Галерея' && isset($form['settings'])) {
drupal_set_message('Галерея: кастом конфиг ' . __FUNCTION__);
}
}
}
<?php
namespace Drupal\synhelper\Hook;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\Markup;
/**
* AjaxContactForm.
*/
class FormFieldUiFieldStorageAddFormAlter extends ControllerBase {
/**
* Hook.
*/
public static function hook(&$form, &$form_state, $form_id) {
// TODO: добавить реакцию на адрес:
// /machine_name/transliterate?text=Текст-для-перевода
// &langcode=ru&replace_pattern=%5B%5Ea-z0-9_%5D%2B&replace=_&lowercase=true.
$message = "Обязательно поставь машинный тип материала в техническое поле!<br>
Например для Команды (team) должность должна быть field_[team_position]<br>
Когда-нибудь мы поймём как это сделать автоматически в " . __CLASS__;
drupal_set_message(Markup::create($message), 'warning');
}
}
<?php
namespace Drupal\synhelper\Hook;
use Drupal\Core\Controller\ControllerBase;
/**
* AjaxContactForm.
*/
class FormNodeTypeAddFormAlter extends ControllerBase {
/**
* Hook.
*/
public static function hook(&$form, &$form_state, $form_id) {
$form['submission']['title_label']['#default_value'] = '';
$form['submission']['preview_mode']['#default_value'] = 0;
$form['workflow']['options']['#default_value'] = ['status', 'revision'];
$form['display']['display_submitted']['#default_value'] = FALSE;
$form['menu']['menu_options']['#default_value'] = [];
}
}
<?php
namespace Drupal\synhelper\Hook;
use Drupal\Core\Controller\ControllerBase;
/**
* AjaxContactForm.
*/
class FormUpdateManagerInstallFormAlter extends ControllerBase {
/**
* Hook.
*/
public static function hook(&$form, &$form_state, $form_id) {
unset($form['project_url']);
unset($form['information']);
unset($form['project_upload']);
$form['#prefix'] = '<h3>Access denied by syndev</h3>
<p>Use composer require drupal/MODULENAME in drupal root folder.';
}
}
......@@ -15,6 +15,11 @@ use Drupal\synhelper\Hook\FormNodePageFormAlter;
use Drupal\synhelper\Hook\FormNodePageEditFormAlter;
use Drupal\synhelper\Hook\FormSynmailSettingsAlter;
use Drupal\synhelper\Hook\EntityPresave;
use Drupal\synhelper\Hook\CssAlter;
use Drupal\synhelper\Hook\FormUpdateManagerInstallFormAlter;
use Drupal\synhelper\Hook\FormFieldUiFieldStorageAddFormAlter;
use Drupal\synhelper\Hook\FormNodeTypeAddFormAlter;
use Drupal\synhelper\Hook\FormFieldConfigEditFormAlter;
/**
* Implements hook_entity_presave().
......@@ -23,6 +28,41 @@ function synhelper_entity_presave($entity) {
EntityPresave::hook($entity);
}
/**
* Hook_css_alter() to embede CSS files as <link> elements.
*/
function syndev_css_alter(&$css) {
CssAlter::hook($css);
}
/**
* Implements hook_form_FORM_ID_alter() for field_ui_field_storage_add_form().
*/
function syndev_form_field_ui_field_storage_add_form_alter(&$form, $form_state, $form_id) {
FormFieldUiFieldStorageAddFormAlter::hook($form, $form_state, $form_id);
}
/**
* Implements hook_form_FORM_ID_alter() for node_type_add_form().
*/
function syndev_form_node_type_add_form_alter(&$form, $form_state, $form_id) {
FormNodeTypeAddFormAlter::hook($form, $form_state, $form_id);
}
/**
* Implements hook_form_FORM_ID_alter() for field_config_edit_form().
*/
function syndev_form_field_config_edit_form_alter(&$form, $form_state, $form_id) {
FormFieldConfigEditFormAlter::hook($form, $form_state, $form_id);
}
/**
* Implements hook_form_FORM_ID_alter() for node_page_form().
*/
function syndev_form_update_manager_install_form_alter(&$form, $form_state, $form_id) {
FormUpdateManagerInstallFormAlter::hook($form, $form_state, $form_id);
}
/**
* Implements hook_ENTITY_TYPE_presave().
*/
......
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