You are here

class VLMAppendCommand in Views Load More 2.x

Same name and namespace in other branches
  1. 8 src/Ajax/VLMAppendCommand.php \Drupal\views_load_more\Ajax\VLMAppendCommand

Provides an AJAX command for appending new rows in a paged AJAX response to the rows on the page.

This command is implemented in Drupal.AjaxCommands.prototype.viewsLoadMoreAppend.

Hierarchy

Expanded class hierarchy of VLMAppendCommand

1 file declares its use of VLMAppendCommand
VLMEventSubscriber.php in src/EventSubscriber/VLMEventSubscriber.php

File

src/Ajax/VLMAppendCommand.php, line 17

Namespace

Drupal\views_load_more\Ajax
View source
class VLMAppendCommand implements CommandInterface, CommandWithAttachedAssetsInterface {
  use CommandWithAttachedAssetsTrait;

  /**
   * The options for the command.
   *
   * @var array
   */
  protected $options;

  /**
   * The content to append.
   *
   * Either a render array or an HTML string.
   *
   * @var string|array
   */
  protected $content;

  /**
   * Constructs a \Drupal\views\Ajax\ScrollTopCommand object.
   * @todo document
   *
   * @param $content
   * @param array $options
   *   Array with the following keys:
   *   - method
   *   - wrapper_selector
   *   - content_selector
   *   - pager_selector
   *   - effect
   *   - speed
   *   - target_list
   */
  public function __construct($content, $options) {
    $this->content = $content;
    $defaults = array(
      'method' => 'append',
      'wrapper_selector' => NULL,
      'content_selector' => LoadMore::DEFAULT_CONTENT_SELECTOR,
      'pager_selector' => LoadMore::DEFAULT_PAGER_SELECTOR,
      'effect' => '',
      'speed' => '',
      'target_list' => '',
    );
    $this->options = array_merge($defaults, $options);
  }

  /**
   * Implements \Drupal\Core\Ajax\CommandInterface::render().
   */
  public function render() {
    return array(
      'command' => 'viewsLoadMoreAppend',
      'data' => $this
        ->getRenderedContent(),
      'options' => $this->options,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommandWithAttachedAssetsTrait::$attachedAssets protected property The attached assets for this Ajax command.
CommandWithAttachedAssetsTrait::getAttachedAssets public function Gets the attached assets.
CommandWithAttachedAssetsTrait::getRenderedContent protected function Processes the content for output.
VLMAppendCommand::$content protected property The content to append.
VLMAppendCommand::$options protected property The options for the command.
VLMAppendCommand::render public function Implements \Drupal\Core\Ajax\CommandInterface::render(). Overrides CommandInterface::render
VLMAppendCommand::__construct public function Constructs a \Drupal\views\Ajax\ScrollTopCommand object. @todo document