Below is a list of the various render array elements used to theme and display common HTML elements.
<?php
/**
* @file
* List of render array types.
*/
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Url;
/**
* Class RenderArrayTypes.
*/
class RenderArrayTypes {
use StringTranslationTrait;
/**
* Render types examples.
*/
public function types() {
// Link - basic.
$element['link_basic'] = array(
'#type' => 'link',
'#title' => array(
'#markup' => $this->t('Link text'),
),
'#url' => Url::fromUri('internal:/url'),
);
// Link - anchor
$element['link_anchor'] = array(
'#type' => 'link',
'#title' => array(
'#markup' => $this->t('Link text'),
),
'fragment' => 'fragment-text',
'absolute' => TRUE,
'#url' => Url::fromUri('internal:/url'),
);
// Button.
$element['button'] = array(
'#type' => 'button',
'#value' => $this->t('Close'),
);
/**
* Bootstrap related.
*/
// Link to open modal.
$element['link_modal'] = array(
'#type' => 'link',
'#title' => array(
'#markup' => 'Link text',
),
'#url' => Url::fromUri('internal:/', array(
'fragment' => 'fragment-text',
'attributes' => [
'class' => array('btn', 'btn-default'),
'data-toggle' => 'modal',
'data-target' => '#modal-id',
],
'absolute' => TRUE,
)),
);
// Bootstrap close button.
$element['close_button'] = array(
'#type' => 'button',
'#value' => $this->t('Close'),
'#attributes' => array(
'class' => array('btn', 'btn-default'),
'data-dismiss' => 'modal',
),
);
}
}