Skip to content

Instantly share code, notes, and snippets.


Udit Rawat devudit

View GitHub Profile
devudit / SftpFetcher.php
Created August 12, 2022 13:38
Feeds Fetcher — Drupal
View SftpFetcher.php
namespace Drupal\feeds_sftp_fetcher\Feeds\Fetcher;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Utility\Token;
use Drupal\feeds\Exception\EmptyFeedException;
use Drupal\feeds\FeedInterface;
devudit / XML Country List
Created February 6, 2020 16:47 — forked from nathanhornby/XML Country List
XML Country list, with country code, ISO number, continent, handle and alternative spelling attributes.
View XML Country List
<?xml version='1.0' encoding='UTF-8'?>
<country code='af' handle='afghanistan' continent='asia' iso='4'>Afghanistan</country>
<country code='al' handle='albania' continent='europe' iso='8'>Albania</country>
<country code='dz' handle='algeria' continent='africa' iso='12'>Algeria</country>
<country code='as' handle='american-samoa' continent='polynesia' iso='16'>American Samoa</country>
<country code='ad' handle='andorra' continent='europe' iso='20'>Andorra</country>
<country code='ao' handle='angola' continent='africa' iso='24'>Angola</country>
<country code='ai' handle='anguilla' continent='north america' iso='660'>Anguilla</country>
<country code='aq' handle='antarctica' continent='antarctica' iso='10'>Antarctica</country>
devudit / taxonomy-term.php
Created November 29, 2017 10:16
Find tid by name in drupal 8
View taxonomy-term.php
* Utility: find term by name and vid.
* @param null $name
* Term name
* @param null $vid
* Term vid
* @return int
* Term id or 0 if none.
devudit / vocabulary.php
Last active April 14, 2023 15:39
Create vocabulary and term programmatically in drupal 8 Assing vocabulary to a referenced field storage automatically
View vocabulary.php
/** If vocabulary id not exist */
* Create vocabulary
* @var $vocabulary
$vocabulary = \Drupal\taxonomy\Entity\Vocabulary::create([
'vid' => $vocab_id,
devudit / isset.js
Last active December 3, 2017 18:25
JavaScript isset() equivalent
View isset.js
// I generally use the typeof operator:
if (typeof !== 'undefined') {
// your code here
// It will return "undefined" either if the property doesn't exist or its value is undefined.
// There are other ways to figure out if a property exists on an object, like the hasOwnProperty method:
devudit / drupal.dialog.js
Created November 27, 2017 12:32
Create modal window in drupal 8 using Drupal.dialog function
View drupal.dialog.js
/** EXAMPLE 1 ***/
var $myDialog = $('<div>My dialog text</div>').appendTo('body');
Drupal.dialog($myDialog, {
title: 'A title',
buttons: [{
text: 'Close',
click: function() {
devudit / index.html
Last active December 3, 2017 18:25
Run a javascript function after user has stopped typing
View index.html
<input type='text' id='text'>
devudit / layout.xml
Last active November 22, 2017 12:15
Move blocks to other container using layout xml
View 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="" 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 / redirect-back.php
Last active November 22, 2017 06:27
Redirect back to node edit page after node submit and not on preview
View redirect-back.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 / static-block.php
Last active November 22, 2017 06:27
Call static block in page
View static-block.php
// If you want to call static block in page
// Try below code :
{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}