Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codeenigma/entity-validation-examples
Drupal 8 Entity Validation API examples to accompany a blog post
https://github.com/codeenigma/entity-validation-examples
drupal drupal8
Last synced: 4 months ago
JSON representation
Drupal 8 Entity Validation API examples to accompany a blog post
- Host: GitHub
- URL: https://github.com/codeenigma/entity-validation-examples
- Owner: codeenigma
- License: mit
- Created: 2018-07-18T10:54:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-24T13:24:46.000Z (over 6 years ago)
- Last Synced: 2024-09-27T10:41:08.987Z (5 months ago)
- Topics: drupal, drupal8
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 6
- Watchers: 6
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Entity Validation Examples
This Drupal 8 module accompanies a Code Enigma blog post.
It illustrates how to use the Drupal 8 Entity Validation API to add different validation
constraints to the entity creation process.Blog post: [Introduction to Drupal 8 Entity Validation](https://blog.codeenigma.com/introduction-to-drupal-8-entity-validation-f0aa37c1f9a3)
The examples are kept short and avoid anything that is not related to the
actual topic of entity validation.## Example 1: ArticleLimitConstraint
This example limits the creation of nodes of the type article to a
specified number (2).In a real-world scenario this limit would probably be configured using
a configuration form, or specified with a config variable in settings.php.The module does the following:
1. Defines a new constraint: ```ArticleLimitConstraint```.
2. Defines a new constraint validator: ```ArticleLimitConstraintValidator```
3. Attaches the constraint to entities of the type _node_ using a
```hook_entity_type_alter``` implementation.### How to test
To test this functionality:
* Enable the module.
* Create 2 articles.
* Attempt to create a 3rd article and notice the error message.## Example 2
Coming soon.