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.
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.
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.
In Drupal there is a function drupal_mkdir(). It helps to create Directory/folder in Server. This function supports on Drupal 7 and Drupal 8 version. This function uses the help of core PHP mkdir() function to create directory.
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.
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.
In Drupal we can define custom validate, on validation able to set field errors. This error is set with help of FormStateInterface object by calling function “setErrorByName”. This functions need 2 arguments to set errors.
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.
In Drupal 7 we use key as “#redirect” of form to redirect. But in Drupal 8 we can’t use this, For Redirection we need call function “setRedirect()”. This function called with FormStateInterface object with argument of redirect URL.
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()”.
In PHP there is a function strip_tags() with argument of string type, which help to remove HTML tags from given string. But in Drupal there is a function drupal_explode_tags(). I will explode the HTML tags from Given String.
In Drupal we can't send HTML mails, It won’t support HTML content rendering. In Drupal mail Body considered as normal text. So we need to alter the mail content mime type to HTML for HTML tags support.
In Drupal 7 we can send mail using the function drupal_mail(). It help to sent mail from our Drupal system. This function need mail module, mail key, to mail id, from id, mail language and parameters with mail subject and message body.
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.
To Alter the View query in Drupal we can use the hook_views_pre_execute(). This function have a argument contains views details. From the parameter contains information about query that run to generate result for us. Using the Query information we need to add range for our view.
In Drupal 8 Core class user entity provide the user related information to us. Using the Role Class function loadMultiple(), will returns all Roles available in our Drupal 8 site as Object. Similarly load() function return particular Role information as Object.
In Drupal 7 there function called module_exist(). This function returns true if module exist else return false. For Drupal 8 module_exist() function is Deprecated. In Drupal there is Core function moduleHandler() will more information about modules in Drupal system. The moduleHandler() returns a object, using this object we can call moduleExists() function with module name as parameter to the function.
If we planned to restrict some pages from user we put 404 error message to that page that is called Access Denied. To achieve this in Drupal 8 we need to use Symfony components class. This AccessDenied is handle as Exception in Drupal 8. By using HttpKernel’s AccessDeniedHttpException class constructor Drupal 8 throwing 404 error.
In Drupal 8 fully works on OOPs concept. To create page redirection we need to use Symfony components class. The page redirection is done by RedirectResponse Class from Symfony HttpFoundation. This class object used inside function as a return parameter. While creating object we need to send valid site path to the constructor of RedirectResponse class. In Drupal 7 we using drupal_goto() function for redirect.