Skip to content

Instantly share code, notes, and snippets.

View heitoralthmann's full-sized avatar

Heitor Althmann heitoralthmann

  • Interactive Strategies
  • Paranavaí, PR, Brazil
View GitHub Profile
@keopx
keopx / import.php
Last active September 20, 2023 12:47 — forked from crittermike/import.php
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');
@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-&gt;getSource()-&gt;getSourceFieldValue($media_entity);
@cecilemuller
cecilemuller / 2019-https-localhost.md
Last active May 2, 2024 16:43
How to create an HTTPS certificate for localhost domains

How to create an HTTPS certificate for localhost domains

This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.

Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).

@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');
@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

@brooke-heaton
brooke-heaton / Drupal8_views_query_alter.php
Created August 11, 2017 22:13
Alters a Drupal 8 view by adding a Left Join and Where condition
<?php
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;
/**
* Implementation of hook_views_query_alter
* @param type $view
* @param type $query
@MatthieuScarset
MatthieuScarset / gist:47b57f2e3bd4afee39a81ae5a7c3dc28
Created December 27, 2016 14:14
Drupal 8 - Get canonical node URL in TWIG
{{ path('entity.node.canonical', {'node': node.id }) }}
@JeffTomlinson
JeffTomlinson / MyService.php
Last active December 22, 2021 07:49
Drupal 8 Logger Dependency Injection
<?php
namespace Drupal\my_module\Services;
use Drupal\Core\Logger\LoggerChannelFactory;
/**
* Class MyService.
*
* @package Drupal\my_module\Services
@jeromedalbert
jeromedalbert / gist:7476f445b7538b488c6ec34b5c4f3da4
Created May 28, 2016 19:08
Installing the Docker Toolbox on OS X with brew
brew cask install dockertoolbox
docker-machine create --driver virtualbox default
docker-machine ls
eval $(docker-machine env default)
Put the exports in this eval in your .zshrc or .bashrc if you use bash
@petemcw
petemcw / 01-README.md
Last active February 2, 2024 11:50
Mac OS X LEMP Configuration

Mac OS X LEMP Configuration

This Gist is a collection of configuration files that can be used to easily setup a Homebrew-based LEMP stack on Mac OS X.

Files in this repository are numbered and named for ordering purposes only. At the top of each file is a section of metadata that denote what component the file belongs to and the default name & location of the file. Feel free to implement it however you want.

Note: some configuration files have hard-coded paths to my user directory -- fix it for your setup

Setup