Skip to content

Instantly share code, notes, and snippets.

View devudit's full-sized avatar
🎓
Focusing

Udit Rawat devudit

🎓
Focusing
View GitHub Profile
@devudit
devudit / layout.xml
Last active November 22, 2017 12:15
Move blocks to other container using layout xml
<!--
There is a new move node in the layout xml that we have access to in M2.
This node sets the declared block or container element as a child of another
element in the specified order.
-->
<!-- EXAMPLE -->
<move element="name.of.an.element" destination="name.of.destination.element" as="new_alias" after="name.of.element.after" before="name.of.element.before"/>
<!-- In the example you provided before you should just be able to call: -->
@devudit
devudit / custom-token.php
Created November 21, 2017 07:59
Create Custom Tokens In Drupal 8
<?php
/**
* @file
* contains custom token declaration script.
*/
/**
* Implements hook_token_info().
*/
function custom_token_info(){
$types['custom_type'] = array(
@devudit
devudit / initilize.html
Last active November 22, 2017 06:27
Run code before and after CkEditor Initilize
<textarea name="editor"></textarea>
@devudit
devudit / static-block.php
Last active November 22, 2017 06:27
Call static block in page
<?php
// If you want to call static block in page
// Try below code :
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}
?>
<?php
@devudit
devudit / redirect-back.php
Last active November 22, 2017 06:27
Redirect back to node edit page after node submit and not on preview
<?php
/**
* Implements hook hook_form_node_form_alter
**/
function hook_form_node_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
foreach (array_keys($form['actions']) as $action) {
if(is_array($form['actions'][$action])) {
@devudit
devudit / Helper.php
Created May 6, 2016 10:35
Dynamic body classes in laravel
<?php
// Create A class Helper as app/Helper/Helper.php
use Illuminate\Support\Facades\Request;
Class Helper {
public static function getBodyClass() {
$body_classes = [ ];
$class = "";
@devudit
devudit / query-string.js
Created May 25, 2017 06:16
How to get Query String using javascript
/**
* @description Below function will return a object of query string variable
**/
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
@devudit
devudit / attachment.php
Last active April 2, 2017 09:36
Add custom field to attachments in wordpress
<?php
/**
*
* @wordpress-plugin
* Plugin Name: Attachment custom fields
* Plugin URI: http://uditrawat.com
* Description: Custom fields for Attachments
* Version: 10.3
* Author: Udit Rawat
* Author URI: http://uditrawat.com
@devudit
devudit / get-ip-address.php
Created November 7, 2016 07:07
Getting the Correct IP Address With PHP
<?php
function get_ip() {
//Just get the headers if we can or else use the SERVER global
if ( function_exists( 'apache_request_headers' ) ) {
$headers = apache_request_headers();
} else {
$headers = $_SERVER;
}
@devudit
devudit / multiple-hook.php
Created August 1, 2016 10:10
Multiple Hooks in one extension - Expression Engine
<?php
$hooks = array(
"template_fetch_template" => "template_fetch_template",
"store_order_item_add_start" => "store_order_item_add_start"
);
foreach ($hooks as $hook => $method){
$data = array(
'class' => __CLASS__,
'method' => $hook,