Skip to content

Instantly share code, notes, and snippets.

@webflo
Forked from steffenr/url.php
Created November 25, 2015 15:08
Show Gist options
  • Save webflo/0c855cb0e234d7d60672 to your computer and use it in GitHub Desktop.
Save webflo/0c855cb0e234d7d60672 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' => 'button button-action button--primary button--small'),
'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