<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ankit Kumar on Medium]]></title>
        <description><![CDATA[Stories by Ankit Kumar on Medium]]></description>
        <link>https://medium.com/@ankit-kumar-fullstackdeveloper?source=rss-0ed101a706ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_dPFWj1AM4gDIBUmkhzJ-w.png</url>
            <title>Stories by Ankit Kumar on Medium</title>
            <link>https://medium.com/@ankit-kumar-fullstackdeveloper?source=rss-0ed101a706ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:00:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ankit-kumar-fullstackdeveloper/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What is Abstraction in PHP? Explained with Simple Examples]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/what-is-abstraction-in-php-explained-with-simple-examples-1990997d5aca?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/1990997d5aca</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[abstraction-in-php]]></category>
            <category><![CDATA[oop-in-php]]></category>
            <category><![CDATA[learn-php]]></category>
            <category><![CDATA[php-abstraction]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Tue, 17 Feb 2026 02:49:13 GMT</pubDate>
            <atom:updated>2026-02-17T02:49:13.686Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will learn about abstraction in PHP. Abstraction is the concept of hiding internal implementation details while exposing only the essential features of an object.</p><h4>Real-Life Analogy</h4><p>Think about a <strong>car</strong>:</p><ul><li>You press the accelerator → the car moves.</li><li>You press the brake → the car stops.</li></ul><p>You don’t know:</p><ul><li>How fuel injectors work</li><li>How combustion happens</li><li>How the braking system works internally</li></ul><p>You only interact with a <strong>simple interface</strong>.<br>👉 That’s abstraction.</p><h4>Why Abstraction is Important</h4><p>Abstraction helps to:</p><ul><li>Reduce complexity</li><li>Improve code readability</li><li>Protect internal logic</li><li>Make systems easier to maintain</li><li>Allow flexibility in implementation</li></ul><h4>How Abstraction Works in PHP</h4><p>In PHP, abstraction is achieved using:</p><ol><li><strong>Abstract Classes</strong></li><li><strong>Interfaces</strong></li></ol><h4>Abstract Class</h4><p>An abstract class:</p><ul><li>Cannot be instantiated directly</li><li>Can contain both abstract and normal methods</li><li>Forces child classes to implement abstract methods</li></ul><h3>Example:</h3><pre>abstract class Payment {<br>    abstract public function process($amount);<br><br>    public function paymentSuccess() {<br>       echo &quot;Payment successful!&quot;;<br>    }<br>  }<br><br>class CreditCardPayment extends Payment {<br>    public function process($amount) {<br>        echo &quot;Processing credit card payment of $amount&quot;;<br>    }<br>}</pre><p>Here:</p><ul><li><strong>Payment</strong> defines <strong>what must be done</strong></li><li><strong>CreditCardPayment</strong> defines <strong>how it is done</strong></li></ul><h3>Interface</h3><p>An interface:</p><ul><li>Contains only method declarations</li><li>Defines a contract</li><li>A class must implement all methods</li></ul><pre>interface Logger {<br>    public function log($message);<br>}<br><br>class FileLogger implements Logger {<br>    public function log($message) {<br>        echo &quot;Logging to file: $message&quot;;<br>    }<br>}</pre><p>The interface says:<br>Any Logger must have a log() method.</p><h4>Abstraction vs Encapsulation</h4><ul><li><strong>Encapsulation</strong> → Hides data using access modifiers</li><li><strong>Abstraction</strong> → Hides implementation logic using abstract classes/interfaces</li></ul><p>Thanks for reading this article. I hope you now have a proper understanding of abstraction in PHP and how it works in object-oriented programming.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1990997d5aca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP Namespaces Explained: What They Are and Why You Need Them]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/php-namespaces-explained-what-they-are-and-why-you-need-them-295a8a2b6d53?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/295a8a2b6d53</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[php-tips]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Fri, 06 Feb 2026 17:14:26 GMT</pubDate>
            <atom:updated>2026-02-06T17:14:26.803Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will learn about <strong>Namespaces</strong>. Namespaces solve a very common and important problem in PHP. When you build a real project, you don’t write everything in a single file. As your PHP project grows, you start using many classes, functions, and constants across multiple files and libraries. Sometimes, different files or third-party libraries use the same names, and this is where PHP gets confused. Namespaces help prevent these naming conflicts and keep your code organized.</p><p><strong>The Problem (Without Namespace)</strong></p><p><strong>File 1: </strong><strong>User.php</strong></p><pre>&lt;?php<br>class User {<br>    public function getName() {<br>        return &quot;Admin User&quot;;<br>    }<br>}</pre><p><strong>File 2: </strong><strong>Customer.php</strong></p><pre>&lt;?php<br>class User {<br>    public function getName() {<br>        return &quot;Customer User&quot;;<br>    }<br>}</pre><p><strong>File 3: </strong><strong>index.php</strong></p><pre>&lt;?php<br>include &quot;User.php&quot;;<br>include &quot;Customer.php&quot;;<br><br>$user = new User();<br>echo $user-&gt;getName();</pre><p><strong>Error:</strong></p><pre>Cannot declare class User, because the name is already in use</pre><p>Why?<br> Because PHP <strong>does not know which </strong><strong>User class you mean</strong>.</p><h4>What Is a Namespace?</h4><p>A <strong>namespace</strong> is like a <strong>folder or label</strong> for your classes.</p><p>Think of it like this:</p><ul><li>Admin\User</li><li>Customer\User</li></ul><p>Same class name, but <strong>different places</strong>.</p><h3>Simple Definition</h3><p>A namespace in PHP is used to <strong>group related classes, functions, and constants</strong> and <strong>avoid name conflicts</strong>.</p><h4>Using Namespace (Solution)</h4><p>File 1: Admin/User.php</p><pre>&lt;?php<br>namespace Admin;<br><br>class User {<br>    public function getName() {<br>        return &quot;Admin User&quot;;<br>    }<br>}</pre><p><strong>File 2: </strong><strong>Customer/User.php</strong></p><pre>&lt;?php<br>namespace Customer;<br><br>class User {<br>    public function getName() {<br>        return &quot;Customer User&quot;;<br>    }<br>}</pre><p><strong>File 3: </strong><strong>index.php</strong></p><pre>&lt;?php<br>include &quot;Admin/User.php&quot;;<br>include &quot;Customer/User.php&quot;;<br><br>$adminUser = new Admin\User();<br>$customerUser = new Customer\User();<br>echo $adminUser-&gt;getName();    // Admin User<br>echo &quot;&lt;br&gt;&quot;;<br>echo $customerUser-&gt;getName(); // Customer User</pre><p>No error<br> Clean code<br> Clear meaning</p><p><strong>Using</strong> use <strong>Keyword (Cleaner Way)</strong></p><p>Instead of writing full names every time:</p><pre>new Admin\User();</pre><p>You can use use 👇</p><pre>&lt;?php<br><br>use Admin\User as AdminUser;<br>use Customer\User as CustomerUser;<br><br>$admin = new AdminUser();<br>$customer = new CustomerUser();<br>echo $admin-&gt;getName();<br>echo $customer-&gt;getName();</pre><p>This makes your code <strong>shorter and more readable</strong>.</p><p><strong>Why Do We Need Namespace?</strong></p><p>Here are the <strong>main reasons</strong> 👇</p><p><strong>1. Avoid Name Conflicts</strong></p><p>Two classes can have the same name without causing errors.</p><p><strong>2. Better Code Organization</strong></p><p>Code becomes structured like folders:</p><pre>App/<br> ├── Controllers/<br> ├── Models/<br> └── Services/</pre><p><strong>3. Easier to Use Libraries</strong></p><p>Modern PHP frameworks and libraries <strong>heavily use namespaces</strong>.</p><p>Example:</p><pre>Laravel\Http\Request<br>Symfony\Component\HttpFoundation\Request</pre><p>Same class name Request, no conflict.</p><p><strong>4. Professional &amp; Scalable Code</strong></p><p>Namespaces are a <strong>best practice</strong> for real-world applications.</p><p><strong>Namespace in Real Project Example</strong></p><pre>namespace App\Controllers;<br><br>class UserController {<br>    public function index() {<br>        echo &quot;User Controller&quot;;<br>    }<br>}</pre><p>Usage:</p><pre>$userController = new App\Controllers\UserController();<br>$userController-&gt;index();</pre><p><strong>When Should You Use Namespace?</strong></p><p>Use namespaces when:</p><ul><li>Your project has <strong>multiple files</strong></li><li>You are building <strong>classes</strong></li><li>You use <strong>Composer or frameworks</strong></li><li>You want <strong>clean and maintainable code</strong></li></ul><p>Thanks for reading this article. I hope you now understand what a namespace does.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=295a8a2b6d53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Is Dependency Injection (DI) and Why Do We Need It?]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/what-is-dependency-injection-di-and-why-do-we-need-it-0c1f3203d0c7?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c1f3203d0c7</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[coding-principle]]></category>
            <category><![CDATA[programming-concepts]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 18:09:23 GMT</pubDate>
            <atom:updated>2026-02-04T18:09:23.702Z</atom:updated>
            <content:encoded><![CDATA[<p>If you work as a software developer, you must have heard about <strong>Dependency Injection (DI)</strong>. Many people associate it with a specific CMS or framework, but that’s not correct. Dependency Injection is <strong>not tied to any CMS or framework</strong> — it is a <strong>core programming concept</strong> that can be applied in any language or architecture.</p><p><strong>The Problem: Code Without Dependency Injection</strong></p><p>Imagine a simple user registration system that sends an email.</p><p><strong>Without DI (Tightly Coupled Code)</strong></p><p>Without Dependency Injection</p><pre>class EmailService<br>{<br>    public function send($message)<br>    {<br>        echo &quot;Sending email: &quot; . $message;<br>    }<br>}<br><br>class UserService<br>{<br>    private $emailService;<br>    public function __construct()<br>    {<br>        $this-&gt;emailService = new EmailService();<br>    }<br>    public function registerUser()<br>    {<br>        $this-&gt;emailService-&gt;send(&quot;Welcome user!&quot;);<br>    }<br>}</pre><p><strong>What’s wrong here?</strong></p><ul><li>UserService <strong>creates</strong> EmailService</li><li>You cannot replace EmailService easily</li><li>Testing becomes difficult</li><li>Code is tightly coupled</li></ul><p>If tomorrow you want to send SMS instead of Email, you must modify UserService</p><p><strong>The Solution: Dependency Injection</strong></p><p>Instead of creating dependencies inside the class, we <strong>inject them</strong>.</p><p><strong>With Dependency Injection</strong></p><pre>class EmailService<br>{<br>    public function send($message)<br>    {<br>        echo &quot;Sending email: &quot; . $message;<br>    }<br>}<br><br><br>class UserService<br>{<br>    private $emailService;<br>    public function __construct(EmailService $emailService)<br>    {<br>        $this-&gt;emailService = $emailService;<br>    }<br>    public function registerUser()<br>    {<br>        $this-&gt;emailService-&gt;send(&quot;Welcome user!&quot;);<br>    }<br>}</pre><p><strong>Why this is better</strong></p><ul><li>UserService doesn’t know how EmailService is created</li><li>Dependency can be replaced</li><li>Code is cleaner and testable</li></ul><p><strong>When Should You Use DI?</strong></p><p>Use Dependency Injection when:</p><ul><li>Your application has multiple services</li><li>You want testable code</li><li>Your project will grow</li><li>You want clean architecture</li></ul><p>Avoid it for:</p><ul><li>Small scripts</li><li>One-file PHP programs</li><li>Quick experiments</li></ul><p>Thank you for reading this article. I hope it helped you gain a clear understanding of DI.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c1f3203d0c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Types of Classes in PHP OOP Explained with Examples]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/types-of-classes-in-php-oop-explained-with-examples-939cdeca6f1a?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/939cdeca6f1a</guid>
            <category><![CDATA[php-oop]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 17:42:02 GMT</pubDate>
            <atom:updated>2026-02-04T17:42:02.694Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will learn about the types of classes in PHP. Many times, when we work as software developers, we use object-oriented programming, and classes are a core concept of OOP. In this tutorial, we will see what classes are and how to use them.</p><p><strong>1. Simple (Concrete / Normal) Class</strong></p><p>A regular class is a class from which we can create an object.</p><pre>class User {<br>    public function login() {<br>        echo &quot;Login success&quot;;<br>    }<br>}<br><br>$user = new User();</pre><p>Can have properties &amp; methods<br>Object can be created</p><p><strong>2. Abstract Class</strong></p><p>A class declared with abstract.<br>You <strong>cannot create an object</strong> of an abstract class.</p><pre>abstract class Shape {<br>    abstract public function area();<br>}</pre><p>Can have <strong>abstract + normal methods</strong><br>Used when you want to <strong>force child classes</strong> to implement methods<br>Cannot create object</p><p><strong>3. Final Class</strong></p><p>A class declared with final.<br>It cannot be inherited.</p><pre>final class Security {<br>    public function encrypt() {<br>        echo &quot;Encrypted&quot;;<br>    }<br>}</pre><p>Object can be created<br>Cannot be extended (no child class)</p><p><strong>4. Interface</strong></p><p>A blueprint of a class.<br>All methods are <strong>abstract by default</strong>.</p><pre>interface Payment {<br>    public function pay();<br>}<br><br>class UPI implements Payment {<br>    public function pay() {<br>        echo &quot;Payment done&quot;;<br>    }<br>}</pre><p>Supports <strong>multiple inheritance</strong><br>Only method declarations (no body)<br>Cannot create object</p><p>Thanks for reading! I hope this article helped you understand the different types of classes in PHP OOP.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=939cdeca6f1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Polymorphism in PHP?]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/what-is-polymorphism-in-php-d5e0bb354cd7?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5e0bb354cd7</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[polymorphism]]></category>
            <category><![CDATA[programming-concepts]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Sun, 01 Feb 2026 16:57:24 GMT</pubDate>
            <atom:updated>2026-02-01T16:57:24.712Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will learn about polymorphism, one of the core concepts of Object-Oriented Programming (OOP). As a software developer, when I was learning polymorphism, it gave me a clear idea of how we can write reusable and flexible code. Polymorphism allows different classes to use the same method name while implementing it in their own way. This helps in reducing code duplication and improving maintainability. In PHP, polymorphism makes applications easier to extend and manage as the project grows.</p><h4>Why Polymorphism is Needed</h4><p>Without polymorphism:</p><ul><li>Code becomes tightly coupled</li><li>Multiple if/else or switch conditions are required</li><li>Code is harder to extend and maintain</li></ul><p>With polymorphism:</p><ul><li>Code is clean and flexible</li><li>New functionality can be added without changing existing code</li><li>Follows <strong>Open/Closed Principle</strong></li></ul><h4>Example Using Interface (Recommended Approach)</h4><p>Step 1: Create an Interface</p><pre>interface NotificationInterface {<br>    public function send(string $message);<br>}</pre><p>Step 2: Implement Interface in Different Classes</p><pre>class EmailNotification implements NotificationInterface {<br>    public function send(string $message) {<br>        echo &quot;Sending Email: &quot; . $message;<br>    }<br>}<br><br>class SmsNotification implements NotificationInterface {<br>    public function send(string $message) {<br>        echo &quot;Sending SMS: &quot; . $message;<br>    }<br>}<br><br>class PushNotification implements NotificationInterface {<br>    public function send(string $message) {<br>        echo &quot;Sending Push Notification: &quot; . $message;<br>    }<br>}</pre><p>Step 3: Use Polymorphism</p><pre>function notifyUser(NotificationInterface $notification) {<br>    $notification-&gt;send(&quot;Your order has been placed.&quot;);<br>}<br><br>notifyUser(new EmailNotification());<br>notifyUser(new SmsNotification());<br>notifyUser(new PushNotification());</pre><p>How This Demonstrates Polymorphism</p><ul><li>Same method name: send()</li><li>Same function call: notifyUser()</li><li>Different behavior based on object type</li><li>No if/else conditions required</li></ul><p>Thanks for reading this article. I hope you now have a clear understanding of what polymorphism is in PHP.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5e0bb354cd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Encapsulation in PHP?]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/what-is-encapsulation-in-php-oop-ef1dfedd126b?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef1dfedd126b</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming-basic]]></category>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[encapsulation]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Mon, 26 Jan 2026 16:39:49 GMT</pubDate>
            <atom:updated>2026-02-04T17:26:54.011Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will learn what encapsulation is in PHP. As a software developer, it’s an important concept to understand because it is frequently asked in interviews. Let’s explore encapsulation with simple examples.</p><p><strong>What is Encapsulation?</strong></p><p>Encapsulation means <strong>wrapping data (variables) and behavior (methods) together inside a class</strong> and <strong>controlling how that data is accessed</strong>.</p><p>In PHP, encapsulation is achieved using <strong>access modifiers</strong>:</p><ul><li>public</li><li>protected</li><li>private</li></ul><p>The main idea is:<br>❝ Don’t allow direct access to internal data — access it through methods ❞</p><p><strong>Simple Example (Without Encapsulation ❌)</strong></p><pre>class User {<br>  public $name;<br>}<br><br>$user = new User();<br>$user-&gt;name = &quot;Ankit&quot;;</pre><p>👉 Anyone can change $name directly — <strong>not safe</strong>.</p><p><strong>Encapsulation in PHP (Correct Way ✅)</strong></p><pre>class User {<br>  private $name;<br><br>  public function setName($name) {<br>    $this-&gt;name = $name;<br>  }<br><br>  public function getName() {<br>    return $this-&gt;name;<br>  }<br>}<br><br>$user = new User();<br>$user-&gt;setName(&quot;Ankit&quot;);<br>echo $user-&gt;getName();</pre><p>✔ $name is <strong>private</strong><br>✔ Access is controlled using <strong>getter &amp; setter methods</strong></p><p><strong>Real-World Example</strong></p><p>Think of <strong>ATM</strong> 🏧</p><ul><li>You <strong>cannot directly access</strong> money inside</li><li>You use <strong>methods</strong> like withdraw() or checkBalance()</li></ul><p>That’s encapsulation!</p><p>That’s all thank you so much for reading this article. I hope you now have a clear understanding of what encapsulation is in PHP.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef1dfedd126b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drupal Event Subscriber: What It Is & How to Create Using Drush]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/drupal-event-subscriber-what-it-is-how-to-create-using-drush-082319bb8aec?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/082319bb8aec</guid>
            <category><![CDATA[drush]]></category>
            <category><![CDATA[drupal-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[event-subscriber]]></category>
            <category><![CDATA[drupal]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Sun, 25 Jan 2026 06:19:39 GMT</pubDate>
            <atom:updated>2026-01-26T16:43:53.950Z</atom:updated>
            <content:encoded><![CDATA[<p>An <strong>Event Subscriber</strong> in Drupal is a way to run your own code when something happens in the system. <br>Drupal fires events for actions like page requests, user login, or saving data. An Event Subscriber <strong>listens</strong> to these events and reacts when they occur.<br> It is written as a PHP class and follows an object-oriented approach.<br> This helps keep code clean, reusable, and separate from core logic.</p><h4><strong>What is Drush?</strong></h4><p><strong>Drush</strong> (Drupal Shell) is a command-line tool used to manage Drupal websites quickly and efficiently.<br> It allows developers to create modules, generate code, clear cache, run updates, and perform many tasks without using the UI.<br> Drush helps save time by automating repetitive development work.<br> It is widely used in modern Drupal development.</p><h4><strong>Step 1: Generate a Custom Module</strong></h4><p>If you don’t already have a custom module, you can create one by running the following command:</p><p><strong>drush generate module</strong></p><p>Follow the prompts and enter your module name, description, and package.</p><h4><strong>Step 2: Generate Event Subscriber</strong></h4><p>After creating the module, generate an event subscriber:</p><p><strong>drush generate event-subscriber</strong></p><ul><li><strong>Welcome to event-subscriber generator!</strong> — Confirms the Event Subscriber generator has started.</li><li><strong>Module machine name</strong> — Asks for the machine name of the module where the subscriber will be created.</li><li><strong>hello_world</strong> – The module selected to contain the event subscriber.</li><li><strong>Class [HelloWorldSubscriber]</strong> — Prompts for the PHP class name of the event subscriber.</li><li><strong>(Default accepted)</strong> — Uses HelloWorldSubscriber as the class name automatically.</li><li><strong>Would you like to inject dependencies?</strong> — Asks whether to use dependency injection in the subscriber.</li><li><strong>No</strong> – Creates a basic subscriber without injecting services.</li><li><strong>Directories and files created</strong> — Displays the files generated by Drush.</li><li><strong>hello_world.services.yml</strong> – Registers the event subscriber as a service in Drupal.</li><li><strong>HelloWorldSubscriber.php</strong> – Contains the event subscriber class and its event-handling logic.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6XGJ3gkFHYkFB7pPCi_Ng.png" /></figure><h4>Step 3: Review Generated Files</h4><p>Drush will generate:</p><ul><li><strong>Event Subscriber class</strong> — contains your event logic</li><li><strong>services.yml file</strong> — registers the subscriber as a service</li><li><strong>getSubscribedEvents() method</strong> — defines which event to listen to</li></ul><h4>Step 4: Add Custom Logic</h4><p>Inside the subscriber method, add your custom code that should run when the event is triggered.</p><h4>Step 5: Clear Cache</h4><p>Enable the module and clear cache:</p><p><strong>drush en your_module_name -y<br>drush cr</strong></p><h4>Final Note</h4><p>Event Subscribers allow you to react to Drupal events in a clean, object-oriented way and Drush makes creating them fast and easy.</p><p><em>Thanks for reading! You should now have a clear understanding of how to create </em>Event Subscriber<em> in Drupal using Drush.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=082319bb8aec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Step-by-Step Guide to Creating Custom Configuration Form in Drupal 10 & 11 Using Drush]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/a-step-by-step-guide-to-creating-custom-configuration-form-in-drupal-10-11-using-drush-204a9de03525?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/204a9de03525</guid>
            <category><![CDATA[drupal]]></category>
            <category><![CDATA[drupal-configuration-form]]></category>
            <category><![CDATA[drupal-11]]></category>
            <category><![CDATA[drush]]></category>
            <category><![CDATA[drupal-10]]></category>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Sat, 24 Jan 2026 07:51:22 GMT</pubDate>
            <atom:updated>2026-01-24T07:51:22.241Z</atom:updated>
            <content:encoded><![CDATA[<p>A configuration form in Drupal is an administrative form that allows site administrators to manage and update configuration values through the UI. These values are stored in Drupal’s configuration system, not in the database as content.</p><p>Configuration forms are commonly used for site-wide settings such as API keys, feature toggles, default values, and module settings. The data entered in these forms is exportable and deployable across environments, making them ideal for configuration management.</p><p><strong>🔧 What is Drush?</strong></p><p>It’s a <strong>command-line tool</strong> that helps you manage a Drupal site <strong>without clicking around the UI</strong>.</p><p>Install Drush via Composer</p><p><strong>composer require drush/drush</strong></p><h4>✅ Step 1: Create a Custom Module (If Not Already Created)</h4><p><strong>drush generate module</strong></p><ul><li><strong>Welcome to module generator!</strong> — Confirms that the interactive module creation wizard has started.</li><li><strong>Module name</strong> — Human-readable name shown on the Extend (modules) page in Drupal.</li><li><strong>Module machine name</strong> — System name used in code and folder name (lowercase, underscores).</li><li><strong>Module description</strong> — Short explanation of what the module does, shown in the module list.</li><li><strong>Package [Custom]</strong> — Category under which the module appears on the Extend page.</li><li><strong>Dependencies (comma separated)</strong> — Other modules that must be enabled before this module.</li><li><strong>Create module file?</strong> — Decides whether to generate the .module PHP file.</li><li><strong>Create install file?</strong> — Decides whether to generate the .install file for hooks/schema.</li><li><strong>Create README.md file?</strong> — Decides whether to generate documentation for the module.</li><li><strong>Directories and files created</strong> — Shows what files were actually generated.</li><li><strong>custom_settings.info.yml</strong> – Main info file that registers the module with Drupal.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KWFNzLiXPhal_Mj6yNZF5Q.png" /></figure><p>Once generated, enable the module:<br><strong>drush en custom_settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hI3lwrffYsid2aR6xBLyLg.png" /></figure><h4>✅ Step 2: Generate a Configuration Form Using Drush</h4><p><strong>drush generate form:config</strong></p><ul><li><strong>Welcome to config-form generator!</strong> — Confirms the config form generator is running.</li><li><strong>Module machine name</strong> — Specifies which module this configuration form belongs to.</li><li><strong>Class [SettingsForm]</strong> — Defines the PHP class name for the config form.</li><li><strong>Create a route for this form?</strong> — Decides whether the form gets a URL in the admin UI.</li><li><strong>Route name</strong> — Unique internal identifier for the form route.</li><li><strong>Route path</strong> — URL where the config form will be accessible in admin.</li><li><strong>Route title</strong> — Page title shown on the configuration form page.</li><li><strong>Route permission</strong> — Permission required to access this settings page.</li><li><strong>Create a menu link for this route?</strong> — Decides whether to show the form in the admin menu.</li><li><strong>Link title</strong> — Text shown for the menu item.</li><li><strong>Link description</strong> — Help text shown under the menu link.</li><li><strong>Parent menu item</strong> — Defines where the link appears in the admin menu hierarchy.</li><li><strong>custom_settings.links.menu.yml</strong> – Registers the admin menu link.</li><li><strong>custom_settings.routing.yml</strong> – Defines the route and URL for the config form.</li><li><strong>custom_settings.schema.yml</strong> – Defines the configuration schema for stored values.</li><li><strong>CustomSettingsForm.php</strong> – PHP class that builds, validates, and saves the config form.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pG_W0TN-rszKPcqL4mJM5w.png" /></figure><h4><strong>✅ Step 3: Review the Generated Form Class</strong></h4><p>Drush creates the form file at:</p><p>custom_settings/src/Form/CustomSettingsForm.php</p><p>Key methods to notice:</p><ul><li><strong>getFormId()</strong> – Returns a unique ID so Drupal can identify and cache this form correctly.</li><li><strong>getEditableConfigNames()</strong> – Declares which configuration objects this form is allowed to edit.</li><li><strong>buildForm()</strong> – Builds and returns the form fields and default values shown to the user.</li><li><strong>submitForm()</strong> – Saves submitted form values into Drupal configuration when the form is submitted.</li></ul><h4>✅ Step 4: Add Fields to the Configuration Form</h4><p>Now add your configuration fields inside buildForm():</p><p>$form[‘api_key’] = [<br> ‘#type’ =&gt; ‘textfield’,<br> ‘#title’ =&gt; $this-&gt;t(‘API Key’),<br> ‘#default_value’ =&gt; $this-&gt;config(‘custom_settings.settings’)-&gt;get(‘api_key’),<br> ‘#required’ =&gt; TRUE,<br>];</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7uWZgL6qDhy6KAD16ZTTA.png" /></figure><h4>✅ Step 5: Save Configuration Values</h4><p>$this-&gt;config(‘custom_settings.settings’)<br> -&gt;set(‘api_key’, $form_state-&gt;getValue(‘api_key’))<br> -&gt;save();</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BAXT_MULkGhj1jdXUG2lMA.png" /></figure><p>Drupal now stores this value in configuration.</p><h4>✅ Step 6: Define Configuration Schema (Important ⚠️)</h4><p>Create the schema file:<br>custom_settings/config/schema/custom_settings.schema.yml</p><p>Add the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ML-DwzD5jK_Oizm9nL2gNw.png" /></figure><p>Without this file, Drupal will show warnings and your config won’t be fully translatable.</p><h4>✅ Step 7: Export Configuration Using Drush</h4><p><strong>drush cex</strong></p><p>You’ll now see:</p><p>config/sync/custom_settings.settings.yml</p><p>This file can be deployed to other environments.</p><h4>✅ Step 8: Access Configuration in Code</h4><p>$config = \Drupal::config(‘custom_settings.settings’);<br>$apiKey = $config-&gt;get(‘api_key’);</p><p><em>Thanks for reading! You should now have a clear understanding of how to create and manage a configuration form in Drupal 10/11 using Drush.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=204a9de03525" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Drupal: Hooks vs Events — When to Use What?]]></title>
            <link>https://ankit-kumar-fullstackdeveloper.medium.com/drupal-hooks-vs-events-when-to-use-what-79a0ab6abc18?source=rss-0ed101a706ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/79a0ab6abc18</guid>
            <dc:creator><![CDATA[Ankit Kumar]]></dc:creator>
            <pubDate>Sun, 18 Jan 2026 05:41:45 GMT</pubDate>
            <atom:updated>2026-01-18T05:41:45.635Z</atom:updated>
            <content:encoded><![CDATA[<p>🔍 <strong>Drupal: Hooks vs Events — When to Use What?</strong></p><p>During my journey of learning Drupal deeply, one recurring question shaped many of my implementation decisions:</p><p><strong>Hooks or event subscribers — which one should I use, and why?</strong></p><p>Here’s the clarity that helped me 👇</p><p><strong>🔗 Hooks</strong></p><p>Hooks are procedural functions provided by Drupal that allow modules to alter data or react to specific events in the system.</p><p><strong>Pros</strong></p><ul><li>✔ Simple and quick to implement</li><li>✔ Ideal for common core integrations</li><li>✔ Familiar to long-time Drupal developers</li></ul><p><strong>Cons</strong></p><ul><li>❌ Harder to manage in large or complex systems</li><li>❌ Not object-oriented</li></ul><p><strong>Common use cases</strong></p><ul><li>hook_form_alter()</li><li>hook_entity_insert()</li></ul><p>⚡ <strong>Events (Event Subscribers)</strong></p><p>Event subscribers follow an <strong>object-oriented approach</strong> and are built on <strong>Symfony’s EventDispatcher</strong>.</p><p><strong>Pros</strong></p><ul><li>✔ Clean, OOP-based architecture</li><li>✔ Easier to test and maintain</li><li>✔ Better control over execution order</li><li>✔ Recommended for modern Drupal (8+)</li></ul><p><strong>Common use cases</strong></p><ul><li>Reacting to kernel request/response events</li><li>Modifying responses globally</li><li>Handling decoupled or complex business logic</li></ul><p>🧠<strong> So, which one should you use?</strong></p><p>👉 <strong>Use Hooks when:</strong></p><ul><li>You’re altering forms or entities</li><li>Drupal already provides a hook for the task</li><li>The logic is small and straightforward</li></ul><p>👉 <strong>Use Events when:</strong></p><ul><li>You need a clean and scalable architecture</li><li>You’re working with the request/response lifecycle</li><li>You want modern, testable, and maintainable code</li></ul><p>Drupal still fully supports hooks, and they aren’t going away anytime soon.<br>However, <strong>event subscribers represent the future</strong> — they align better with modern PHP practices and scalable application design.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79a0ab6abc18" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>