Drupal Dump

Drupal Snippets, Hacks and more....

Drupal 8 commerce (2.x) - multi currency how to

For multi-currency in drupal 7 commerce we had it all running out of the box with drupal multicurrency modul. You had price fields per currency and rules that would solve that. There is no out of the box solution like that yet, but this module is pretty close to it.

Configure git to ignore some files locally without .gitignore file

Some times you dont want to add something to .gitignore, while it would be nice that there is some .gitignore-local version by default, there is not, so you need to find a different way to do this, the way to do is this.  Go to .git/info/exclude file and edit it like regular .gitignore file, add files/folders you want to ignore.

Xdebug and docker4drupal on mac

To have xdebug working, you need to have this in your docker config for PHP.

      PHP_XDEBUG: 1
      PHP_XDEBUG_DEFAULT_ENABLE: 1
      PHP_XDEBUG_REMOTE_CONNECT_BACK: 0
      PHP_XDEBUG_REMOTE_HOST: 10.254.254.254 # macOS, Docker < 18.03

Also it is often noted that this should also be run

Making url with anchor(fragment) and making url with query string appended

$options = ['fragment' => 'feedback'];
$url = Url::fromRoute('entity.node.canonical', ['node' => 22], $options);

$options = ['query' => ['animal' => 'dog', 'color' => 'black']];
$url = Url::fromRoute('entity.node.canonical', ['node' => 42], $options);

So first would give you  this result 

Some ways to make links in drupal 8

// Link to an internal path defined by a route.
$link = Link::createFromRoute('This is some link', 'entity.node.canonical', ['node' => 22])

// Link to an external URI.
$link = Link::fromTextAndUrl('This is a link', Url::fromUri('https://example.com'));

// Get output as a render array.
$link->toRenderable();

// Get output as a string.

How to create URL's from internal route or external URI

// From a route.
$url = Url::fromRoute('contact.site_page');
// From a URI.
$url = Url::fromUri('https://example.com');
// From route with additional parameters.
$url = Url::fromRoute('entity.node.canonical', ['node' => 22]);