Skip to content

Instantly share code, notes, and snippets.

View ConfigExampleOverrides.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 / Reduce-git-size.txt
Created September 4, 2023 11:08
Reduce .git folder size
View Reduce-git-size.txt
# 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 / gist:4a67ddbee1347c288dc79c451eff6008
Last active June 1, 2023 04:54
Upgrade Google Chrome on Ubuntu
View gist:4a67ddbee1347c288dc79c451eff6008
# 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 / git.txt
Created April 28, 2023 05:11
Push to new or existing repository on github/gitlabs
View git.txt
// Git global setup
git config --global "your git username"
git config --global "your git email address"
// Create a new repository
git clone <.git url>
cd project_folder
git add
git commit -m "add README"
prashantdsala / custom.js
Created April 12, 2023 07:06
Drupal - AJAX request using Drupal ajax and get response
View custom.js
url: '/myurl/ajax',
type: 'POST',
data : {
title: title,
type : type,
target: target,
view : view,
prashantdsala / myController.php
Created April 12, 2023 06:57
Drupal - Snippet to programatically return a block as a response to AJAX request from controller
View myController.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 / myController.php
Last active April 12, 2023 06:59
Drupal - Snippet to programatically return a view as a response to AJAX request from controller
View myController.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 / wget.php
Created April 12, 2023 06:42
PHP - Download file using "wget"
View 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
prashantdsala / example.module
Created April 12, 2023 06:37
Drupal - Alter views query and add where conditions
View example.module
* Implements hook_views_query_alter().
function mymodule_announcements_views_query_alter(Drupal\views\ViewExecutable $view, Drupal\views\Plugin\views\query\QueryPluginBase $query) {
// Alter annoucements views.
if (($view->id() == 'announcements')) {
if ($view->current_display == 'page_announcements' || $view->current_display == 'block_announcements') {
$current_user_id = \Drupal::currentUser()->id();
$user_service = \Drupal::service('my_service.user');
prashantdsala / interfaces.php
Created March 21, 2023 09:50
Example of implementing interfaces in PHP
View interfaces.php
// Define the interface for a payment gateway
interface PaymentGateway {
public function processPayment(float $amount): bool;
// Define a class for a credit card payment gateway that implements the PaymentGateway interface
class CreditCardGateway implements PaymentGateway {
private string $apiKey;