Repository URL to install this package:
|
Version:
2.0.2 ▾
|
<?php
namespace Drupal\custom_forms\Ajax;
use Drupal\Core\Ajax\CommandInterface;
/**
* Class CustomFormsErrorCommand
*
* Custom ajax command for adding and removing errors from custom forms.
*
* @package Drupal\custom_forms\Ajax
*/
class CustomFormsErrorCommand implements CommandInterface {
private $commands = ['addCustomFormsError' => 'addCustomFormsError', 'removeCustomFormsError' => 'removeCustomFormsError'];
protected $command;
/** @var string */
private $selector;
/** @var string */
private $message;
/**
* CustomFormsErrorCommand constructor.
*
* @param string $command
* The command to use, can be either 'addCustomFormsError' or 'removeCustomFormsError'.
* @param string $selector
* The field selector.
* @param string $message
* The error message to display.
*/
public function __construct($command, $selector, $message = '') {
$this->command = $command;
$this->selector = $selector;
$this->message = $message;
}
/**
* {@inheritdoc}
*/
public function render() {
return [
'selector' => $this->selector,
'message' => $this->message,
'command' => $this->commands[$this->command]
];
}
}