Skip to content

Instantly share code, notes, and snippets.

View achraf-jeday's full-sized avatar
🏠
Working from home

Achraf Jeday achraf-jeday

🏠
Working from home
View GitHub Profile
@achraf-jeday
achraf-jeday / drupal8-links.php
Created August 1, 2017 09:06 — forked from colorfield/drupal8-links.php
Drupal 8 links, or where is my l() function
@achraf-jeday
achraf-jeday / gist:3dce48d6462949f38d8f7207b08b050d
Created August 21, 2017 11:06 — forked from imcmahon/gist:4335d05967f54bb6d14e
jQuery remove all classes with the same prefix
$('html').removeClass(function (index, css) {
return (css.match (/\bpage-\S+/g) || []).join(' '); // removes anything that starts with "page-"
});
@achraf-jeday
achraf-jeday / gist:7a9084ee248c51e834e043bf1c320868
Created October 11, 2017 10:26 — forked from paulallies/gist:0052fab554b14bbfa3ef
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@achraf-jeday
achraf-jeday / chosen-bootstrap.css
Created January 9, 2018 17:06 — forked from koenpunt/chosen-bootstrap.css
Bootstrap 3.0 theme for Chosen
select.form-control + .chosen-container.chosen-container-single .chosen-single {
display: block;
width: 100%;
height: 34px;
padding: 6px 12px;
font-size: 14px;
line-height: 1.428571429;
color: #555;
vertical-align: middle;
background-color: #fff;
@achraf-jeday
achraf-jeday / load_node_translations.php
Last active May 11, 2021 12:56
Drupal 8: How to load available translations of a given node, change some fields and save.
<?php
// Credit to Gábor Hojtsy
// http://hojtsy.hu/blog/2015-nov-11/drupal-8-multilingual-tidbits-19-content-translation-development
use Drupal\node\Entity\Node;
// Load node 4. In terms of language, this will get us an entity
// in the original submission language.
$node = Node::load(4);
@achraf-jeday
achraf-jeday / Docker most used commands and drush for drupal 8
Last active June 21, 2022 14:07
Docker and drush most used commands (drupal 8)
List all containers (only IDs):
docker ps -aq
Stop all running containers:
docker stop $(docker ps -aq)
Or this one:
docker-compose down --remove-orphans
Or this one:
@achraf-jeday
achraf-jeday / CSS - Position Text Over an Image
Created November 16, 2018 14:22
How to position text over an image
<div class="container">
<img src="img_snow_wide.jpg" alt="Snow" style="width:100%;">
<div class="bottom-left">Bottom Left</div>
<div class="top-left">Top Left</div>
<div class="top-right">Top Right</div>
<div class="bottom-right">Bottom Right</div>
<div class="centered">Centered</div>
</div>
/* Bottom left text */
@achraf-jeday
achraf-jeday / TWIG_Add_classes_to_attributes_array.txt
Created November 29, 2018 14:53
TWIG Add classes to attributes array
attributes.addClass()
Adds classes or merges them on to array of existing CSS classes.
Single class:
<div{{ attributes.addClass('my-class') }}></div>
Multiple classes:
{%
set classes = [
'red',
'green',
@achraf-jeday
achraf-jeday / hook_update_N.txt
Last active November 21, 2019 10:54
Drupal 8: To run a mymodule_update_8004() multiple times in development enivrements use these queries:
SELECT * FROM key_value WHERE collection="system.schema";
UPDATE key_value SET value='s:4:"8003";' WHERE collection="system.schema" AND name="mymodule";
How to "revert" a custom module's update 'N value'
D7 only: If you need to execute an update hook another time when testing it locally you can "revert" a custom module's update 'N value' with:
UPDATE system SET schema_version = [last_successful_update_ID] WHERE name = '[name_of_module]';
Replace the square brackets plus its content. See https://drupal.stackexchange.com/a/69841/19480.
Examples:
@achraf-jeday
achraf-jeday / my_module.install
Last active March 2, 2020 14:15
Drupal 8: Log error messages programmatically in a custom module.
// Logs a notice
\Drupal::logger('my_module')->notice($message);
// Logs an error
\Drupal::logger('my_module')->error($message);
// Logs an info
\Drupal::logger('my_module')->info($message);