Skip to content

Instantly share code, notes, and snippets.

@webflo
Forked from steffenr/url.php
Created November 25, 2015 15:08

Revisions

  1. webflo revised this gist Nov 25, 2015. 1 changed file with 13 additions and 9 deletions.
    22 changes: 13 additions & 9 deletions url.php
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,14 @@
    <?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);
    ?>

    $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'],
    ]
    ];

  2. SteffenR created this gist Nov 25, 2015.
    10 changes: 10 additions & 0 deletions url.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    <?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);
    ?>