Posts

D8 KernelEvents constants

Here is a list of KernelEvents constants: KernelEvents::CONTROLLER ; // The CONTROLLER event occurs once a controller was found for handling a request. KernelEvents::EXCEPTION ; // The EXCEPTION event occurs when an uncaught exception appears. KernelEvents::FINISH_REQUEST ; //The FINISH_REQUEST event occurs when a response was generated for a request. KernelEvents::REQUEST ; // The REQUEST event occurs at the very beginning of request dispatching. KernelEvents::RESPONSE ; // The RESPONSE event occurs once a response was created for replying to a request. KernelEvents::TERMINATE ; // The TERMINATE event occurs once a response was sent. KernelEvents::VIEW ; // The VIEW event occurs when the return value of a controller is not a Response instance.

PHP - How to increase size of POST value in php

Problem: PHP/HTML Forms with more the >20 fields(which approx post more the 1000 characters) will end up in error or the posted values will not be received in form action because by default in php  max_input_vars is set to 1000 . Solution:   In this case you can increase the size of  max_input_nesting_level and  max_input_vars in php.ini to resolve. max_input_nesting_level: Sets the max nesting depth of input variables (i.e. $_GET, $_POST.) max_input_vars How many input variables may be accepted (limit is applied to $_GET, $_POST and $_COOKIE superglobal separately). Use of this directive mitigates the possibility of denial of service attacks which use hash collisions. If there are more input variables than specified by this directive, an E_WARNING is issued, and further input variables are truncated from the request.

Linux - search all extension available in a folder(recursively)

To search all extension available in a folder(recursively) Navigate to the target directory cd target/directory find $directory -type f -name "*.docx" Note: find command works recursively by default

Linux - How to delete all files recursively for sub-folders with out deleting the folder/sub-folder

To List all the files recursively form the patent folder and sub-folder, cd /target/directory find . -type f To Delete all the files recursively form the patent folder and sub-folder, cd /target/directory find . -type f -delete To Delete all the sub-folders & files recursively form the patent folder, cd /target/directory find . -type rf -delete

D8 - Derive the route_name for the views created page

You can derive the views route_name from the below pattern view.{view_id}.{display_id} {view_id} - Basically the machine name appears in the URL when you edit the view. {display_id} - Hope the tab of every display to find the display ID(eg., page_1, page_2 etc.,)

D8 - Programmatically Redirect in Custom module

Use the below code use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Core\Url; return new RedirectResponse(\Drupal::url('{route_name}')); {route_name} - Name given while defining the path in .routing file. To derive the route_name of a views created page refer the below link, http://romelchrist.blogspot.com/2017/09/d8-derive-routename-for-views-created.html

D8 - How to Get Current node object in content view/edit page

$current_node = \Drupal::routeMatch()->getParameter('node');

D8 - Attach file programmatically to a node

Scenario 1: If the file resides on the other server/website. Try the below code, use \Drupal\node\Entity\Node; /** Create file object from remote server/website URL. */ $data = file_get_contents('https://www.example.com/sites/default/files/logo.png'); $file = file_save_data($data, 'public://logo.png', FILE_EXISTS_REPLACE); // Create node object with attached file. $node = Node::create([   'type'        => 'article',   'title'       => 'Sample test',   'field_image' => [     'target_id' => $file->id(),   ], ]); $node->save(); Refer " file_save_data " API for more options/overide functions Scenario 2:  If the file resides on the same server/website. Try the below code, use \Drupal\node\Entity\Node; use \Drupal\file\Entity\File; // Create file object from a locally copied file. $uri  = file_unmanaged_copy('public://source.jpg', 'public://destination.jpg', ...