ifthenelse-8.x-1.x-dev-no-core/modules/contrib/if_then_else/if_then_else.module
modules/contrib/if_then_else/if_then_else.module
<?php
/**
* @file
* Ifthenelse Module file.
*/
use Drupal\if_then_else\Controller\IfThenElseController;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\UserInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\views\ViewExecutable;
/**
* Implements hook_form_alter().
*/
function if_then_else_form_alter(&$form, FormStateInterface &$form_state, $form_id) {
IfThenElseController::process('form_alter_event', [
'form' => &$form,
'form_state' => &$form_state,
'form_id' => $form_id,
]);
$form['#validate'][] = 'if_then_else_form_validation_handler';
// Added to skip triggering form submit for uninstall confirm form.
// It gives error for ifthenelserule entity doesn't exists.
if ($form_id != 'system_modules_uninstall_confirm_form') {
if (!empty($form['actions'])) {
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
if(isset($form['actions'][$action]['#submit'])){
$form['actions'][$action]['#submit'][] = 'if_then_else_form_submit_handler';
}else{
$form['#submit'][] = 'if_then_else_form_submit_handler';
}
}
}
}
else {
$form['#submit'][] = 'if_then_else_form_submit_handler';
}
}
}
/**
* Implements if_then_else_form_ifthenelserule_add_form_alter()
*/
function if_then_else_form_ifthenelserule_add_form_alter(&$form, &$form_state) {
$form['actions']['#weight'] = 0;
}
/**
* Implements if_then_else_form_ifthenelserule_edit_form_alter()
*/
function if_then_else_form_ifthenelserule_edit_form_alter(&$form, &$form_state) {
$form['actions']['#weight'] = 0;
}
/**
* Validation handler.
*
* @param object $form
* Form object.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state object.
*/
function if_then_else_form_validation_handler($form, FormStateInterface &$form_state) {
IfThenElseController::process('form_validate_event', [
'form' => $form,
'form_state' => &$form_state,
]);
}
/**
* Validation handler.
*
* @param object $form
* Form object.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state object.
*/
function if_then_else_form_submit_handler($form, FormStateInterface &$form_state) {
IfThenElseController::process('form_submission_event', [
'form' => $form,
'form_state' => &$form_state,
]);
}
/**
* Implements hook_user_login().
*/
function if_then_else_user_login(UserInterface $account) {
IfThenElseController::process('user_login_event', [
'user' => $account,
]);
}
/**
* Implements hook_user_logout().
*/
function if_then_else_user_logout($account) {
IfThenElseController::process('user_logout_event', [
'user' => $account,
]);
}
/**
* Implements hook_entity_load().
*/
function if_then_else_entity_load(array $entities, $entity_type_id) {
foreach ($entities as $entity) {
IfThenElseController::process('entity_load_event', [
'entity' => $entity,
]);
}
}
/**
* Implements hook_mail().
*/
function if_then_else_mail($key, &$message, $params) {
switch ($key) {
case 'send_email_if_then_else':
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
break;
}
}
/**
* Implements hook_entity_delete().
*/
function if_then_else_entity_delete(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
IfThenElseController::process('after_deleting_entity_event', [
'entity' => $entity,
]);
}
}
/**
* Implements hook_entity_insert().
*/
function if_then_else_entity_insert(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
IfThenElseController::process('after_saving_new_entity_event', [
'entity' => $entity,
]);
}
}
/**
* Implements hook_entity_update().
*/
function if_then_else_entity_update(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
IfThenElseController::process('after_saving_existing_entity_event', [
'entity' => $entity,
]);
}
}
/**
* Implements hook_entity_presave().
*/
function if_then_else_entity_presave(EntityInterface $entity) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
IfThenElseController::process('before_saving_entity_event', [
'entity' => $entity,
]);
}
}
/**
* Implements hook_entity_view().
*/
function if_then_else_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
IfThenElseController::process('entity_is_viewed_event', [
'entity' => $entity,
]);
}
}
/**
* Implements hook_cron().
*/
function if_then_else_cron() {
IfThenElseController::process('cron_maintenance_task_is_performed_event', []);
}
/**
* Implements hook_views_post_execute().
*/
function if_then_else_views_post_execute(ViewExecutable $view) {
IfThenElseController::process('view_is_loaded_event', [
'view' => $view,
]);
}
