Skip to content

Instantly share code, notes, and snippets.

prashantdsala / drupalTimestamp.php
Created February 27, 2024 10:05
Drupal: Get timestamp from date field and current time
use Drupal\Core\Datetime\DrupalDateTime;
// Check if the event's end date is not present
// or has been passed.
$current_time = new DrupalDateTime('now', 'UTC');
if ($entity->get('field_event_end_date')->isEmpty() || ($current_time->getTimestamp() >= $entity->field_event_end_date->date->getTimestamp())) {
prashantdsala / settings.php
Created February 4, 2024 05:38
Drupal - Specify path for private files directory
* Private file path:
* A local file system path where private files will be stored. This directory
* must be absolute, outside of the Drupal installation directory and not
* accessible over the web.
* Note: Caches need to be cleared when this value is changed to make the
* private:// stream wrapper available to the system.
prashantdsala / bltddev.txt
Created December 22, 2023 04:16
Setup Acquia BLT with ddev and Drupal 10
// Following steps are to setup Acquia BLt with Drupal 10 which is a kind of work around till gets resolved.
// These steps assuming you have all pre-requisuites done
// Main point here is The Drupal root must be in a top-level "docroot" directory.
1. composer create-project --no-interaction --no-install drupal/recommended-project drupalblt
2. cd drupalblt
3. sudo sed -i '' -e "s|web/|docroot/|g" composer.json (replacing web/ with doctroot/ to make docroot the top-level directory)
4. composer require --dev thegbomb/blt-ddev
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": "",
"exclude": [
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;
// 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
# 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
# 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
// 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
url: '/myurl/ajax',
type: 'POST',
data : {
title: title,
type : type,
target: target,
view : view,