Skip to content

Instantly share code, notes, and snippets.

@pingevt
pingevt / settings.local.php
Created February 20, 2023 17:50
Switch DB with local Drupal
...
$stringfromfile = file('../.git/HEAD', FILE_USE_INCLUDE_PATH);
$firstLine = $stringfromfile[0]; //get the string from the array
$explodedstring = explode("/", $firstLine, 3); //seperate out by the "/" in the string
$branchname = $explodedstring[2];
$last = explode("/", $branchname);
@pingevt
pingevt / _db_connection.php
Last active March 11, 2023 20:18
If you want multiple DBs per git branch, add this code to you settings.local.php
// After your local DB settings.
$stringfromfile = file('../.git/HEAD', FILE_USE_INCLUDE_PATH);
$firstLine = $stringfromfile[0]; //get the string from the array
$explodedstring = explode("/", $firstLine, 3); //seperate out by the "/" in the string
$branchname = $explodedstring[2];
$last = explode("/", $branchname);
$op_db_name = $databases['default']['default']['database'] . "__" . trim($last[(count($last) - 1)]);
try {
@pingevt
pingevt / deploy-to-pantheon.yml
Created August 1, 2022 16:58
Action - Push to Pantheon - wNode
name: Deploy to Pantheon
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: shimataro/ssh-key-action@v2
@pingevt
pingevt / deploy-to-pantheon.yml
Last active August 1, 2022 16:42
Action - Push to Pantheon - wBranch
name: Deploy to Pantheon
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: shimataro/ssh-key-action@v2
@pingevt
pingevt / deploy-to-pantheon.yml
Last active August 1, 2022 16:41
Action - Push to Pantheon - Simple
name: Deploy to Pantheon
on:
push:
branches:
- 'master'
jobs:
build:
runs-on: ubuntu-latest
steps:
@pingevt
pingevt / gen_menu.php
Last active February 16, 2022 17:21
Generate Test Menu - Drupal 8/9
function _build_test_menu($link_title, $how_many, $full_depth = 3, $parent_id = NULL, $current_depth = 1) {
$menu_link_storage = \Drupal::entityTypeManager()->getStorage('menu_link_content');
for ($a = 1; $a <= $how_many; $a++) {
$new_title = $link_title . $a;
if ($current_depth != $full_depth) $new_title .= ".";
$item1 = $menu_link_storage->create([
'title' => $new_title,
'link' => ['uri' => 'internal:/'],
'menu_name' => 'main',
@pingevt
pingevt / translate.php
Last active March 4, 2021 16:50
Drupal - Multi-lingual
<?php
use Drupal\node\Entity\Node;
/**
* Create node with English/Spanish.
*/
$node = Node::create([
'type' => 'article',
@pingevt
pingevt / img_style.php
Created January 9, 2021 14:01
Create image styles on the fly
use Drupal\image\Entity\ImageStyle;
$name = "34x9_full";
$sizes = [
'1024' => ['max' => 1440],
'768' => ['max' => 1023],
'500' => ['max' => 767],
'default' => ['max' => 499],
];
// Time Service (replacing REQUEST_TIME)
use Drupal\Component\Datetime\TimeInterface;
/**
* Time Service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $timeService;
/**
@pingevt
pingevt / assets--src--js--ViewsSCrollTop.js
Created November 1, 2019 13:41
Views Ajax Response Commands
(function ($, Drupal) {
Drupal.AjaxCommands.prototype.viewsScrollTop = function (ajax, response, status) {
var offset = $(response.selector).offset();
var scrollTarget = response.selector;
while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).parent()) {
scrollTarget = $(scrollTarget).parent();
}