Drupal

Drupal 7 : ApacheSolr custom search using Keyword - Example

ApacheSolr is the effective method to search the our site contents. With help of ApacheSolr module we can able to index site contents in apache solr server. To get solr server content from using function “apachesolr_search_execute”. This function return searched results as array.

Drupal 7 : Check given Path is valid system path or not with source code

To check given path is Drupal system path or not by using below functions. It check all Drupal system and modules path. It accepts string of path is argument return TRUE if valid path else FALSE if non exist path. We can able to pass wild cards for dynamic paths. For example node/*, comment/*. This function will check these type of paths also.

PHP : Replacing logical operators with logical strings with Example

In PHP normally we use logical operators for validating. The operators performs operation with values and return Boolean value as TRUE or FALSE. Normal logical operators are AND(&&) and OR(||). We can able to replace logical operators with logical strings.

Drupal 7 & 8 : Alter system path with custom Paths with Example

In Drupal system defines some paths. For example “node/add/CONTENT-TYPE”. We can change system path in custom module. There is hook function “hook_menu_alter()”. This hook loads all menu items in our system. By changing the items path by our custom path so system work with new path. In this hook we can also unset system path by unsetting item path.

Drupal 7 & 8 : Securing Files non Executable with Example

Normally servers hits request that execute file. To prevent execution of file we need make this files as securable by changing the extension of the file. In Drupal there is a function file_munge_filename() it will munge the actual file format by adding additional characters in extension. There by file is consider as some other file so it won't execute while calling. The function file_munge_filename() need argument of file name with additional arguments of extension details and message details. If extension is set than an underscore(_) will be adding to the file. If Message parameter set true Drupal message is show at user end.

Drupal 8 : Programmatically sent Mail from system - Example

In Drupal 8 there is function service() from core is used to send Emails. This function returns a object that help to trigger mail from system by passing argument as “plugin.manager.mail”. Using this Object call mail() function. After initiate mail need to call hook_mail() for define the Mail subject, Body and From address.

Drupal 8 : Get Site Informations like Site Name and Site Mail ID with Code

In Drupal 8 site information's are stored in system.site config file. This information's are accessed from config() function with help of Drupal object. Basically this settings holds the information's of Site name, Site Slogan and Site Mail Id.

Drupal 8 : Custom Form Validate and Submit in hook_form_alter() with Example

In Drupal 8 we can able to call custom validate and submit function for our need. This custom functions need to be defined in hook_form_alter(). Validate is defined as array parameter for #validate key of $form array. Similarly for submit is defined as array parameter for #submit on $form submit action.

Drupal 8 : Encrypting String with Site Private Key including Sample code

In Drupal 7 to encrypt the string we use the core function “drupal_hash_base64()”. This function have 2 parameters, Encrypting string and optional parameter of Site private key. But this function is deprecated in Drupal 8. In Drupal 8 we need to use the class Crypt from component utility for encryption. Similarly it have 2 parameters. Accessing Private key of your site by calling the service function of Core “\Drupal::service('private_key')->get()”.

Drupal 7 : Alter View Pagination with custom Pager

We can set pager for our views in user interface under pager [Shown in screenshot]. For our custom purpose we can alter the views pager in our module by using the hook function hook_views_pre_render(). This hook contains the reference argument $view that have all render able array of the view. Using this argument we can reset the pager based on our requirements.