You are here

disable_user_1_edit.module in Disable user 1 edit 8

Disable user 1 edit module.

File

disable_user_1_edit.module
View source
<?php

/**
 * @file
 * Disable user 1 edit module.
 */
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;

/**
 * Implements hook_ENTITY_TYPE_access().
 */
function disable_user_1_edit_user_access(EntityInterface $entity, $operation, AccountInterface $account) {
  if ($entity
    ->id() == 1) {

    // Return a permission that definitely does not exist. Just to be 100% sure,
    // we add some random data to this, since I guess a module can provide this
    // abyss permission.
    $config = \Drupal::config('disable_user_1_edit.settings');
    if (empty($config
      ->get('disabled'))) {
      return AccessResult::forbiddenIf(!$account
        ->hasPermission('Stare into the abyss ' . uniqid()));
    }
  }
  return AccessResult::neutral();
}

Functions