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 / 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 / chmod Symbols
Last active August 29, 2019 09:06
chmod Symbols
7 rwx
6 rw-
5 r-x
4 r--
3 -wx
2 -w-
1 --x
0 ---
@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 / UserTokenService.php
Created June 28, 2019 10:09
Dependency injection of a service that is already in the container (Symfony 4)
<?php
namespace CoreBundle\Service;
use CoreBundle\Entity\User;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\AdapterInterface;
class UserTokenService
@achraf-jeday
achraf-jeday / FrontController.php
Last active June 25, 2019 15:54
Drupal 8 and GuzzleHttp 6: Basic HTTP authentication.
$credentials = base64_encode("admin:SuperSecret123");
$apiResponse = $this->client->get("{$this->container->getParameter('api')}jwt/token",
[
'verify' => false,
'headers' => [
'Authorization' => 'Basic ' . $credentials,
],
]);
@achraf-jeday
achraf-jeday / Curl.sh
Last active June 18, 2019 15:23
curl --insecure: For development purposes only you can pass the --insecure argument to curl, to skip cert check (self signed certificate).
curl --insecure -X POST -H "Content-Type: application/json" https://front.site-dev.fr:8002/api/login_check -d '{"username":"johndoe","password":"test"}'
@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);
@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 / 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 / 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 */