SystemCompactLink::preRenderCompactLink

public static SystemCompactLink::preRenderCompactLink($element)

Pre-render callback: Renders a link into #markup.

Doing so during pre_render gives modules a chance to alter the link parts.

Parameters

array $element: A structured array whose keys form the arguments to Drupal::l():

  • #title: The link text to pass as argument to Drupal::l().
  • One of the following:
    • #route_name and (optionally) a #route_parameters array; The route name and route parameters which will be passed into the link generator.
    • #href: The system path or URL to pass as argument to Drupal::l().
  • #options: (optional) An array of options to pass to Drupal::l() or the link generator.

Return value

array The passed-in element containing the system compact link default values.

File

core/lib/Drupal/Core/Render/Element/SystemCompactLink.php, line 59

Class

SystemCompactLink
Provides a link to show or hide help text on administration pages.

Namespace

Drupal\Core\Render\Element

Code

public static function preRenderCompactLink($element) {
  // By default, link options to pass to l() are normally set in #options.
  $element += array('#options' => array());

  if (system_admin_compact_mode()) {
    $element['#title'] = t('Show descriptions');
    $element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', array('mode' => 'off'));
    $element['#options'] = array(
      'attributes' => array('title' => t('Expand layout to include descriptions.')),
      'query' => \Drupal::destination()->getAsArray()
    );
  }
  else {
    $element['#title'] = t('Hide descriptions');
    $element['#url'] = BaseUrl::fromRoute('system.admin_compact_page', array('mode' => 'on'));
    $element['#options'] = array(
      'attributes' => array('title' => t('Compress layout by hiding descriptions.')),
      'query' => \Drupal::destination()->getAsArray(),
    );
  }

  $options = NestedArray::mergeDeep($element['#url']->getOptions(), $element['#options']);
  $element['#markup'] = \Drupal::l($element['#title'], $element['#url']->setOptions($options));

  return $element;
}
doc_Drupal
2016-10-29 09:45:40
Comments
Leave a Comment

Please login to continue.