Skip to content

Instantly share code, notes, and snippets.

View mecmartini's full-sized avatar

Marco Martino mecmartini

View GitHub Profile
@mecmartini
mecmartini / drupal-fix-module-has-an-entry-in-the-system-schema.php
Created December 10, 2020 18:00
Drupal: fix module has an entry in the system.schema
<?php
/**
* Removing traces of the test_marco_socialfood_workflow module after merging.
*/
function hook_update_N() {
$schema_store = \Drupal::keyValue('system.schema');
$schema_store->delete('module_name');
\Drupal::database()->delete('key_value')
@mecmartini
mecmartini / drupal-8-fix-url-absolute-for-http.md
Last active November 30, 2020 17:28
Drupal 8 - Fix url() absolute for https

In settings.php enable:

$settings['reverse_proxy'] = TRUE;
$settings['reverse_proxy_addresses'] = array($_SERVER['REMOTE_ADDR']);

In .htaccess write in mod_headers.c:

@mecmartini
mecmartini / drupal-8-disable-page-for-content-type.php
Last active April 20, 2022 21:39
Drupal 8 - Disable page for content type
<?php
use Drupal\node\NodeInterface;
/**
* Implements hook_ENTITY_TYPE_view().
*/
function mymodule_node_view(array &$build, NodeInterface $node, $display, $view_mode) {
if ($node->getType() === 'post') {
$build['#cache']['max-age'] = 0;
@mecmartini
mecmartini / jupyter-generate-password.py
Created November 24, 2020 13:33
jupyter generate password
from notebook.auth import passwd
passwd(passphrase='mynewpassword', algorithm='sha1')
@mecmartini
mecmartini / drupal-entity-query-or-and-reference.php
Created November 5, 2020 15:24
Drupal 8 entity query with or condition and entity reference field
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
$orGroup = \Drupal::entityQuery('node')->orConditionGroup()
->condition('type', 'page');
->condition('type', 'article')
->condition('type', 'landing');
$result = \Drupal::entityQuery('node')
->status(1)
->condition($orGroup)
@mecmartini
mecmartini / render-reponsive-image-style-twig-drupal.html-twig
Created December 13, 2019 17:18
How to render responsive image style on Twig in Drupal
{% set imagePath = 'public://images/default.jpg' %}
{% set responsiveimagestyle = {
'#theme': 'responsive_image',
'#responsive_image_style_id': 'my_responsive_image_style_id',
'#uri': imagePath,
'#alt': 'my alt text',
'#attributes': { class: 'img-responsive' },
} %}
{{ responsiveimagestyle }}
@mecmartini
mecmartini / .docker_aliases
Last active November 9, 2021 13:59
My docker aliases
#!/bin/sh
# Start/Stop
alias dcup='docker-compose up -d'
alias dcst='docker-compose stop'
# Traefik
alias dcup-traefik='docker-compose -f traefik.yml up -d'
alias dcst-traefik='docker-compose -f traefik.yml stop'
@mecmartini
mecmartini / languages_dropdown_remove_css_dependency.patch
Created August 27, 2019 12:10
Drupal contrib module Languages Dropdown - Remove Css Dependency
diff --git a/languages_dropdown.module b/languages_dropdown.module
index 1df935d..b31d212 100644
--- a/languages_dropdown.module
+++ b/languages_dropdown.module
@@ -71,10 +71,6 @@ function languages_dropdown_page_attachments(&$attachments) {
$attachments['#attached']['library'][] =
'languages_dropdown/dependency-js';
}
- else {
- $attachments['#attached']['library'][] =
@mecmartini
mecmartini / docker4andrex.sh
Created August 20, 2019 13:16
docker4andrex
# Move to main Docker folder.
cd docker4andrex/
# Start proxy server.
docker-compose -f traefik.yml up -d
# Start docker sync.
docker-sync start
# Move to project folder (i.e. uricchio/).
@mecmartini
mecmartini / vmware_fusion_mac_could_not_open_dev_mmon.sh
Last active August 9, 2019 12:36
vmware could not open /dev/mmon
sudo kextunload -b com.intel.kext.intelhaxm