Skip to content

Instantly share code, notes, and snippets.

@steffenr
Last active March 24, 2016 10:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save steffenr/fc669ca3fdd10bb96bfb to your computer and use it in GitHub Desktop.
Save steffenr/fc669ca3fdd10bb96bfb to your computer and use it in GitHub Desktop.
Create link with attributes in Drupal 8
<?php
$link_url = Url::fromRoute('node.add', array('node_type' => $content_type));
$link_url->setOptions(array(
'attributes' => array(
'class' => array('button')
),
'query' => \Drupal::destination()->getAsArray(),
));
$link_text = t('Add !content_type content', array('!content_type' => ucfirst($content_type)));
// Build link
$link = \Drupal::l($link_text, $link_url);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment