Last active
July 11, 2024 13:51
-
-
Save ygerasimov/b27db8b9cde8d6d779dcc03e12da106c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_entity_access(). | |
*/ | |
function HOOK_entity_access(EntityInterface $entity, $operation, AccountInterface $account) { | |
// Only allow access to the test page. | |
$testPageNid = 111111; | |
if ((int) $entity->id() !== $testPageNid) { | |
return AccessResult::neutral(); | |
} | |
$allowlist = [ | |
// Diffy. | |
'3.216.56.216', | |
// Me. | |
'22.222.22.222', | |
]; | |
$requestIP = \Drupal::request()->getClientIp(); | |
$isOnAllowlist = in_array($requestIP, $allowlist, TRUE); | |
return AccessResult::allowedIf($isOnAllowlist); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment