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
@yifanzz
yifanzz / code-editor-rules.md
Created December 17, 2024 00:01
EP12 - The One File to Rule Them All

[Project Name]

Every time you choose to apply a rule(s), explicitly state the rule(s) in the output. You can abbreviate the rule description to a single word or phrase.

Project Context

[Brief description ]

  • [more description]
  • [more description]
  • [more description]
@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);
@ruimaranhao
ruimaranhao / python-guide-ist.md
Last active April 10, 2025 03:02
A guide of best practices to developing in Python (meant for the first year students of the Instituto Superior Técnico, U.Lisboa).

A Guide of Best Practices for Python

A guide of best practices to developing in Python (meant for the first year students of the Instituto Superior Técnico, University of Lisbon). Do you want to have a hard-cover book on this, check this list out.

Inspired in Steve Sloria's gist.

In General

"Beautiful is better than ugly." - [PEP 20][]

@cecilemuller
cecilemuller / 2019-https-localhost.md
Last active April 15, 2025 14:53
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 February 5, 2025 19:23
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
@gwagroves
gwagroves / module.php
Last active October 9, 2024 18:14
Drupal 8 Paragraphs: Add a theme suggestion based on the paragraph and the type of the parent node / entity.
<?php
/**
* Implements theme_suggestions_HOOK_alter().
*/
function mytheme_theme_suggestions_paragraph_alter(array &$suggestions, array $variables) {
/** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
$paragraph = $variables['elements']['#paragraph'];
/** @var \Drupal\Core\Entity\ContentEntityInterface $parent */
$parent = $paragraph->getParentEntity();
@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 }) }}