Skip to content

Instantly share code, notes, and snippets.

View miloskroulik's full-sized avatar

Miloš Kroulík miloskroulik

View GitHub Profile
@pyrello
pyrello / drupal-core-dev-setup.md
Last active October 24, 2023 07:04
Drupal core development easy local setup

Initial setup

  1. Install DDEV (if not already installed): https://ddev.readthedocs.io/en/stable/users/install/ddev-installation/
  2. Ensure that you have a ssh key setup with Drupal.
  3. Install joachim-n/drupal-core-development-project:
composer create-project -n joachim-n/drupal-core-development-project drupal-core-dev && cd drupal-core-dev
  1. Add DDEV to the project:
@alangrainger
alangrainger / Copy direct link to Gmail email.md
Last active April 7, 2024 11:17
Copy a direct link to a Gmail email to your clipboard
@crittermike
crittermike / MODULENAME.module.php
Last active October 23, 2020 17:43
Add a query_args cache context to the header block so that the cache is dependent on query string.
<?php
function MODULENAME_block_build_alter(array &$build, \Drupal\Core\Block\BlockPluginInterface $block) {
// Add the 'query args' cache context to the header block.
if ($this_block_is_the_header_block) { // @TODO: Make this line work.
$build['#cache']['contexts'][] = 'url.query_args';
}
}

users.csv

user_id,email,name,member_number
1,some@emailaddress.com,some user name,123456789

migrate_plus.migration.users.yml

langcode: en
status: true
@sahava
sahava / dataLayerHistory.js
Last active March 13, 2024 12:26
JavaScript for persisting dataLayer array and data model composition across pages
(function() {
// Set the timeout for when the dataLayer history should be purged. The default is 30 minutes.
// The timeout needs to be in milliseconds.
var timeout = 30*60*1000;
// Change dataLayerName only if you've defined another named for the dataLayer array in your
// GTM container snippet.
var dataLayerName = 'dataLayer';
// Don't change anything below.
@jleehr
jleehr / gist:7ac2a5de785881dfce99f7034547f07b
Last active May 25, 2023 11:02
Drupal 8 - Migrate from public to private files
# Enable maintanance mode
drush state-set system.maintenance_mode 1
# Backup file field data
drush sql-query "CREATE TABLE media__field_file_bak AS SELECT * FROM media__field_file;"
drush sql-query "CREATE TABLE media_revision__field_file_bak AS SELECT * FROM media_revision__field_file;"
# Truncate file field tables (need to change storage settings)
drush sql-query "TRUNCATE media__field_file;"
drush sql-query "TRUNCATE media_revision__field_file;"
@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');
@frjo
frjo / contact.php
Last active January 20, 2023 07:22
PHP script for contact form
<?php
// Set the e-mail address that submission should be sent to.
$address = 'info@example.com';
// Set the e-mail subject prefix.
$prefix = 'Website feedback';
// DO NOT EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING.
@andrewstuart
andrewstuart / .gitlab-ci.yml
Last active June 12, 2023 17:44
One Deployment Per branch, plus CI CD, gitlab and helm setup
image: docker.mydomain.com/build/kube-go-make
variables:
DOCKER_TAG: docker.mydomain.com/myapp/home:$CI_COMMIT_REF_SLUG
DOCKER_HOST: tcp://localhost:2375
DOCKER_DRIVER: overlay
PROD_RSYNC_HOST: myprodserver.com
DOMAIN: mydomain.com
CHART_DIR: chart
<?php
namespace Drupal\sitemanager\Plugin;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Config\ConfigFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;