You are here

class FireJavascriptCommand in Maestro 8.2

Same name and namespace in other branches
  1. 3.x modules/maestro_template_builder/src/Ajax/FireJavascriptCommand.php \Drupal\maestro_template_builder\Ajax\FireJavascriptCommand

An AJAX command for calling our own javascript functions/methods.

Hierarchy

Expanded class hierarchy of FireJavascriptCommand

5 files declare their use of FireJavascriptCommand
MaestroTemplateBuilderAddNew.php in modules/maestro_template_builder/src/Form/MaestroTemplateBuilderAddNew.php
MaestroTemplateBuilderCanvas.php in modules/maestro_template_builder/src/Form/MaestroTemplateBuilderCanvas.php
MaestroTemplateBuilderEditTask.php in modules/maestro_template_builder/src/Form/MaestroTemplateBuilderEditTask.php
MaestroTemplateBuilderForm.php in modules/maestro_template_builder/src/Form/MaestroTemplateBuilderForm.php
MaestroValidityCheck.php in modules/maestro_template_builder/src/Form/MaestroValidityCheck.php

File

modules/maestro_template_builder/src/Ajax/FireJavascriptCommand.php, line 12

Namespace

Drupal\maestro_template_builder\Ajax
View source
class FireJavascriptCommand implements CommandInterface {

  /**
   * The Function to call in our maestro template.  Please see
   * template-display.js and find the declaration for
   * Drupal.AjaxCommands.prototype.addNewTask as an example of a javascript callback.
   *
   * @var string
   */
  protected $function;

  /**
   * Keyed array of the values we want to pass back.
   * We cycle through these values and create the final return structure.
   *
   * @var array
   */
  protected $values;

  /**
   * Constructs a our FireMaestroCommand.
   *
   * @param string $function
   *   The javascript function you wish to call.
   * @param array $values
   *   Keyed array of values you wish to pass back to the javascript function being called.
   */
  public function __construct($function, array $values) {
    $this->function = $function;
    $this->values = $values;
  }

  /**
   * Implements Drupal\Core\Ajax\CommandInterface:render().
   */
  public function render() {
    $ret = [];
    $ret['command'] = $this->function;
    foreach ($this->values as $key => $val) {
      $ret[$key] = $val;
    }
    return $ret;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FireJavascriptCommand::$function protected property The Function to call in our maestro template. Please see template-display.js and find the declaration for Drupal.AjaxCommands.prototype.addNewTask as an example of a javascript callback.
FireJavascriptCommand::$values protected property Keyed array of the values we want to pass back. We cycle through these values and create the final return structure.
FireJavascriptCommand::render public function Implements Drupal\Core\Ajax\CommandInterface:render(). Overrides CommandInterface::render
FireJavascriptCommand::__construct public function Constructs a our FireMaestroCommand.