Exemple #1
0
 /**
  * Add an AJAX command to the response.
  *
  * @param \Drupal\Core\Ajax\CommandInterface $command
  *   An AJAX command object implementing CommandInterface.
  * @param boolean $prepend
  *   A boolean which determines whether the new command should be executed
  *   before previously added commands. Defaults to FALSE.
  *
  * @return AjaxResponse
  *   The current AjaxResponse.
  */
 public function addCommand(CommandInterface $command, $prepend = FALSE)
 {
     if ($prepend) {
         array_unshift($this->commands, $command->render());
     } else {
         $this->commands[] = $command->render();
     }
     return $this;
 }
Exemple #2
0
 /**
  * Add an AJAX command to the response.
  *
  * @param \Drupal\Core\Ajax\CommandInterface $command
  *   An AJAX command object implementing CommandInterface.
  * @param bool $prepend
  *   A boolean which determines whether the new command should be executed
  *   before previously added commands. Defaults to FALSE.
  *
  * @return AjaxResponse
  *   The current AjaxResponse.
  */
 public function addCommand(CommandInterface $command, $prepend = FALSE)
 {
     if ($prepend) {
         array_unshift($this->commands, $command->render());
     } else {
         $this->commands[] = $command->render();
     }
     if ($command instanceof CommandWithAttachedAssetsInterface) {
         $assets = $command->getAttachedAssets();
         $attachments = ['library' => $assets->getLibraries(), 'drupalSettings' => $assets->getSettings()];
         $attachments = $this->getRenderer()->mergeAttachments($this->attachments, $attachments);
         $this->setAttachments($attachments);
     }
     return $this;
 }