function AddJsCommand::__construct

Same name in other branches
  1. 10 core/lib/Drupal/Core/Ajax/AddJsCommand.php \Drupal\Core\Ajax\AddJsCommand::__construct()
  2. 11.x core/lib/Drupal/Core/Ajax/AddJsCommand.php \Drupal\Core\Ajax\AddJsCommand::__construct()

Constructs an AddJsCommand.

Parameters

array $scripts: An array containing the attributes of the 'script' tags to be added to the page. i.e. `['src' => 'someURL', 'defer' => TRUE]` becomes `<script src="someURL" defer>`.

string $selector: A CSS selector of the element where the script tags will be appended.

File

core/lib/Drupal/Core/Ajax/AddJsCommand.php, line 45

Class

AddJsCommand
An AJAX command for adding JS to the page via AJAX.

Namespace

Drupal\Core\Ajax

Code

public function __construct(array $scripts, string $selector = 'body') {
    $this->scripts = $scripts;
    $this->selector = $selector;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.