You are here

class AjaxLinksApiService in Ajaxify Drupal with JQuery Ajax 8

Ajax Links ApiService Class.

Hierarchy

Expanded class hierarchy of AjaxLinksApiService

1 string reference to 'AjaxLinksApiService'
ajax_links_api.services.yml in ./ajax_links_api.services.yml
ajax_links_api.services.yml
1 service uses AjaxLinksApiService
ajax_links_api.ajax_link in ./ajax_links_api.services.yml
Drupal\ajax_links_api\Plugin\AjaxLinksApiService

File

src/Plugin/AjaxLinksApiService.php, line 8

Namespace

Drupal\ajax_links_api\Plugin
View source
class AjaxLinksApiService {

  /**
   * Ajax links API.
   *
   * @param string $ajax_link_title
   *   Title to display.
   * @param string $ajax_link_path
   *   Drupal path eg: user/login.
   * @param string $ajax_link_target
   *   ID or CLASS of DIV to be replaced. eg: #content-content or #content.
   * @param array $ajax_link_options
   *   Array of link options eg: array(
   *    '#attributes' => 'class' => array(
   *      'ajax-links-api'
   *    ))
   *
   * @return string
   *   a link with class ajax_link and rel=$ajax_link_target.
   */
  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;
  }

}

Members