Drupal 9 - Forward a request within Symfony

Prob. there are better ways or alternatives, but the next way works for me!

A route definition:

  path: '/something/else'
    uri: '/valid_uri'
    _controller: '\Drupal\keboca\Controller\KController::forward'

The trick happens here:


namespace Drupal\keboca\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;

 * Returns responses for KEBOCA routes.
class KController extends ControllerBase {

   * Forwards the request to a valid URI.
   * @param string $uri
   * @return \Symfony\Component\HttpFoundation\Response
   * @throws \Exception
  public function forward(string $uri) {
    // Init a sub request based on the current request.
    $request = \Drupal::request();
    $subRequest = Request::create($uri,

    /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel */
    $httpKernel = \Drupal::service('http_kernel');
    return $httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);



Git "back" helper
gitback() {
 BRANCH_NAME=${1:-$(git branch --show-current)}

 git checkout  dev &&
 git pull origin dev &&
 git remote prune origin &&
 git branch -D "$BRANCH_NAME" &&
 git remote show origin &&
 git status

alias git-back='gitback'


Solr index delete all documents


Calculate Aspect Ratio

function findAspectRatio(int $width, int $height) {
  // search for greatest common divisor
  $greatestCommonDivisor = static function ($width, $height) use (&$greatestCommonDivisor) {
    return ($width % $height) ? $greatestCommonDivisor($height, $width % $height) : $height;

  $divisor = $greatestCommonDivisor($width, $height);

  return $width / $divisor . ':' . $height / $divisor;


Drupal behaviors - jQuery Once
(function ($, Drupal, drupalSettings) {
   'use strict';  
   Drupal.behaviors.my_behavior =  {
    attach: function (context, settings) {
      $(document, context).once('my_behavior').each( function() {
} (jQuery, Drupal, drupalSettings));


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/
deleted:    config/
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/
git checkout config/
git checkout config/webform.webform.baz.yml

Then copy and paste once and enjoy your wonderful day!


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


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