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
gabapentin 300mg capsule:…
gabapentin 300mg capsule: GabaRx Direct - gabapentin accion
http://levocarepharma.com/#…
http://levocarepharma.com/# purchase generic synthroid online
accutane discount pharmacy…
accutane discount pharmacy or accutane without ipledge accutane price per pill
https://maps.google.com.au/url?sa=t&url=https://dermatretdirect.com cheap generic roaccutane 40mg or http://asresin.cn/home.php?mod=space&uid=1314146 order isotretinoin capsules
order accutane overnight delivery accutane generic brands and п»їbuy accutane online cheap generic roaccutane 40mg
gabapentin stada 600 mg…
gabapentin stada 600 mg nebenwirkungen: buying gabapentin - gabapentin koira sivuvaikutus
https://dermatretdirect.shop…
https://dermatretdirect.shop/# buy accutane from canada
replacement drug for…
replacement drug for gabapentin or what is gabapentin 300 mg capsules is pregabalin same as gabapentin
https://maps.google.com.sg/url?sa=t&url=https://gabarxdirect.com restless leg syndrome gabapentin or https://cyl-sp.com/home.php?mod=space&uid=201555 can gabapentin cause speech problems
gabapentin vicodin high can i take gabapentin for sciatica or gabapentin for period pain can i get fluoxetine
buy authentic synthroid…
buy authentic synthroid tablets or synthroid 88 mcg best price buy synthroid with fast shipping
http://101.43.178.182/sell/email.asp?d=levocarepharma.com&on=tb synthroid 112 mcg online order or https://mantiseye.com/community/wnwmxagjye buy generic levothyroxine 100mcg
generic synthroid for sale buy authentic synthroid tablets or order generic synthroid 75mcg order synthroid overnight
https://zpacksupply.shop/#…
https://zpacksupply.shop/# buy zithromax 500mg online
zithromax 250 price and buy…
zithromax 250 price and buy zithromax online fast shipping buy zithromax 1000mg online
https://www.google.com.eg/url?q=https://zpacksupply.com how to get zithromax over the counteror http://lostfilmhd.com/user/wjvmvxnwwg/ zithromax cost canada
generic zithromax 500mg india zithromax 250 mg australiaand how to buy zithromax online can you buy zithromax online
buy accutane discreet…
buy accutane discreet shipping or buy generic isotretinoin no rx generic accutane 20mg buy
https://www.google.nu/url?q=https://dermatretdirect.com indian generic accutane online or https://www.0468wudi.com/home.php?mod=space&uid=324493 п»їbuy accutane online
accutane for sale online accutane generic brands or isotretinoin 30mg price cheap accutane online pharmacy
buy generic levothyroxine…
buy generic levothyroxine 100mcg Levo Care Pharma mail order levothyroxine
gabapentin and elevated…
gabapentin and elevated blood sugar gabapentin cerebellar ataxia can i take xanax and gabapentin
https://pulseguarddirect…
https://pulseguarddirect.shop/# Lopressor oral solution price
https://zpacksupply.shop/#…
https://zpacksupply.shop/# zithromax online
synthroid 88 mcg best price…
synthroid 88 mcg best price LevoCarePharma purchase generic synthroid online
https://pulseguarddirect.com…
https://pulseguarddirect.com/# metoprolol succinate
order isotretinoin capsules…
order isotretinoin capsules and cheap isotretinoin 10mg order accutane overnight delivery
https://www.google.fi/url?q=https://dermatretdirect.com order isotretinoin without prescription and http://www.1gmoli.com/home.php?mod=space&uid=1221988 where to buy accutane online safely
accutane without ipledge accutane without ipledge and isotretinoin 30mg price п»їbuy accutane online
where can i get zithromax or…
where can i get zithromax or zithromax 1000 mg pills zithromax 500 mg lowest price pharmacy online
https://www.bausch.pk/en/redirect/?url=https://zpacksupply.com zithromax capsules 250mgand http://nosugar.co.uk/profile.php?uid=272928 generic zithromax india
buy zithromax online zithromax tabletsand zithromax 500 mg lowest price pharmacy online where can i purchase zithromax online
zithromax 500 mg lowest…
zithromax 500 mg lowest price pharmacy online: Z-Pack Supply - zithromax online usa
generic isotretinoin tablets…
generic isotretinoin tablets: dermatretdirect - accutane generic brands
zithromax online no…
zithromax online no prescription ZPack Supply zithromax capsules
order accutane overnight…
order accutane overnight delivery: accutane generic brands - isotretinoin 30mg price
https://dermatretdirect.com/…
https://dermatretdirect.com/# п»їbuy accutane online
gabapentin lower extremity…
gabapentin lower extremity edema and can you mix gabapentin and suboxone gabapentin severe headaches
http://txtrek.net/go.php?go=http://gabarxdirect.com is expired gabapentin safe and http://la-maison-des-amis.com/user/gfiszzzaqw/ mylan gabapentin 100mg
fluoxetine no prescription gabapentin katze dosierung and cena leku gabapentin teva equine gabapentin dose
http://zpacksupply.com/#…
http://zpacksupply.com/# zithromax 500mg
zithromax 600 mg tablets and…
zithromax 600 mg tablets and order zithromax without prescription zithromax 250
http://images.google.bt/url?q=http://zpacksupply.com zithromax z-pakand https://kigalilife.co.rw/author/ciwlgpyylq/ zithromax tablets for sale
how to get zithromax over the counter buy zithromax online with mastercardand how much is zithromax 250 mg purchase zithromax online
gabapentin atenolol…
gabapentin atenolol interaction: gabapentin 100 - carbamazepine and gabapentin
http://dermatretdirect.com/#…
http://dermatretdirect.com/# cheap accutane online pharmacy
http://levocarepharma.com/#…
http://levocarepharma.com/# п»їbuy synthroid online
accutane without ipledge:…
accutane without ipledge: generic accutane 20mg buy - buy accutane from canada
http://dermatretdirect.com/#…
http://dermatretdirect.com/# indian generic accutane online
zithromax pill: Z-Pack…
zithromax pill: Z-Pack Supply - zithromax online no prescription
purchase levothyroxine…
purchase levothyroxine tablets online LevoCare Pharma order levothyroxine 175 mcg
zithromax 250mg: Z-Pack…
zithromax 250mg: Z-Pack Supply - where can i purchase zithromax online
https://gabarxdirect.com/#…
https://gabarxdirect.com/# gabapentin 300
https://gabarxdirect.shop/#…
https://gabarxdirect.shop/# can stopping gabapentin cause insomnia
buy medication from india:…
buy medication from india: online medicine order - online medicine purchase in india
canada rx pharmacy:…
canada rx pharmacy: CanPointe - best canadian online pharmacy
https://fronteracaredirect…
https://fronteracaredirect.com/# cheapest mexican prescription drugs
cheapest mexican pharmacy…
cheapest mexican pharmacy online: mail order mexican pharmacy - buying from online mexican pharmacy
mexican mail order pharmacy:…
mexican mail order pharmacy: FronteraCareDirect - mexico pharmacy mail order online
https://canpointerx.shop/#…
https://canpointerx.shop/# cipa canada online pharmacy
I've been using Tenobet…
I've been using Tenobet since about March, and I figure I have enough history to actually comment. Came across it off someone on another board who wanted somewhere with proper game coverage without all the affordability checks you get now on the UK licensed sites. Should flag early: it's not UK Gambling Commission licensed and it isn't on GamStop, and that will matter to some of you a lot.
Game selection's genuinely big — about 3,000+ slots last I looked, and the usual heavy hitters all turn up: Pragmatic Play, NetEnt, Play n GO, BTG, Betsoft, Microgaming. Personally I stick to Sweet Bonanza plus Book of Dead, both load quick on mobile browser. Live dealer's Evolution, which means what you're getting — proper croupiers, Crazy Time and Lightning Roulette if that's your thing. They do sports as well, which I've used a handful of times for the football, nothing special.
The welcome thing it's a 100% match to ?125 and 100 spins thrown in, you'll want the promo code JOIN002 at deposit — I nearly forgot it the first time. Do read the terms before depositing, the requirement is not the loosest to be honest. Don't expect free credit without depositing as far as I can tell. For the what's running currently, have a look over on [url=https://solvecovid19.net]tenobet casino[/url] rather than taking my word for it. Minimum deposit is a tenner, registration took under five minutes.
Cashouts have been the better half for me. Visa/Mastercard go through, e-wallets like Skrill and Neteller are supported, and crypto if you prefer. E-wallet withdrawals have come through in under 24 hours; Visa took a bit longer. What did wind me up was KYC — took a day and a half to approve my ID, so the first cashout just sat there the whole time. Not dodgy, but slow.
Few more things: no native app, so it's the mobile site. Works fine on my iPhone but an app would be nicer. The login sometimes gets fiddly in the evenings. Live chat at Tenobet is English-speaking and reasonably quick, but the opening messages feel a bit scripted. Ask a specific question and they sort it.
e pharmacy in india:…
e pharmacy in india: pharmacy india online - online medicine delivery service
medicine from india: buy…
medicine from india: buy medicines from india online - indian online pharmacies list
https://zenithindusrx.com/#…
https://zenithindusrx.com/# buy drugs from india
canadian pharmacy online…
canadian pharmacy online canadian pharmacy ratings legit canadian online pharmacy
https://zenithindusrx.com/#…
https://zenithindusrx.com/# online india pharmacy
canada online pharmacy:…
canada online pharmacy: CanPointe - canada drug pharmacy
https://fronteracaredirect…
https://fronteracaredirect.com/# mexican online pharmacies
Pagination
Add new comment