Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By cofaure on
Hi,
I want to create a PHP script to create basic pages on Drupal 8. I need some advices, i don't know how to start, i just have my database connection. I don't know which data i have to create etc... Maybe i have to create a row in node...
Any idea ?
Comments
Basic sections:
Basic sections:
1. Setup error handling.
2. Initialize Drupal 8 before booting.
3. Boot the Drupal kernal.
4. Login.
5. Create a node entity with desired bundle.
Check the links below:
Check the links below:
Create a custom page
A "Hello World" Custom Page Module
Thank You,
Shashwat Purav
Thanks for the links
This is very useful for Drupal beginners.
Re
In fact, i'm just trying to update the drupal database to create a page. So i need to know which tables i have to update (node__body etc)
Best way to do it is, not by
Best way to do it is, not by updating databse tables but using Drupal's API. Please find below useful link to create nodes programatically in D8.
Programmatically create nodes
Thank You,
Shashwat Purav
Shashwat is correct. You
Shashwat is correct. You should never directly write to any tables that you have not created yourself. Always use the Drupal API for that.
Re
Ok guys i understand, i'll try with something like that :
Thank you
Re
Last question, i dont understand this line "use Drupal\node\Entity\Node;"
I have got a multisite drupal installation, which path i have to use ?
I don't know where i have to put the php code.
That's the namespace of Node.
That's the namespace of Node. It tells the system both where the file is (for autoloaders), and ensures that it can be used even if you have another class named Node somewhere else in your system (since they will be in a different namespace).
This is related to the code base, not the database, so you will use the same value regardless of which site you are using in your multisite.
Re
OK thanks !
Worked for me
Very nice post, thank you.