
Learn to create custom Drupal nine entities, add annotations, enable workflows and access controls, and build multi-step data entry forms with the field API and core media module for images.
See the guiding pdf per chapter for source code.
From the Q&A:
Offer Table is Missing After Install
I was able to install the offer module, but when I go to uninstall it, I'm getting the below error:
The website encountered an unexpected error. Please try again later. Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'default.offer' doesn't exist: SELECT "base_table"."vid" AS "vid", "base_table"."id" AS "id" FROM "offer" "base_table" GROUP BY base_table.vid, base_table.id LIMIT 1 OFFSET 0; Array ( ) in Drupal\Core\Entity\Query\Sql\Query->result() (line 271 of core/lib/Drupal/Core/Entity/Query/Sql/Query.php).
Also when I look at the database there is no table named 'offer' in it.
ANSWER
A very annoying issue this is. I think it actually means the custom entity was not installed correctly in the first place. Steps to get rid of the error:
- You need to uninstall the module BUT first move the Entity folder outside the module (f.e. to your desktop).
Steps:
- move the Entity folder
- uninstall the offer module
- replace your Entity folder in the offer module
- install the offer module again
- have a look if the database table 'offer' was created (if not: look in the Offer.php file for mistakes)
From the Q&A:
Question:
At 05:28, the OfferAccessControlHandler.php file checks for the "administer own offers" permission. I see that permission is also defined in the offers.permissions.yml
Does the offers.permissions.yml defines the "administer own offers" or is it using a naming convention "adminster own {entity_name}"?
Are we telling Drupal that we want to use this permission or are we creating a new permission?
Answer:
it is definitely the "offers.permissions.yml" that defines the "administer own offers".
It uses the key of the permission:
administer own offers: title: 'Create/edit/delete own offers'
You can name it like you want. It is not really convention. Drupal would typically split up the permissions:
create offer: 'Create an offer'
edit offer: 'Edit own offers'
...
But in reality, I find it handy to use "administer" and specify it like: "create/edit/delete own..."
Learn how to implement create, read, edit, and delete forms for a custom Drupal entity in Drupal 8 & 9, including entity forms, routing, access controls, and delete confirmation.
Create powerful listings for custom Drupal entities using views and Fuse integration; learn to link entities to views, configure access, build CRUD listings, and manage configuration.
Note: at /admin/structure/display-modes/view/add/offer add 'teaser' and 'full' view modes. From then, they are available in the manage display.
Enable the media module and media library, define an image media type, and upload an image to the offer entity while securing the library with a user-specific filter.
Add and configure fields for a custom Drupal entity via the UI, including a rich text description, offer type, price, and options, with text formats and configuration management.
Enable workflows and content moderation to extend custom entities with draft, published, and expired states, and define transitions like make expired for the offer entity.
Learn to build custom Drupal 8/9 entities with a dropbutton of dynamic operation links (publish, edit, delete) via a views plugin, using render areas and theme APIs.
Add a custom controller with route parameter upcasting to cast the offer entity for automatic validation, then publish by updating moderation state, logging revisions, and redirecting to the published URL.
Learn to optimize a drupal entity teaser by adding dynamic variables with tweak, rendering promo text and price based on bids and offer type, using pre-processing and view modes.
Attach a css library to the module to style the views overview page in Drupal 8 and 9 by registering the library in libraries file and using a pre-render hook.
Learn to build a user-friendly multi-step form for creating a custom offer entity in Drupal 8/9 by configuring four form modes, three data-entry steps, and routing.
Learn to extend a Drupal 8/9 entity form with custom actions, adding cancel, delete, and go back buttons for a multi-step form, with redirects and step-based notifications.
Learn to use Drupal's core form API to show or hide fields based on another field. Make the prize field appear when offer type equals minimum price.
My blog: https://stefvanlooveren.me
Twitter: https://twitter.com/stefvanlooveren
Bluesky: https://bsky.app/profile/stefvanlooveren.bsky.social
A big thank you!
[Please read the table of contents first! Also the prerequisites are important]
This is 2h 30min video course is chapter 3 of the "Learning Drupal 9 as a framework", the best-selling Drupal book on Leanpub.
Join me in an interesting journey of learning the Object-oriented architecture behind entities in Drupal. In this hands-on course, a part of an offer software where users are able to create offers will be created.
PDF with text and code available per chapter. Please read the table of contents carefully to know what to expect!
This is the ideal introduction for custom module development with Drupal.
We'll start by creating a custom entity from scratch. Custom-tailored access handling is one of the a-ha moments you will have in this course. Remember the difficulties with separating access between node types, right?
We'll make the entity fieldable, and add a media library where users can upload images.
Next, we'll head on towards creating a multi-step entity form. So much more user-friendly than the one-page node creation form you know. I promise you will uninstall the node module on some drupal websites sooner or later after taking this course.
Impress your coworkers with Drupal skills that are rather new but extremely powerful.
Stef Van Looveren has more than 10 years of expertise with Drupal. His message is: "It struck me that there are so few good learning paths for drupal. With this course, I try to fill the gap. I gave it my best and I hope you will enjoy it!"