What are the Events in Drupal

Events in Drupal allow various system components to interact and communicate with one another while remaining independent, or decoupled. The event system is built on the Symfony event dispatcher component, and is an implementation of the Mediator design pattern.

As an application grows in complexity, and additional components are added, it becomes necessary for those components to communicate with one another. Rather than having objects refer to one another explicitly, which can quickly turn into a maintenance nightmare, communication is instead facilitated by a mediator object. This reduces the dependencies between communicating objects, thereby lowering the coupling, and creating a code base that's easier to maintain.

When writing custom code you can dispatch events in order to notify other components in the system about actions taken by your code. For example, the Recurly module works with the Recurly web service to facilitate subscription billing. The Recurly web service handles the recurring logic, and charging of subscribers. Whenever a charge is made Recurly sends a ping notification to the Drupal Recurly module. The module receives the incoming notice, opens its contents, and uses that to make changes within Drupal. It would be impossible for the Recurly module to hard-code every possible action that someone might want to take when a user cancels their subscription. So instead, it takes the incoming notice, wraps it in an Event object, and then dispatches a new "recurly ping received" event, to which any number of different modules can subscribe and do things like cancel the Drupal user's account, send an email, display a message, or anything else you as a PHP developer could conceive of.


Event subscribers respond to specific events being triggered and perform custom logic. Which could be anything from updating related settings when a configuration change occurs in another module, to redirecting a request after inspecting the request parameters.

Drupal Contextual filters

Contextual filters are the Views mechanism for dynamically refining the contents of a view. It might be also called as "dynamic filters".  Contextual filters in the Views UI, and review the Taxonomy term view that comes with Drupal and how it uses a contextual filter.

For example
A contextual filter for a node author would be able to display all nodes written by the currently logged in user.

Step 1

We have to go through basic View Page creation by visiting /admin/structure/views/add

Fill up View Basic information, Page settings detail and click on Save and edit. 
I have created a view with below input.

View Basic Information
         View name: Article
         Description: listing article created by logged in User

View Settings
         Show: Content
         of Type: Article
         
Page Settings
        Page Title: Article
        Path: article

Page Display Settings
         Display format: Table


















Step 2
Once we have done with Step1, next we would be redirected to View Settings Page. Here I have added Body, Authored by & Authored on under Fields Section. Now click the Advanced Section on extreme right and click on CONTEXTUAL FILTERS “Add” button.

FIELDS
     Content: Body
     Content: Authored by (Authored by)
     Content: Authored on (Authored on)













Step 3

Search For “Authored by” and click on Apply (all displays).












Step 4
Select “Provide default value” under WHEN THE FILTER VALUE IS NOT IN THE URL & Select Type as “User ID from logged in user” and click on Apply (all displays).

Step 5
So, we are done with view creation. It’s time to review by visiting
the URL: localhost/d8/article

This page is showing articles created by logged in users and we don’t have to pass any additional argument. Try logging with some other user credentials and visit article-by-you page to test the view we have created just now. 


Basic PHP interview Question (TCS, Wipro, Capgemini, HCL) For Freshers

 What is the interface in PHP and how it is use

What is the use of friend function

How can we submit a form without a submit button

Why is PHP-MySQL frequently used for web (Portal) Development

PHP : Validating and Sanitizing User Input Data with Filters

What is the difference between InnoDB and MyIsam

 Any 2 regular expressions with example

How can we extract string 'abc.com' from a string "http://info@abc.com" using regular expression of PHP

What is a procedure in PHP

How to display and include the user system date/time in a php program/project

How to remove duplicate values from an array in PHP

What is recursive function

How to send mail from localhost XAMPP using PHP

What is PDO 

What is Type casting in PHP 

Write a Program in PHP to reverse a Number

Write a program in PHP to find no of days between two dates 

PHP Abstract Class and Methods

What is the relation between Classes and Objects

What is Constructor and Destructor

What is Git

How to Create a new branch in Git

Convert PHP Array To JSON

Difference between array_merge() and array_combine() in PHP 

PHP Method Overloading

MySQL Thread Cache Size

How to find a position of character in a string in PHP without using strpos function

Dependency Injection 

PHP Namespace

PHP use Keyword

PHP - Traits

Difference Between PHP echo and print Statements 

Prevention of Host Header Injection in PHP

PHP - Remove warning and notice

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...