Skip to content

Instantly share code, notes, and snippets.

View leymannx's full-sized avatar
✍️
git reset --soft HEAD~1

Norman Kämper-Leymann leymannx

✍️
git reset --soft HEAD~1
View GitHub Profile
@emilorol
emilorol / drupal-composer.js
Created October 11, 2024 21:29
Drupal composer installation helper. Pick version and path
#!/bin/bash
# Prompt for version if not provided as the first parameter
if [ -z "$1" ]; then
read -p "Enter the Drupal version you would like to install (e.g., 8, 9, 10, 11): " version
else
version=$1
fi
# Prompt for installation directory if not provided as the second parameter
@antmbraun
antmbraun / gist:3ae4f22c6ddd1de2b959284c0ec74e3f
Last active September 12, 2024 10:48
Get all instances of paragraphs in Drupal 8
$entity_storage = \Drupal::entityTypeManager()->getStorage('paragraph');
$query = \Drupal::entityQuery('paragraph')
->condition('type', "paragraph_type_machine_name")
->accessCheck(false);
$results = $query->execute();
$hosted_paragraphs_found = [];
@schnippy
schnippy / drupal8-media-entity-file-url.md
Last active April 24, 2024 19:13
Programmatically get file URL from a media entity entity reference field in Drupal 8

Programmatically get file URL from a media entity reference field in Drupal 8

I have a content type with a media (image) entity reference field (field_thumbnail_image) and I want to grab its file URL. For this, I need to load the media entity, isolate its source object using getSource, then load this source as a file entity so I can make a proper URL.

    // load the media entity from the media entity reference field
    $media_entity = Media::load($entity->field_thumbnail_image->target_id);

    // get the file source value for the media entity
 $source_value = $media_entity->getSource()->getSourceFieldValue($media_entity);
@ptmkenny
ptmkenny / README.md
Last active September 22, 2020 19:22
Hosting Drulma depenencies locally + minimizing CSS/JS

How to host all drulma dependencies locally + minimize the CSS/JS

The steps in this guide enabled me to avoid using any CDNs and shrink my bulma CSS to just 19 KB. It also shrinks BulmaJS from 100+ Kb to ~20 Kb with a custom fork of BulmaJS that only builds the navbar, file, and dropdown components.

First, we have to create a subtheme of drulma.

Next, we override the drulma libraries.

Add the following lines to mydrulmasubtheme.info.yml:

@mparker17
mparker17 / fix-d8-empty-install-profile.md
Last active July 26, 2023 04:36
Fixing a Drupal 8 site with an empty install profile

Fixing a Drupal 8 site with an empty install profile

You'll probably notice this because of a series of errors like the ones below on the status report at /admin/reports/status:

    Notice: Undefined index: name in system_requirements() (line 59 of core/modules/system/system.install).
    Notice: Undefined index: version in system_requirements() (line 61 of core/modules/system/system.install).

To fix this...

  1. Check settings.php and settings.local.php in the order they are parsed for lines that look like $settings['install_profile']
@crittermike
crittermike / disable_aggregation.md
Last active February 14, 2022 12:17
Disabling CSS/JS aggregation via Drush in Drupal 7 and Drupal 8

Drupal 7

drush vset preprocess_css 0 --yes
drush vset preprocess_js 0 --yes

Drupal 8

@MatthieuScarset
MatthieuScarset / drupal8_programatically_delete_content.php
Last active August 28, 2024 05:55
Programatically delete content in Drupal 8
// Enable Devel module and go to /devel/php
$nodes = \Drupal::entityQuery("node")
->condition('created', strtotime('-30 days'), '<=')
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage("node");
// $entities = $storage_handler->loadMultiple(); // Delete ALL nodes.
$entities = $storage_handler->loadMultiple($nodes);
$storage_handler->delete($entities);
@mortenson
mortenson / docker-drush
Last active January 7, 2020 11:53
Quick way to proxy Drush commands to your Docker container
#!/bin/bash
# Save this to a file named "drush" (not "drush.sh") and put it in the same
# directory as your docker-compose file. Replace "SERVICE" with your docker
# container's name.
# Now every time you run "drush" from this directory, it runs drush inside
# your container instead. Cool!
docker-compose exec SERVICE drush $@
@rachellawson
rachellawson / .circleci_config.yml
Created July 7, 2017 21:28
CircleCI for Drupal 8 and Behat
version: 2
jobs:
build:
docker:
- image: circleci/php:7.1-apache-browsers
working_directory: ~/working
steps:
- checkout
- run:
@crittermike
crittermike / import.php
Last active August 28, 2024 06:43
Importing Drupal 8 config programmatically
<?php
// Import arbitrary config from a variable.
// Assumes $data has the data you want to import for this config.
$config = \Drupal::service('config.factory')->getEditable('filter.format.basic_html');
$config->setData($data)->save();
// Or, re-import the default config for a module or profile, etc.
\Drupal::service('config.installer')->installDefaultConfig('module', 'my_custom_module');