Content types are the backbone of content management in Drupal. In Drupal 10, you can create custom content types to structure and organize your content. This blog post will guide you through the process of creating content types programmatically in Drupal 10, allowing you to tailor your website's content structure to your specific needs.
Prerequisites
Before creating custom content types programmatically in Drupal 10, you should have the following:
- A working Drupal 10 or 9 website.
- Basic knowledge of Drupal site building and module development.
- Familiarity with PHP and Drupal's module structure.
Step 1: Define the Custom Module
To create a custom content type programmatically, you need to place the code in a custom module. If you don't already have a custom module, you can create one by following these steps:
- In your Drupal installation, navigate to the sites/all/modules directory (or your preferred module location).
- Create a new directory for your custom module. Give it a unique and descriptive name, such as my_custom_content_type.
- Inside your module directory, create a my_custom_content_type.info.yml file with the following content:
name: 'My Custom Content Type Module'
type: module
description: 'Defines custom content types programmatically.'
core_version_requirement: ^9 || ^10
package: Custom
dependencies:
- nodeThis YAML file defines the basic information about your custom module.
Step 2: Create a Custom Content Type
To create a custom content type, you'll need to implement the hook_entity_type_build and hook_node_type_insert hooks within your custom module.
- Create a file named my_custom_content_type.module in your module directory.
- In this file, implement the hook_entity_type_build hook to define your custom content type. Here's an example:
/**
* Implements hook_entity_type_build().
*/
function my_custom_content_type_entity_type_build(array &$entity_types) {
$entity_types['node']->setClass('Drupal\my_custom_content_type\NodeTypeCustom');
}This code defines a custom class, NodeTypeCustom, to handle the configuration of your custom content type.
- Create the NodeTypeCustom class in a file named NodeTypeCustom.php and place it in your module's directory:
namespace Drupal\my_custom_content_type;
use Drupal\node\NodeTypeBase;
/**
* Provides a custom content type.
*/
class NodeTypeCustom extends NodeTypeBase {
/**
* {@inheritdoc}
*/
public function postSave(NodeTypeInterface $node_type) {
parent::postSave($node_type);
// Define the custom content type settings.
$config = \Drupal::configFactory()->getEditable('node.type.' . $node_type->id());
$config->set('name', 'Custom Content Type');
$config->set('description', 'A custom content type created programmatically.');
$config->set('new_revision', TRUE);
$config->save();
}
}n the NodeTypeCustom class, we extend the NodeTypeBase class to define the custom content type settings, such as the name and description.
Step 3: Enable and Verify Your Custom Content Type
- In your Drupal admin interface, navigate to Extend (admin/modules) and enable your custom module, "My Custom Content Type Module."
- After enabling the module, go to Structure > Content types (admin/structure/types) to see your custom content type listed as "Custom Content Type."
Conclusion
Creating custom content types programmatically in Drupal 10 allows you to define content structures that fit your specific project requirements. By following the steps outlined in this blog post, you can easily create and configure custom content types within your Drupal website, providing a flexible and tailored content management experience.
In Drupal 9 and 10, custom modules should be stored in the "modules/custom" directory rather than "sites/all/modules." Drupal's module directory structure has evolved, and the recommended practice is to place custom modules in the "modules/custom" directory to follow the modern Drupal standards.
So, if you're creating a custom module in Drupal 9 or 10, you should place it in the following directory:
/sites/all/modules/custom/By following this structure, your custom modules will be more organized and adhere to Drupal's best practices, making it easier to manage and maintain your site's codebase.
Comment
india pharmacy online:…
india pharmacy online: ZenithIndus Rx - e pharmacy in india
meds from mexico:…
meds from mexico: FronteraCareDirect - online pharmacy in mexico
https://fronteracaredirect…
https://fronteracaredirect.com/# mexican pharmacy online ordering
canadian pharmacy checker:…
canadian pharmacy checker: CanPointeRx - canadian pharmacy official site
pharmacies in mexico: best…
pharmacies in mexico: best mexican online pharmacy - mexican online pharmacy shipping
real canadian pharmacy:…
real canadian pharmacy: CanPointe Rx - best canadian online pharmacy
http://zenithindusrx.com/#…
http://zenithindusrx.com/# online indian pharmacy
mexico pharmacy ship to us:…
mexico pharmacy ship to us: FronteraCareDirect - order antibiotics from mexico
best pharmacy in mexico:…
best pharmacy in mexico: FronteraCareDirect - mexican pharmacies that ship to the united states
online canadian pharmacy and…
online canadian pharmacy and canadian pharmacies that deliver to the us online pharmacy canada
https://images.google.com.co/url?q=https://canpointerx.shop vipps approved canadian online pharmacy and https://exhibitioncourthotel4.co.uk/user-2/vgercrpwge/?um_action=edit real canadian pharmacy
safe canadian pharmacy canadian pharmacy checker and online pharmacy canada real canadian pharmacy
canadian pharmacy reviews:…
canadian pharmacy reviews: CanPointe - trusted canadian pharmacy
canadian pharmacy online and…
canadian pharmacy online and canadian pharmacy compare canadian pharmacy comparison
https://eng.b2club.ru/buyticket/concertru/?url=https://canpointerx.com/ canadian pharmacy onlineand http://www.orangepi.org/orangepibbsen/home.php?mod=space&uid=7151265 canadian online pharmacy
canadian pharmacies canadian pharmacy kingand canadian pharmacy reviews legit canadian online pharmacy
https://zenithindusrx.shop/#…
https://zenithindusrx.shop/# generic medicines in india
best online pharmacies from…
best online pharmacies from india and order medicine without prescription best online indian pharmacy
http://www.cliptags.net/Rd?u=http://zenithindusrx.shop/ indian pharmacy legit or http://jonnywalker.net/user/lngfednceh/ indian pharmacy website
generic medicine best online pharmacies from india or online medicine order online drugs order
canadian pharmacies that…
canadian pharmacies that deliver to the us: CanPointeRx - trusted canadian pharmacy
legit canadian online…
legit canadian online pharmacy: canadian pharmacy ratings - canadian online pharmacy
Поздравляю, ваша мысль…
Поздравляю, ваша мысль блестяща
Looking for fun and excitement? Discover the Best Online Casinos, [url=https://www.finovativeworld.com/online-pokies-amp-live-tables-2026/]htt…] that offer thrilling games, lucrative bonuses, and a secure environment. Playing at reputable sites ensures a fantastic experience while winning big. Join now and start your adventure!
best canadian online…
best canadian online pharmacy: CanPointeRx - reliable canadian pharmacy
canadian pharmacy ratings…
canadian pharmacy ratings and reliable canadian pharmacy canadian pharmacy compare
https://www.google.dj/url?q=http://canpointerx.shop canadian mail order pharmacy or https://armandohart.com/user/vjrcrpqzbg/?um_action=edit canadian pharmacy 365
canada pharmacy world online canadian pharmacy or best canadian pharmacy real canadian pharmacy
canadian pharmacy king:…
canadian pharmacy king: CanPointeRx - legit canadian pharmacy
best indian pharmacy website…
best indian pharmacy website or online medicine shopping india online pharmacy store
http://obchody.forwardo.com/cz/go_preload.php?url=http://zenithindusrx… medicine purchase online or https://cyl-sp.com/home.php?mod=space&uid=207814 rx pharmacy india
buy online medicine indian online pharmacy USA and medicine purchase online indian online pharmacy
https://zenithindusrx.shop/#…
https://zenithindusrx.shop/# india pharmacies
reputable canadian pharmacy:…
reputable canadian pharmacy: CanPointeRx - canada pharmacy online
certified canadian…
certified canadian international pharmacy: CanPointeRx - canadian pharmacy drugs online
https://canpointerx.shop/#…
https://canpointerx.shop/# best rated canadian pharmacy
canadian online pharmacy:…
canadian online pharmacy: CanPointe Rx - pharmacies in canada that ship to the us
legitimate canadian online…
legitimate canadian online pharmacy: CanPointe - canadian drug pharmacy
online canadian pharmacy or…
online canadian pharmacy or reliable canadian pharmacy canadian pharmacy official site
http://toolbarqueries.google.sm/url?q=https://canpointerx.com my canadian pharmacyand https://cyl-sp.com/home.php?mod=space&uid=207308 canadian pharmacy price checker
canadian pharmacies canadian pharmacies that deliver to the usor canadian drugstore online canadian pharmacy official website
online pharmacy india or…
online pharmacy india or indian pharmacy shipping to usa cheap prescription drugs india
http://wiki.wlug.org.nz/~matt/m.php?a%5B%5D=%3Ca%20href%3Dhttp%3A%2F%2F… best indian pharmacy website or https://armandohart.com/user/cblmxeyuyc/?um_action=edit generic medicine
best site for medicine online pharmacy india or buy online medicine buy medicine online
https://zenithindusrx.com/#…
https://zenithindusrx.com/# meds from india
best site for online…
best site for online medicine: ZenithIndus Rx - generic medicines in india
canadian pharmacy legit…
canadian pharmacy legit CanPointe reliable canadian pharmacy
So I've been using Craybet…
So I've been using Craybet for about two months now and thought I'd throw out my experience since I haven't seen many posts about them around here. Signed up randomly one night and registration literally took a couple minutes. Minimum deposit is ten bucks which is pretty standard. I grabbed a sign-up bonus — 100 percent match to $500 and fifty free spins on Sweet Bonanza. Wagering was 35x which is kinda average but not the worst I've seen.
The game library is honestly pretty solid. You'll find games from Pragmatic Play, Betsoft, plus Play'n GO — so like Gates of Olympus, Starburst, all the popular ones. I'd guess maybe 2000 games including table games. Live dealer stuff uses Evolution which is legit — played some blackjack and Crazy Time with real dealers and zero lag issues.
Tbh the thing that annoyed me a little was withdrawal times. Withdrew via Visa and it took about 48 hours for my first withdrawal. After that though things sped up. They accept credit cards, Skrill, Neteller, and BTC which covers pretty much everything you'd want. You can look at what they've got going on on CrayBet to see for yourself.
Mobile experience on Craybet on mobile was surprisingly good. There's no app to download though the web app loads fast and slots and live games work no problem. Played some slots on my commute and had zero problems.
Customer service on Craybet is alright — live chat that actually connects within a few minutes when I've used it. I contacted them about my verification docs and it was resolved same day. I think they're Curacao-based from what I can tell and that's what most platforms like this. It's not flawless — the bonus wagering could be lower — but for what it is I'm still using it.
Learn the principles how to…
Learn the principles how to deposit on binary options with opay. Analyze trading strategies, choose trading platforms, and discuss the specifics of trading and the risks associated with it.
Закажите профессиональный…
Закажите профессиональный ремонт ванной комнаты с учетом планировки и ваших пожеланий. Подберите отделочные материалы, сантехнику и дизайн, чтобы оформить удобное, функциональное и современное пространство.
canadian pharmacies that…
canadian pharmacies that ship to usa or top canadian pharmacy canadian pharmacies shipping to usa
https://cse.google.st/url?sa=i&url=https://canpointerx.com canada drug pharmacyand http://jonnywalker.net/user/bunwcdnptg/ canadian pharmacy official website
cipa canada online pharmacy reputable canadian pharmacyand best canadian pharmacy canadian pharmacy checker
Pagination
Add new comment