By cofaure on
Hello,
All is in the title, I'm starting on drupal 8, and i have to create a module who is displaying data from a database (mysql), I don't know how to make a good structure, what functions i need etc.
I already did a module "Hello World" to undertsand D8.
Need help
Co.
Comments
You may benefit from looking
You may benefit from looking at the Examples and reading the code:
https://www.drupal.org/project/examples
Be sure to get the Drupal 8 set.
The Node Type example might be a good starting point, though I think most of them have some sort of database interaction.
============================
Resonetrics: Better Tools for Building Brands
http://resonetrics.com
http://technologyformarketers.com
http://kittenassociates.org
http://www.linkedin.com/in/sammooreatresonetrics
Try Content Entity Example
If you are happy with the normal database Drupal node table structures you can create a new content type (using the UI or programmatically) and then add nodes of this content type from within your module code.
Drupal Nodes are one type of Drupal Entity which store content. You can also create new "Content Entity" types and with these you can control the UI and the backend database storage. The Content Entity Example in the examples module shows you how to do this and by default writes to a single dedicated table in the Drupal database.
More background on Drupal 8 entities here :
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!entity.api.php/group/entity_api/8
https://drupalwatchdog.com/blog/2015/3/entity-storage-drupal-8-way
If you use this approach you also get to reuse other Drupal code for free, eg your new content entity will get default edit forms, a REST api, and data table UI display. This approach is much better than writing SQL to access a database and then having to write all the layers of controller and UI code.
Re
Hello, thank you both but I don't understand the drupal's module sctructure. I have got my module, who's just displaying "hello world". What I have to add to this module ? I have to create a new entity content and in this entity i make an access to my database to show some datas when i create a content page with this entity content ? Something like this ?
Sorry i'm just begining on Drupal 8...
Co.
Did you work your way through
Did you work your way through all of the Examples in the Examples module?
Contact me to contract me for D7 -> D10/11 migrations.
Re
I'm actually working on the node type example, not easy to understand all of the code !
I'm trying to :)
Before starting with Drupal 8
Before starting with Drupal 8, have a look at Drupal 8 tutorials at Free Drupal 8 Tutorials
Re
Thank you i'll check it !