Drupal hook

Hooks allow modules to alter and extend the behavior of Drupal core, or another module. They are one of the various ways that code components in Drupal can communicate with one another. Using hooks a module developer can change how core or another module works -- without changing the existing code.

By toswebdev, 18 April, 2023

Description

If you have an input field on your website with a font size of fewer than 16 pixels, Safari on iPhone considers the text too small to read and automatically zooms in on the form field when the user taps on it.

The behavior is intended but it can deteriorate the expected user experience so it might be a good idea to disable this functionality and keep the zoom static while filling form controls.

By toswebdev, 27 January, 2022
<?php

use Drupal\Core\Access\AccessResult;
 
...
 
/**
 * Implements hook_entity_access().
 */
function drupalbook_examples_entity_access(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Session\AccountInterface $account) {
  if ($entity->getEntityTypeId() == 'node' && $entity->getType() == 'article' && $operation == 'view' && in_array('administrator', $account->getRoles())) {
    AccessResult::forbidden();
  }
}

?>

There Main Three types AccessResult as Below 

By toswebdev, 27 January, 2022
/**
 * Implements hook_entity_presave().
 */
function drupalbook_examples_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
  if ($entity->getEntityTypeId() == 'node' && $entity->getType() == 'article') {
    $entity->title->value = $entity->title->value . 'by ' . date('d-m-Y');
  }
}

Hook_entity_presave () is fired every time an entity is saved.