Skip to content

Instantly share code, notes, and snippets.

@davidjguru
davidjguru / intro_drupal_8_9_getting_taxonomy_terms_from_different_levels_programmatically.md
Last active August 28, 2024 05:24
Drupal 8 || 9 - Getting Taxonomy Terms from different levels programmatically

Introduction

In this snippet I've gathered some examples and cases about how to get taxonomy terms programmatically in Drupal, using always the same method and the same mechanics: get terms and then processing it in order to get only the required under certain criteria.

Author

@ChristofKaufmann
ChristofKaufmann / FastLED_RGBW.h
Created May 26, 2021 11:17
This is a workaround for FastLED library to make SK6812 RGBW led strips work.
/* FastLED_RGBW
*
* Hack to enable SK6812 RGBW strips to work with FastLED.
*
* Original code by Jim Bumgardner (http://krazydad.com).
* Modified by David Madison (http://partsnotincluded.com).
* Modified by Christof Kaufmann.
*
*/
@vijayrana99
vijayrana99 / google-reviews.php
Created March 3, 2021 13:58
Retrieve google reviews on website using Curl Request in PHP
<?php
$cid = 1417698146920752799; //CID of a place can be genrated from https://pleper.com/index.php?do=tools&sdo=cid_converter
//execute curl
$url = 'https://maps.googleapis.com/maps/api/place/details/json?cid='.$cid.'&key=<API-KEY>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$data = curl_exec($ch);
@maitrungduc1410
maitrungduc1410 / create-vod-hls.sh
Last active August 6, 2024 16:37
Bash scripts to create VOD HLS stream with ffmpeg (Extended version)
#!/usr/bin/env bash
START_TIME=$SECONDS
set -e
echo "-----START GENERATING HLS STREAM-----"
# Usage create-vod-hls.sh SOURCE_FILE [OUTPUT_NAME]
[[ ! "${1}" ]] && echo "Usage: create-vod-hls.sh SOURCE_FILE [OUTPUT_NAME]" && exit 1
# comment/add lines here to control which renditions would be created
renditions=(
@atuline
atuline / circring.ino
Last active February 16, 2022 14:12
Circular loader ring
/* Circular loader ring (a real basic one)
*
* By: Andrew Tuline
*
* Date: May, 2019
*
* One version uses a loop and fixed colours, while the other uses a fader.
*
*/
@signalpoint
signalpoint / example.php
Last active July 16, 2022 23:41
Drupal 8 Set Message Example
<?php
// The drupal_set_message() function is being deprecated!
// @see https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/function/drupal_set_message/8.5.x
// > Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
// > Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
// In some custom code.
\Drupal::messenger()->addMessage('Say something else');
@ilkermutlu
ilkermutlu / convert.md
Last active April 9, 2024 11:23
Convert PDF file to v1.4
// Not much of PHP magic
// This just takes a PDF file from a path
// and executes Ghostscript to convert your
// PDF to version 1.4

// You need to have Ghostscript installed
// See https://www.ghostscript.com/Documentation.html

$PDFFile = '/path/to/your/pdf.pdf';
@bdlangton
bdlangton / Blocks.md
Last active October 12, 2023 08:40
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@ardyantohermawan
ardyantohermawan / ngrok-install.sh
Created November 7, 2017 06:30
Ngrok Service Ubuntu 16.04
#!/bin/bash
# download
wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
# unzip
unzip ngrok-stable-linux-amd64.zip
# move to /usr/local/bin
sudo mv ngrok /usr/local/bin
@ohthehugemanatee
ohthehugemanatee / RestaurantEntity.php.diff
Created September 18, 2017 11:10
Add revisions to an existing entity. In a project for RAS I had to add revisions to an existing entity. There are some small modifications necessary to the entity class itself, and two update hooks to apply the schema changes (core's normal process won't allow you to modify the schema of an entity type with existing data). Note that entity_ui=TR…
use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\RevisionableContentEntityBase;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
@@ -19,6 +20,7 @@
* @ContentEntityType(
* id = "restaurant",
* label = @Translation("Restaurant"),
+ * show_revision_ui = TRUE,