Book Image

Drupal 8 Development Cookbook - Second Edition

By : Matt Glaman
Book Image

Drupal 8 Development Cookbook - Second Edition

By: Matt Glaman

Overview of this book

Began as a message board, Drupal today is open source software maintained and developed by a community of over 1,000,000 users and developers. Drupal is used by numerous local businesses to global corporations and diverse organizations all across the globe. With Drupal 8’s exciting features it brings, this book will be your go-to guide to experimenting with all of these features through helpful recipes. We’ll start by showing you how to customize and configure the Drupal environment as per your requirements, as well as how to install third-party libraries and then use them in the Drupal environment. Then we will move on to creating blocks and custom modules with the help of libraries. We will show you how to use the latest mobile-first feature of Drupal 8, which will help you make your apps responsive across all the major platforms. This book will also show you how to incorporate multilingual facilities in your sites, use web services and third-party plugins with your applications from inside Drupal 8, and test and deploy your apps.
Table of Contents (20 chapters)
Title Page
About the Author
About the Reviewer
Customer Feedback

Implementing custom access control for an entity

All entities have a set of handlers that control specific pieces of functionalities. One handler handles access control. When the access handler is not specified, the base \Drupal\Core\Entity\EntityType module will implement \Drupal\Core\Entity\EntityAccessControlHandler as the access handler. By default, this will check whether any modules have implemented hook_entity_create_access or hook_entity_type_create_access and use their opinions. Otherwise, it defaults to the admin permission for the entity type, if implemented.

In this recipe, we will provide an admin permission for our entity and implement the access handler and permission provider available through the Entity API module. We will base this on an entity called Message.


This recipe specifically uses the functionality from the Entity API module because it has been tested and thoroughly reviewed and reduces boilerplate code. Ideally, this will be part of an upcoming minor release...