Articles

Drupal also supports transactions, including a transparent fallback for databases that do not support transactions. However, transactions can be quite tricky if you try to run two transactions simultaneously. Behavior in such cases also depends on the database.
A similar issue exists with nested locks in C / C++. If code has already acquired lock A and tries to acquire lock A again, the code will block. If you write code that checks whether it already holds the lock and avoids acquiring it again, you can prevent deadlocks, but you might release the lock prematurely.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

The Drupal database layer does not provide cross-database abstraction for SQL functions. To ensure portability across supported database engines, your code should use only those functions that are known to be part of the ANSI standard and supported in all databases supported by Drupal. The following is still an incomplete list. The form used here is recommended, as other syntax variants may not work across all databases.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

The Drupal 8 Entity System
Entities are typed classes with methods.
Generic methods |
$entity->id() |

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

- Drupal 7 - Entities were generic stdClass objects.
- Drupal 8 - Entities are now strongly typed objects, with each entity type defining the class used for its instances.
Requirements
Entity classes must reside in the Entity namespace of the module that provides the entity type, e.g., \Drupal\[module_name]\Entity. This means the PHP files for Entity classes can be found in the module's src/Entity directory.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

This cheat sheet provides an overview of commonly used methods, classes, and interfaces for content entities.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Configuration entities use the Entity API to store configuration in the database.
Differences Compared to Content Entities
- Integrated with the CMI API for exportability
- No fields
- Uses a schema file (Content Entities use hook_schema())
Tutorials

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

This cheat sheet provides an overview of commonly used methods, classes, and interfaces for content entities.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Audience
This documentation is primarily intended for developers experienced in object-oriented PHP, Drupal 6 or Drupal 7, and for those looking to explore the principles of Drupal 8.
The guide to creating a content entity type in Drupal 8 contains a full list of available options.
Building a Bundle-less Content Type in Drupal 8
In this case, we are creating a Drupal 8 content entity that does not have any bundles.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

This page is a copy of Enable-by-default configuration in a Drupal 8 module. This should be considered deprecated.
Creating a custom content type has become quite straightforward thanks to the new Configuration API provided by Drupal 8.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.

Sometimes, when extracting a content type from a custom module, you may want to include fields associated with that content type. Automatically creating fields allows you to remove and reinstall on multiple sites without leaving behind unnecessary fields and ensures you don’t forget to add them. There are two ways to add these fields to your codebase, which we’ll cover here.

Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.