Skip to content

Instantly share code, notes, and snippets.

@fazni
Forked from webflo/url.php
Created March 19, 2018 13:06
Show Gist options
  • Save fazni/c19908586906f856c9bb8eb8f7b59691 to your computer and use it in GitHub Desktop.
Save fazni/c19908586906f856c9bb8eb8f7b59691 to your computer and use it in GitHub Desktop.
Create link with attributes in Drupal 8
<?php
$url = Url::fromRoute('node.add', array('node_type' => $content_type));
$url->setOption('query', \Drupal::destination()->getAsArray(),);
$link = [
'#type' => 'link',
'#title' => t('Add !content_type content', array('!content_type' => $content_type)),
'#url' => $url,
'#attributes' => [
'class' => ['button', 'button-action', 'button--primary', 'button--small'],
]
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment