PHPackages                             gabesullice/entity\_access\_policies - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. gabesullice/entity\_access\_policies

ActiveDrupal-module[Authentication &amp; Authorization](/categories/authentication)

gabesullice/entity\_access\_policies
====================================

Provide custom access policies for any entity

0401PHP

Since Jun 21Pushed 8y agoCompare

[ Source](https://github.com/gabesullice/entity_access_policies)[ Packagist](https://packagist.org/packages/gabesullice/entity_access_policies)[ RSS](/packages/gabesullice-entity-access-policies/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Entity Access Policies
======================

[](#entity-access-policies)

Entity Access Policies let you express fine-grained access control rules for any Drupal 8 entity type.

The concept is simple. You put your entities under lock and key.

**Warning**: This is *alpha* software. In fact, the concepts here are under [active discussion on Drupal.org](https://www.drupal.org/node/777578) and some really insightful ideas are being proposed by lots of people. This is an experimental implementation that is subject to change.

Overview
--------

[](#overview)

Inspired by the `hook_node_grants` and `hook_node_access_records` system, Entity Access Policies are incredibly flexible while being much easier to understand and applicable beyond just nodes.

Entity access policies are plugins, just like blocks in Drupal 8.

You can define your own custom access policy with just two files:

1. A module `info.yml`
2. And a file at `src/Plugin/entity_access_policies/Policy/YourCustomPolicy.php`.

The module directory tree would look like this:

```
custom_module/
  custom_module.info.yml
  src/
    Plugin/
      entity_access_policies/
        Policy/
          YourCustomPolicy.php

```

The Policy File
---------------

[](#the-policy-file)

The policy file is pretty simple, a policy is just a class that has three methods: `getLocks()`, `getKeys()`, and `applies()`.

You also have to tell Drupal about your policy class with a simple annotation.

Here's an example:

```
