You are here

function template_preprocess_link_formatter_button_link in Button Link Formatter 8

Prepares variables for button link field templates.

This template outputs a separate title and link.

Default template: link-formatter-button-link.html.twig.

Parameters

array $variables: An associative array containing:

  • title: (optional) A descriptive or alternate title for the link, which may be different than the actual link text.
  • url_title: The anchor text for the link.
  • url: A \Drupal\Core\Url object.

File

./button_link.module, line 44
Defines simple link field types.

Code

function template_preprocess_link_formatter_button_link(&$variables) {
  $url = $variables['url'];
  $attributes = $url
    ->getOption('attributes');
  if (isset($variables['disable_btn_role']) && !$variables['disable_btn_role']) {
    $attributes['role'] = 'button';
  }
  $attributes['class'][] = 'btn';
  $attributes['class'][] = $variables['type'];
  $attributes['class'][] = $variables['size'];
  $attributes['class'][] = $variables['block'];
  $attributes['href'] = $url
    ->toString();
  $url
    ->setOption('attributes', $attributes);
  $variables['link'] = Link::fromTextAndUrl($variables['title'], $url)
    ->toString();
  $variables['attributes'] = new Attribute($attributes);
  $icon_attributes['class'][] = $variables['icon_class'];
  $variables['icon_attributes'] = new Attribute($icon_attributes);
}