Notes
Drupal 8 - Retrieve current node
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
$nid = $node->id();
}
To use different ssh key depending on the repository
git config core.sshCommand "ssh -o IdentitiesOnly=yes -i ~/.ssh/id_rsa -F /dev/null"
Git reset last commit without losing changes
git reset HEAD~1
Git autocorrect typos
git config --global help.autocorrect 1
Prepare git-checkout statements by using `awk` Linux
Having a status like this:
$ git status
modified: composer.json
modified: composer.lock
deleted: config/webform.webform.foo.yml
deleted: config/webform.webform.bar.yml
deleted: config/webform.webform.bazyml
modified: config/core.extension.yml
If I want to revert only `webform` changes by running something like,
$ git checkout config/webform.webform.*
It won't work because those are deleted files, then I can use `awk` to create `checkout` statements,
$ git status | grep webform | awk '{ print "git checkout " $2; }'
git checkout config/webform.webform.foo.yml
git checkout config/webform.webform.bar.yml
git checkout config/webform.webform.baz.yml
Then copy and paste once and enjoy your wonderful day!
EDIT:
As a heads-up from a friend of mine, if we include double quotes it will work, as below:
git checkout "config/webform.webform.*"
Updated 3 paths from the index
PD:
Ha! An extra trick, if you include `| xargs -0 bash -c ` at the end, it will get execute it right away:
git status | grep webform | awk '{ print "git checkout " $2; }' | xargs -0 bash -c
Updated 1 path from the index
Updated 1 path from the index
Updated 1 path from the index
Drupal 8 - raw SQL queries for debugging
/** @var \Drupal\Core\Database\Query\SelectExtender $query */
echo $query->__toString();
var_dump($query->getArguments());
CSS - Typical Device Breakpoints
/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {
}
/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {
}
/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {
}
/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {
}
/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {
}
Valid URL from Link field into a Twig template
{# it will work either external or internal link #}
{{ node.field_image_link.get(0).getUrl().toString() }}
Drupal 8 - The following module is missing from the file system... hotfix
drush sql-query "DELETE FROM key_value WHERE collection='system.schema' AND name='module_name';"
Drupal 8 - Country name list by code
/** @var array $countries */
$countries = \Drupal::service('country_manager')
->getList();
// Transform TranslatableMarkup object into a string.
array_walk($countries, function (&$translation) {
/** @var Drupal\Core\StringTranslation\TranslatableMarkup $translation */
$translation = $translation->render();
});
var_dump($countries);
Drupal 8 ships with a service to easily retrieve all countries by code. Be sure to use dependency injection.