Skip to content

Instantly share code, notes, and snippets.

@prashantdsala
prashantdsala / build.yml
Created July 25, 2024 14:25
Github actions "build" part steps
# create a folder .github/workflows and file name say build.yml
# create a token from Profile settings, Developer settings, Personal access token, Token(classic)
# create secret keys in repo settings "Secrets and variables" -> "Actions"
name: Build and Deploy SSG
on:
repository_dispatch:
types: [deploy]
env:
@prashantdsala
prashantdsala / deploy.yml
Created July 25, 2024 14:22
Github actions "deploy" part steps
# copy public key into authrized keys file: cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# chmod 600 ~/.ssh/authorized_keys
# create secrets in repo settings actions page.
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Download build artifacts
@prashantdsala
prashantdsala / gist:759cfd6ca629451c7a2f30275adff521
Last active July 1, 2024 09:49
Renaming a branch both locally and remotely:
# Rename the branch locally
git branch -m old-branch-name new-branch-name
# Push the renamed branch and set upstream
git push origin -u new-branch-name
# Delete the old branch from the remote repository
git push origin --delete old-branch-name
# Clean up local branches (optional)
@prashantdsala
prashantdsala / drupalTimestamp.php
Created February 27, 2024 10:05
Drupal: Get timestamp from date field and current time
<?php
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
prashantdsala / settings.php
Created February 4, 2024 05:38
Drupal - Specify path for private files directory
<?php
/**
* 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
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
// https://docs.acquia.com/blt/install/
// https://docs.acquia.com/blt/install/adding-to-project/
// 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
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