Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AddCssCommand.php

class AddCssCommand

An AJAX command for adding css to the page via ajax.

This command is implemented by Drupal.AjaxCommands.prototype.add_css() defined in misc/ajax.js.

Hierarchy

  • class \Drupal\Core\Ajax\AddCssCommand implements \Drupal\Core\Ajax\CommandInterface

Expanded class hierarchy of AddCssCommand

See also

misc/ajax.js

Related topics

Ajax API
Overview for Drupal's Ajax API.

File

core/lib/Drupal/Core/Ajax/AddCssCommand.php, line 15

Namespace

Drupal\Core\Ajax
View source
class AddCssCommand implements CommandInterface {
    
    /**
     * Arrays containing attributes of the stylesheets to be added to the page.
     *
     * @var string[][]
     */
    protected $styles;
    
    /**
     * Constructs an AddCssCommand.
     *
     * @param string[][] $styles
     *   Arrays containing attributes of the stylesheets to be added to the page.
     *   i.e. `['href' => 'someURL']` becomes `<link href="someURL">`.
     */
    public function __construct(array $styles) {
        $this->styles = $styles;
    }
    
    /**
     * {@inheritdoc}
     */
    public function render() {
        return [
            'command' => 'add_css',
            'data' => $this->styles,
        ];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AddCssCommand::$styles protected property Arrays containing attributes of the stylesheets to be added to the page.
AddCssCommand::render public function Return an array to be run through json_encode and sent to the client. Overrides CommandInterface::render
AddCssCommand::__construct public function Constructs an AddCssCommand.
RSS feed
Powered by Drupal