- Creates a custom content entity name Movie with the fields title and release date
- Create a taxonomy vocabulary named Genre with the following terms: Comedy, Drama, and Action.
- Add a genre field to the movie entity that is a reference to the Genre vocabulary.
- Add validation to the movie entity’s add and edit forms so that the release_date field is required and that it cannot be in the future.
- Expose a REST export for all the Movie entities.
Download and install as any other drupal module.
- Add
david4lim/custom_movies
to yourcomposer.json
repositories:
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "package",
"package": {
"name": "david4lim/custom_movies",
"version": "dev-master",
"type":"drupal-custom-module",
"source": {
"url": "https://github.com/david4lim/custom_movies",
"type": "git",
"reference": "master"
}
}
}
]
- Add the composer package:
composer require david4lim/custom_movies:dev-master
- Install the module using
drush
:
drush en custom_movies
All the CRUD action can be found in /admin/content/movie
.
The movies export is accessible from the path /movies?_format=json
, only json
format is enabled, so it can also be accessed using only/movies
and json
format will be used.
- The movie entity was generated using the drush command
drush gen entity:content
. - The release date validation was done by creating a new field constraint plugin, and adding it to the
release_date
field definition. - All javascript alterations were done in the library
custom_movies/movies.admin_form
.