Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
novicell/custom_forms / src / Ajax / CustomFormsErrorCommand.php
Size: Mime:
<?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]
    ];
  }
}