You are here

class TestYamlFormHandler in YAML Form 8

Form submission test handler.

Plugin annotation


@YamlFormHandler(
  id = "test",
  label = @Translation("Test"),
  category = @Translation("Testing"),
  description = @Translation("Tests form submission handler behaviors."),
  cardinality = \Drupal\yamlform\YamlFormHandlerInterface::CARDINALITY_SINGLE,
  results = \Drupal\yamlform\YamlFormHandlerInterface::RESULTS_IGNORED,
)

Hierarchy

Expanded class hierarchy of TestYamlFormHandler

File

tests/modules/yamlform_test/src/Plugin/YamlFormHandler/TestYamlFormHandler.php, line 22

Namespace

Drupal\yamlform_test\Plugin\YamlFormHandler
View source
class TestYamlFormHandler extends YamlFormHandlerBase {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'message' => 'One two one two this is just a test',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form['message'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Message'),
      '#default_value' => $this->configuration['message'],
      '#required' => TRUE,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    $this->configuration['message'] = $form_state
      ->getValue('message');
  }

  /**
   * {@inheritdoc}
   */
  public function alterElements(array &$elements, YamlFormInterface $yamlform) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function alterForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
    if ($value = $form_state
      ->getValue('element')) {
      $form_state
        ->setErrorByName('element', $this
        ->t('The element must be empty. You entered %value.', [
        '%value' => $value,
      ]));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function confirmForm(array &$form, FormStateInterface $form_state, YamlFormSubmissionInterface $yamlform_submission) {
    drupal_set_message($this->configuration['message'], 'status', TRUE);
    \Drupal::logger('yamlform.test')
      ->notice($this->configuration['message']);
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function preCreate(array $values) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function postCreate(YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function postLoad(YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function preDelete(YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function postDelete(YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function preSave(YamlFormSubmissionInterface $yamlform_submission) {
    $this
      ->displayMessage(__FUNCTION__);
  }

  /**
   * {@inheritdoc}
   */
  public function postSave(YamlFormSubmissionInterface $yamlform_submission, $update = TRUE) {
    $this
      ->displayMessage(__FUNCTION__, $update ? 'update' : 'insert');
  }

  /**
   * Display the invoked plugin method to end user.
   *
   * @param string $method_name
   *   The invoked method name.
   * @param string $context1
   *   Additional parameter passed to the invoked method name.
   */
  protected function displayMessage($method_name, $context1 = NULL) {
    if (PHP_SAPI != 'cli') {
      $t_args = [
        '@class_name' => get_class($this),
        '@method_name' => $method_name,
        '@context1' => $context1,
      ];
      drupal_set_message($this
        ->t('Invoked: @class_name:@method_name @context1', $t_args), 'status', TRUE);
      \Drupal::logger('yamlform.test')
        ->notice('Invoked: @class_name:@method_name @context1', $t_args);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
TestYamlFormHandler::alterElements public function Alter form submission form elements. Overrides YamlFormHandlerBase::alterElements
TestYamlFormHandler::alterForm public function Alter form submission form . Overrides YamlFormHandlerBase::alterForm
TestYamlFormHandler::buildConfigurationForm public function Form constructor. Overrides YamlFormHandlerBase::buildConfigurationForm
TestYamlFormHandler::confirmForm public function Confirm form submission form. Overrides YamlFormHandlerBase::confirmForm
TestYamlFormHandler::defaultConfiguration public function Gets default configuration for this plugin. Overrides YamlFormHandlerBase::defaultConfiguration
TestYamlFormHandler::displayMessage protected function Display the invoked plugin method to end user.
TestYamlFormHandler::postCreate public function Acts on a form submission after it is created. Overrides YamlFormHandlerBase::postCreate
TestYamlFormHandler::postDelete public function Acts on deleted a form submission before the delete hook is invoked. Overrides YamlFormHandlerBase::postDelete
TestYamlFormHandler::postLoad public function Acts on loaded form submission. Overrides YamlFormHandlerBase::postLoad
TestYamlFormHandler::postSave public function Acts on a saved form submission before the insert or update hook is invoked. Overrides YamlFormHandlerBase::postSave
TestYamlFormHandler::preCreate public function Changes the values of an entity before it is created. Overrides YamlFormHandlerBase::preCreate
TestYamlFormHandler::preDelete public function Acts on a form submission before they are deleted and before hooks are invoked. Overrides YamlFormHandlerBase::preDelete
TestYamlFormHandler::preSave public function Acts on a form submission before the presave hook is invoked. Overrides YamlFormHandlerBase::preSave
TestYamlFormHandler::submitConfigurationForm public function Form submission handler. Overrides YamlFormHandlerBase::submitConfigurationForm
TestYamlFormHandler::submitForm public function Submit form submission form. Overrides YamlFormHandlerBase::submitForm
TestYamlFormHandler::validateForm public function Validate form submission form . Overrides YamlFormHandlerBase::validateForm
YamlFormHandlerBase::$handler_id protected property The form handler ID.
YamlFormHandlerBase::$label protected property The form handler label.
YamlFormHandlerBase::$logger protected property A logger instance.
YamlFormHandlerBase::$status protected property The form handler status.
YamlFormHandlerBase::$weight protected property The weight of the form handler.
YamlFormHandlerBase::$yamlform protected property The form .
YamlFormHandlerBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
YamlFormHandlerBase::cardinality public function Returns the form handler cardinality settings. Overrides YamlFormHandlerInterface::cardinality
YamlFormHandlerBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 2
YamlFormHandlerBase::description public function Returns the form handler description. Overrides YamlFormHandlerInterface::description
YamlFormHandlerBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurablePluginInterface::getConfiguration
YamlFormHandlerBase::getHandlerId public function Returns the unique ID representing the form handler. Overrides YamlFormHandlerInterface::getHandlerId
YamlFormHandlerBase::getLabel public function Returns the label of the form handler. Overrides YamlFormHandlerInterface::getLabel
YamlFormHandlerBase::getStatus public function Returns the status of the form handler. Overrides YamlFormHandlerInterface::getStatus
YamlFormHandlerBase::getSummary public function Returns a render array summarizing the configuration of the form handler. Overrides YamlFormHandlerInterface::getSummary 2
YamlFormHandlerBase::getWeight public function Returns the weight of the form handler. Overrides YamlFormHandlerInterface::getWeight
YamlFormHandlerBase::getYamlForm public function Get the form that this handler is attached to.
YamlFormHandlerBase::init public function Initialize form handler.
YamlFormHandlerBase::isDisabled public function Returns the form handler disabled indicator. Overrides YamlFormHandlerInterface::isDisabled
YamlFormHandlerBase::isEnabled public function Returns the form handler enabled indicator. Overrides YamlFormHandlerInterface::isEnabled 1
YamlFormHandlerBase::label public function Returns the form handler label. Overrides YamlFormHandlerInterface::label
YamlFormHandlerBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface::setConfiguration
YamlFormHandlerBase::setHandlerId public function Sets the id for this form handler. Overrides YamlFormHandlerInterface::setHandlerId
YamlFormHandlerBase::setLabel public function Sets the label for this form handler. Overrides YamlFormHandlerInterface::setLabel
YamlFormHandlerBase::setStatus public function Sets the status for this form handler. Overrides YamlFormHandlerInterface::setStatus
YamlFormHandlerBase::setWeight public function Sets the weight for this form handler. Overrides YamlFormHandlerInterface::setWeight
YamlFormHandlerBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
YamlFormHandlerBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 2
YamlFormHandlerInterface::CARDINALITY_SINGLE constant Value indicating a single plugin instances are permitted.
YamlFormHandlerInterface::CARDINALITY_UNLIMITED constant Value indicating unlimited plugin instances are permitted.
YamlFormHandlerInterface::RESULTS_IGNORED constant Value indicating form submissions are not processed (ie email or saved) by the handler.
YamlFormHandlerInterface::RESULTS_PROCESSED constant Value indicating form submissions are processed (ie email or saved) by the handler.