You are here

public static function AjaxLinksApiSettingsForm::ajaxLinksApiGetTriggers in Ajaxify Drupal with JQuery Ajax 8

Get trigger classes/ids.

Ajax links triggers now come in two varieties:

positive triggers: these are selectors that are used to select a set of links negative triggers: these are selectors used in .not() to remove links from the set of matched ones

The user can specify these in the admin/config screen. Negative triggers are those listed with a "!" as the first character.

1 call to AjaxLinksApiSettingsForm::ajaxLinksApiGetTriggers()
ajax_links_api_page_attachments in ./ajax_links_api.module
Implements hook_page_attachments().

File

src/Form/AjaxLinksApiSettingsForm.php, line 94

Class

AjaxLinksApiSettingsForm
Displays the Ajax links API settings form.

Namespace

Drupal\ajax_links_api\Form

Code

public static function ajaxLinksApiGetTriggers() {
  $config = \Drupal::config('ajax_links_api.admin_settings');
  $trigger = $config
    ->get('ajax_links_api.trigger');
  $trigger = explode("\n", $trigger);

  // Trim all entries.
  $trigger = array_map('trim', $trigger);

  // Filter out empty lines.
  $trigger = array_filter($trigger);
  $positive_triggers = array();
  $negative_triggers = array();
  foreach ($trigger as $this_trigger) {
    if (preg_match('/^!/', $this_trigger)) {
      $negative_triggers[] = substr($this_trigger, 1);
    }
    else {
      $positive_triggers[] = $this_trigger;
    }
  }
  $positive_trigger = implode(',', $positive_triggers);
  $negative_trigger = implode(',', $negative_triggers);
  return array(
    $positive_trigger,
    $negative_trigger,
  );
}