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 / ExampleModuleController.php
Created July 2, 2019 09:50 — forked from crittermike/ExampleModuleController.php
Example of overriding a route controller in Drupal 8
<?php
/**
* @file
* Contains \Drupal\example_module\Controller\ExampleModuleController.
*/
// THIS FILE BELONGS AT /example_module/src/Controller/ExampleModuleController.php
namespace Drupal\example_module\Controller;
@achraf-jeday
achraf-jeday / mysql-docker.sh
Last active September 4, 2019 07:59 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
# Added current date and time to generated file name.
docker exec preprod_safefood_vitrine_mariadb /usr/bin/mysqldump -u safefood_vitrine --password=safefood_vitrine123 drupal > $(date +"%Y_%m_%d_%I_%M_%p").sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@achraf-jeday
achraf-jeday / module.php
Created April 6, 2020 05:56 — forked from modcab/module.php
Drupal 8 - Get MIME type from file uri.
<?php
$mime = \Drupal::service('file.mime_type.guesser')->guess($uri);
@achraf-jeday
achraf-jeday / delete_content_entities.d8.php
Created April 7, 2020 15:38 — forked from Jaesin/delete_content_entities.d8.php
Delete all content entities in Drupal 8.
<?php
// Delete all nodes.
entity_delete_multiple('node', \Drupal::entityQuery('node')->execute());
// Delete all files.
entity_delete_multiple('file', \Drupal::entityQuery('file')->execute());
// Delete all taxonomy terms.
entity_delete_multiple('taxonomy_term', \Drupal::entityQuery('taxonomy_term')->execute());
get current user in drupal 8
Description: In drupal 7 we get the current user object by defining global $user but in drupal 8 this quite different. If you want to get current user object then follow below code.
$current_user = \Drupal::currentUser();
$uid = $current_user->id();
It returns user id of current user.
$user_mail = $current_user->getEmail();
It returns user email id.