You are here

public function AjaxLinksApiService::lAjax in Ajaxify Drupal with JQuery Ajax 8

Ajax links API.

Parameters

string $ajax_link_title: Title to display.

string $ajax_link_path: Drupal path eg: user/login.

string $ajax_link_target: ID or CLASS of DIV to be replaced. eg: #content-content or #content.

array $ajax_link_options: Array of link options eg: array( '#attributes' => 'class' => array( 'ajax-links-api' ))

Return value

string a link with class ajax_link and rel=$ajax_link_target.

File

src/Plugin/AjaxLinksApiService.php, line 28

Class

AjaxLinksApiService
Ajax Links ApiService Class.

Namespace

Drupal\ajax_links_api\Plugin

Code

public function lAjax($ajax_link_title, $ajax_link_path, $ajax_link_target, $ajax_link_options = array()) {
  $url = \Drupal::service('path.validator')
    ->getUrlIfValid($ajax_link_path);
  $ajax_link_options['attributes']['class'][] = 'ajax-link';
  $ajax_link_options['attributes']['rel'] = $ajax_link_target;
  $url
    ->setOptions($ajax_link_options);
  $ajax_link = \Drupal::l($ajax_link_title, $url);
  return $ajax_link;
}