
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..."
Note: at /admin/structure/display-modes/view/add/offer add 'teaser' and 'full' view modes. From then, they are available in the manage display.
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!"