Skip to content

Instantly share code, notes, and snippets.

View msankhala's full-sized avatar
🎯
Focusing

mahesh sankhala msankhala

🎯
Focusing
View GitHub Profile
@msankhala
msankhala / panel-panelizer-snippets.php
Last active March 18, 2024 11:44
Panel/Panelizer: snippets
<?php
// When we have a panels page in features and we want to move it to database
// we need to run.
$cache = page_manager_get_page_cache('page-PAGENAME');
page_manager_save_page_cache($cache);
// Build contextual link for the custom pane (after pane's information is in database)
if (user_access('administer site configuration')) {
ctools_include('modal');
@msankhala
msankhala / laravel-multiple-env-setup.php
Last active February 29, 2024 04:53
Setup Multiple Environment for Laravel 5 Developers Way
<?php
/*
|--------------------------------------------------------------------------
| Follow this instructions:
|--------------------------------------------------------------------------
|
| Laravel takes a dead simple approach to your application environments
| so you can just specify a machine name for the host that matches a
| given environment, then we will automatically detect it for you.
@msankhala
msankhala / Drupal8HorizontalTabs.php
Created December 14, 2023 12:50 — forked from leymannx/Drupal8HorizontalTabs.php
How to create horizontal tabs programmatically in Drupal 8, requires Field Group module
<?php
// How to create horizontal tabs programmatically in Drupal 8, requires Field Group module
$form = array();
$form['my_field'] = array(
'#type' => 'horizontal_tabs',
'#tree' => TRUE,
'#prefix' => '<div id="unique-wrapper">',
'#suffix' => '</div>',
);
$items = array(
@msankhala
msankhala / nginx-ssl-config
Created September 9, 2020 06:50 — forked from apollolm/nginx-ssl-config
Nginx Configuration with multiple port apps on same domain, with SSL.
# the IP(s) on which your node server is running. I chose port 3000.
upstream app_geoforce {
server 127.0.0.1:3000;
}
upstream app_pcodes{
server 127.0.0.1:3001;
}
@msankhala
msankhala / NearestEventFilter.php
Last active May 24, 2023 17:08
Drupal 9 Views custom filter plugin to filter content based on users zipcode
<?php
namespace Drupal\mymodule\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\Core\Form\FormStateInterface;
use Geocoder\Formatter\StringFormatter;
use Drupal\user\Entity\User;
/**
@msankhala
msankhala / tmux-restore-lost-sessions.md
Created April 10, 2023 12:50
How to restore tmux lost sessions

How to restore tmux lost sessions

Tmux is a terminal multiplexer that allows users to create multiple sessions, panes, and windows within a single terminal window. It is an excellent tool for developers and system administrators who often work with multiple terminal sessions at once. However, sometimes users may face a situation where their tmux session gets lost due to system restart, terminal crash, or any other reason. In this blog post, we will discuss how to restore a lost tmux session.

There are various plugins available for tmux, including tmux-resurrect and tmux-continuum. These plugins allow users to save and restore their tmux sessions, making it easy to recover from a lost session. However, sometimes these plugins may not work correctly, and users may still lose their tmux session. In such cases, users can follow the steps mentioned below to restore their lost tmux session.

Step 1: Check for session files

The first step is to check if the session files created by tmux-resurrect are present

@msankhala
msankhala / drush-turn-off-aggregate-assets.txt
Last active January 2, 2023 08:18 — forked from chrisjlee/drush-turn-off-aggregate-assets.txt
drush disable js/css aggregation
Drupal 7
// To turn on JS Aggregation
drush vset preprocess_js 1 --yes
// To clear all Cache
drush cc all
// To disable JS Aggregation
drush vset preprocess_js 0 --yes
@msankhala
msankhala / d8-entity-api-cheet-sheet.md
Created May 4, 2018 11:28
d8 entity api cheet sheet

Drupal 8 Entity API cheat sheet

The examples here contain some hard-coded IDs. These are all examples. In your real code, you should already have the node IDs, file IDs, etc. in a variable.

Working with nodes

Load a node by NID:

$nid = 123;     // example value
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node = $node_storage->load($nid);
@msankhala
msankhala / DeleteFeeds.php
Created November 25, 2022 12:49
Drupal 9 batch api example using BatchBuilder
<?php
namespace Drupal\miax_content\Command;
use Drupal\Core\Batch\BatchBuilder;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drush\Commands\DrushCommands;
use Drupal\miax_content\Services\DeleteFeedsBatchService;
@msankhala
msankhala / ampersand-before-php-function-names.php
Last active June 13, 2022 14:15
Understanding Ampersand Before PHP Function Names – Returning By Reference
<?php
// You may have wondered how a PHP function defined as below behaves:
function &config_byref()
{
static $var = "hello";
return $var;
}
// the value we get is "hello"
$byref_initial = config_byref();