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 / 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 / MigrateOPMCommands.php
Created April 21, 2020 07:02
Progress bar Example: drush command drupal 8
<?php
namespace Drupal\migrate_opm\Commands;
use Drush\Commands\DrushCommands;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* A Drush commandfile.
@achraf-jeday
achraf-jeday / bash.sh
Created January 19, 2022 00:13
Curl inside loop
set -B # enable brace expansion
for i in {1..200}; do
echo "Hello Hey $i"
curl --location --request POST 'http://dev.passwordlocker.loc/api/json/password' \
--header 'Accept: application/vnd.api+json' \
--header 'Content-type: application/vnd.api+json' \
--header 'X-CSRF-Token: Kbl6ZFLWvrPOtyD6EmULWcRsOMk3CH4WmSrLgPGExzU' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImMzNzhlYmEyNmU1NjcwYjYzMjM2YmE5NjljN2E5NzEyZTBmMGVlMzRlOGYwNzI0MmI5YzkzNGFiNmU1NjNhNWUyYzQ4ODYwNjkzNmUwNzg5In0.eyJhdWQiOiIwNzgwYWVkYy1jZWZhLTQ2MDMtODFiZi1hOWZkMzVjZDcwMmQiLCJqdGkiOiJjMzc4ZWJhMjZlNTY3MGI2MzIzNmJhOTY5YzdhOTcxMmUwZjBlZTM0ZThmMDcyNDJiOWM5MzRhYjZlNTYzYTVlMmM0ODg2MDY5MzZlMDc4OSIsImlhdCI6MTY0MjU1MDIwOSwibmJmIjoxNjQyNTUwMjA5LCJleHAiOjE2NDU1NTAyMDguOTU2ODI1LCJzdWIiOiIyIiwic2NvcGUiOlsiY3VzdG9tZXIiLCJhdXRoZW50aWNhdGVkIl19.qWaPozwNbJZyYHjVMbnrN7vB6PDgij5oLe6NmjYOpeZz6a1TwzMYXqtSbbDQuhBuNaihEaF4Xn4fJLzGgnhVled8ZgQrDBL72DknIuVkPMjaBkoMn5A05RaSmY-DreYVDUeKN_JOveQxDWHbBj98uY7pj0mmvm2T
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.
@achraf-jeday
achraf-jeday / nginx.conf
Last active December 3, 2021 22:40
Nginx configuration for Drupal 9 without ssl (only http)
server {
listen 80;
listen [::]:80;
server_name dev.passwordlocker.loc;
index index.php index.html index.htm;
root /var/www/html/web;
@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 / git-rebase.txt
Last active December 9, 2020 14:05
Git: git rebase and git -D
10225 gco develop
10226 git fetch --all
10227 git pull
10228 git branch -D feature/DevOps-Refonte-du-docker
10229 git fetch --all
10230 gco feature/DevOps-Refonte-du-docker
10232 git branch
10234 git rebase origin/develop
10236 git add composer.lock
10238 git rebase --continue
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessage;
/**
* Implements hook_cron().
*/
function migrate_tools_cron() {
$manager = Drupal::service('plugin.manager.migration');
$migration_ids = ['drupal_planet_rss_importer'];
foreach ($migration_ids as $migration_id) {
id: drupal_planet_rss_importer
label: 'Import Drupal planet RSS feed'
status: true
source:
plugin: url
data_fetcher_plugin: http
urls: 'https://www.drupal.org/planet/rss.xml'
data_parser_plugin: simple_xml
@achraf-jeday
achraf-jeday / import.sh
Created June 16, 2020 08:44
Import local translation file in Drupal 8
drush locale-import file modules/custom/custom_opm/translations/custom_opm.fr.po