Skip to content

Instantly share code, notes, and snippets.

@prashantdsala
prashantdsala / composer.json
Created December 18, 2023 16:02
Drupal: Clone unreleased version of a module/theme from git using composer
// Dowload form_mode_manager from git and using composer.
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8",
"exclude": [
"drupal/form_mode_manager"
]
},
{
@prashantdsala
prashantdsala / CustomSearchSubscriber.php
Created December 4, 2023 10:04
Alter Apache Solr Query and Boost Results
<?php declare(strict_types = 1);
namespace Drupal\custom_search\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Drupal\search_api_solr\Event\PreQueryEvent;
use Drupal\search_api_solr\Event\SearchApiSolrEvents;
<?php
// This file will reside in modules/custom/YOURMODULE/src/Config
namespace Drupal\custom_event\Config;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\StorageInterface;
/**
* Example configuration override.
@prashantdsala
prashantdsala / Reduce-git-size.txt
Created September 4, 2023 11:08
Reduce .git folder size
# To see the 10 biggest files, run this from the root directory:
$ git verify-pack -v .git/objects/pack/pack-7b03cc896f31b2441f3a791ef760bd28495697e6.idx \
| sort -k 3 -n \
| tail -10
# To see what each file is, run this:
$ git rev-list --objects --all | grep [first few chars of the sha1 from previous output]
# Rewrite all the commits:
$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch "Folder Name/*"' -- --all
@prashantdsala
prashantdsala / gist:4a67ddbee1347c288dc79c451eff6008
Last active June 1, 2023 04:54
Upgrade Google Chrome on Ubuntu
# use sudo apt-get update command to download package information from all configured sources.
# The sources often defined in the /etc/apt/sources.
sudo apt update
# upgrade google chrome to latest stable version
sudo apt --only-upgrade install google-chrome-stable
# check the google chrome version
google-chrome --version
@prashantdsala
prashantdsala / git.txt
Created April 28, 2023 05:11
Push to new or existing repository on github/gitlabs
// Git global setup
git config --global user.name "your git username"
git config --global user.email "your git email address"
// Create a new repository
git clone <.git url>
cd project_folder
touch README.md
git add README.md
git commit -m "add README"
@prashantdsala
prashantdsala / custom.js
Created April 12, 2023 07:06
Drupal - AJAX request using Drupal ajax and get response
$.ajax({
url: '/myurl/ajax',
type: 'POST',
data : {
title: title,
type : type,
target: target,
view : view,
display:display
},
@prashantdsala
prashantdsala / myController.php
Created April 12, 2023 06:57
Drupal - Snippet to programatically return a block as a response to AJAX request from controller
<?php
use Drupal\Core\Render\Renderer;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Form\FormBuilder;
/**
* Drupal\Core\Block\BlockManager definition.
*
* @var \Drupal\Core\Block\BlockManager
*/
@prashantdsala
prashantdsala / myController.php
Last active April 12, 2023 06:59
Drupal - Snippet to programatically return a view as a response to AJAX request from controller
<?php
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\views\Views;
use Drupal\Core\Render\Renderer
/**
* Drupal\Core\Render\Renderer definition.
*
* @var \Drupal\Core\Render\Renderer
@prashantdsala
prashantdsala / wget.php
Created April 12, 2023 06:42
PHP - Download file using "wget"
<?php
function __callURLinBackground($url) {
exec("wget -bqc ".$url." -P /var/www/html/", $output, $result_code);
echo $output;
echo $result_code;
echo '<pre>';print_r($output);
echo '<pre>';print_r($result_code);
echo 'Running in background';
}
// call a URL in background