Skip to main content

Posts

Why drupal is not fully object oriented ?

You can see module hooks are still in a procedural way to  utilize a dependent service  That's why we have a static  Drupal Class , it can get a service in a procedural context. How to access a service in module hooks? Drupal::service('{service id}') or  service accessors like Drupal::request(), Drupal::currentUser(), Drupal::entityManager(). It is providing a uniform way of getting any services inside hooks and it eases the transition from procedural code to injected oops code. How a container get services in drupal?  The container is built by the kernel  and passed to the static Drupal Class and the container gets all the services from the system by the below methods    1. \Drupal\Core\CoreServiceProvider    2.  the service providers of enabled modules     3. any other service providers defined in $GLOBALS['conf']['container_service_providers']. How you can improve the dependent service access from module ?  function hook_do_stuff() { $lock = lock()
Recent posts

Redirection In Drupal 8 Programatcially

Redirection In Drupal 8  In this post we can learn about the ways we can make redirect in Drupal 8. You can make a custom redirect according to the context in many ways. Form Redirect      We can use the formstate object to redirect from form.     Currently below two methods are available from Drupal\Core\Form  formstate to build  a    \Symfony\Component\HttpFoundation\RedirectResponse  for redirection. 1) setRedirect  function setRedirect($route_name, array $route_parameters = [], array $options = []) This method will call the setRedirectUrl function inside it. 1) route_parameters - optional argument 2) route_name -  The name of the route name. 3) options -    (optional) An associative array of additional URL options, with the    *   following elements:    *   - 'query': An array of query key/value-pairs (without any URL-encoding)    *     to append to the URL .    *   - 'fragment': A fragment identifier (named anchor) to append to the URL.    *     Do not incl

Things You Must Know Before Trying Forms In Drupal 8.

 You Should Invest In Forms                      What does your customer think?  What do they looking for? will decide the success of any business.    In a digital marketing, Most of the customer requirement is gathered through forms. So its   essential  to spend some  time with forms Example : a user can search a particular product using the search form on an e-commerce website. Form API in Drupal 8          As we know already Drupal use forms for most of the administrative site building. Drupal 8 follows object-oriented style of programming with the integration of symfony . Based on the purpose of the form, it can inherit the basic properties and methods of the below classes. 1.Config Base 2.FormBase 3.ConfirmBase   Note : Routing configuration is done through the yml files in drupal 8 When the user hits the valid url in the browser , Major Responses are 1.Page Content 2.Forms 3.Map..etc. Basic Routing Configuration for Form Internal path-machi

Twig in Drupal 8

                                             Twig in Drupal 8 Introduction   In web development , every developer knows  presenting  a content in a  webpage is more important than any  functional logic inside the website whether the site is for tutoring , just a blog or its site for ecommerce products , how your site going to interact with the user plays major role for your business profit . Its a matter of minute to hold your customer/user in online to make a profit. you may thought , it is inappropriate to discuss those  with the title of this post  twig in drupal 8.   twig is used as presenter of your content in an easy way. Templating Engine in drupal 7     For those who are familiar with drupal 7 already know that php is used as templating engine . So its with an advantage of adding much more logic while creating an template for any page in drupal 7. So it is an necessity for front end developer to know about basic level of php to work with drupal 7.

Multi site Set up on drupal on Lamp(Linux ,Apache , Mysql, Php )

Hi all, In this post , we are going to create a multisite on drupal 8 , Two  sites namely dogs and cats can share the same codebase and different database  Here am using Ubuntu 16.04  , So that some server configurations may vary depend on your server... So please follow the below steps to create a multi site on drupal 8 Step1:  Download the latest  drupal 8 project using the  link   www.drupal.org . Note: You can use any other method you follow to download drupal Project ..For Example : Console , Composer Step 2:  Extract the downloaded  package inside your Html folder For Example:  var/www/html/ drupal-8.4.3( Your downloaded folder here ) Step3:  In your Drupal Root Folder (drupal-8.4.3)       In the sites folder create the  required  sites as shown in the screenshot Here i create two sites namely cats and dogs sharing the same codebase and different database Step4: Inside the cats and dog folders   copy the default.settings file from the the defa

Process of page request to response in Drupal 8 - Part 1

For every drupal developer is it necessary to know the under the hood process of how drupal internally works and some of them may already know  page rendering process of drupal 7. Lets see the Process of User Request to Response in  two parts: PART 1: Step 1:  The user make a request in the browser in the form of url for example: www.example.com Step 2:  The browser will pass the request to the Web server where the website  resides(Here Drupal makes website...) Step 3: In drupal , every request is handled via index.php file ,while digging into index file we may see the following lines as shown in the image. Note:  Symfony is a playing a major role  in  drupal 8 and drupal 8 follows the object oriented style of programming .. Components used from symfony in drupal 8.  So as you see , there is a two use statements  1.use Drupal\Core\DrupalKernel 2.use Symfony\Component\Httpfoundation\Request. Drupal and Symfony co

Hooks in Drupal

                  Hi All ,            For Every Drupal Developer initially get strucked with the concept of drupal is Hooks. It is the major driven approach in the old versions of drupal but  hooks are there in  drupal 8 too .                  Inorder to describe about  hook i dont want to explain with simple  statements or definitions. I assume that below points will make you clear in the concept of hooks in drupal 8. 1. Hooks occur at various points in the thread of execution, where Drupal seeks contributions from all the enabled modules. 2.A hook can be thought of as an event listener in the sense that an event triggers an action. The event in Drupal, such as deleting a node, would trigger the hook "hook_delete". 3.One way for modules to alter the core behavior of Drupal (or another module) is to use hooks. Hooks are specially-named functions that a module defines (this is known as "implementing the hook"), which are discovered and called at spec