Score:0

If i have to add a content in drupal through custom form which table in database should be used?

bd flag

I have created a custom Form through form api which only contains one form field of adding image to node and their will be a different form through which i am going to add body , title and tags in database . Now I am really confused that which table in database should i use to add the data so i can see the data in the content section on the user interface of the site( for admin ). I tried using some tables as node__field_image for adding the image but turns out it is not working. Any suggestions how can this be done.

sonfd avatar
in flag
Don't interact with the DB tables directly. Instead, load an entity, add the values to the correct fields on the entity, then save the entity.
Kevin avatar
in flag
Yes, don't use raw SQL, use the API.
Vighnesh Sadagopal avatar
bd flag
OK I will try it by using entity manager , but can someone tell me why can't we directly use database in this use-case.
leymannx avatar
ne flag
Look you don't know what tables to touch and therefore are asking this question. The API doesn't need to ask this question. It knows which tables to touch and which not. You have a CMS with numerous APIs to handle all CRUD operations in a standardised way. You don't want to be the poor future maintainer of your project who years later finds out that someone thought it was a clever idea bypassing the CMS and to store field data in the database on their own.
Kevin avatar
in flag
You would never write anything directly to the database that Entity API manages. It makes no sense at all and there are dozens of things that happen on save besides just the writes.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.