You are here

class TestEnvironment in Build Hooks 3.x

Same name and namespace in other branches
  1. 8.2 tests/modules/build_hooks_test/src/Plugin/FrontendEnvironment/TestEnvironment.php \Drupal\build_hooks_test\Plugin\FrontendEnvironment\TestEnvironment

Defines a test environment plugin.

Plugin annotation


@FrontendEnvironment(
 id = "build_hooks_test",
 label = "Test environment",
 description = "Test environment."
)

Hierarchy

Expanded class hierarchy of TestEnvironment

File

tests/modules/build_hooks_test/src/Plugin/FrontendEnvironment/TestEnvironment.php, line 20

Namespace

Drupal\build_hooks_test\Plugin\FrontendEnvironment
View source
class TestEnvironment extends FrontendEnvironmentBase {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return parent::defaultConfiguration() + [
      'whiz' => 'whang',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getBuildHookDetails() {
    $details = new BuildHookDetails();
    $details
      ->setOptions([
      'hi' => 'there',
    ]);
    $details
      ->setMethod('POST');
    $details
      ->setUrl('http://example.com?whiz=' . $this->configuration['whiz']);
    return $details;
  }

  /**
   * {@inheritdoc}
   */
  public function getAdditionalDeployFormElements(FormStateInterface $form_state) {
    return [
      [
        '#markup' => '<h3>Hi there</h3>',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function frontEndEnvironmentForm($form, FormStateInterface $form_state) {
    return parent::frontEndEnvironmentForm($form, $form_state) + [
      'whiz' => [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Whiz?'),
        '#default_value' => $this->configuration['whiz'],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function frontEndEnvironmentFormValidate($form, FormStateInterface $form_state) {
    parent::frontEndEnvironmentFormValidate($form, $form_state);
    $whiz = $form_state
      ->getValue('whiz');
    if (strlen($whiz) < 3) {
      $form_state
        ->setErrorByName('whiz', $this
        ->t('Whiz must contains minimum 3 characters.'));
    }
  }

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

  /**
   * {@inheritdoc}
   */
  public function preDeploymentTrigger(BuildTrigger $trigger) : void {
    if ($this->configuration['whiz'] === 'no deploy for you') {
      $trigger
        ->setShouldNotBuild(new TranslatableMarkup('No deploy today'));
    }
    if ($trigger
      ->getDeployment()->contents->entity) {
      $entity = $trigger
        ->getDeployment()->contents->entity;
      if ($entity
        ->label() === "can't let you do that dave") {
        $trigger
          ->setShouldNotBuild(new TranslatableMarkup('No deploy for this item'));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FrontendEnvironmentBase::$transliteration protected property The transliteration service.
FrontendEnvironmentBase::baseConfigurationDefaults protected function Returns generic default configuration for frontend environment plugins.
FrontendEnvironmentBase::buildConfigurationForm public function Form constructor. Overrides PluginFormInterface::buildConfigurationForm
FrontendEnvironmentBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
FrontendEnvironmentBase::deploymentWasTriggered public function Determine if the deployment was triggered successfully. Overrides FrontendEnvironmentInterface::deploymentWasTriggered 2
FrontendEnvironmentBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
FrontendEnvironmentBase::getMachineNameSuggestion public function
FrontendEnvironmentBase::label public function
FrontendEnvironmentBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
FrontendEnvironmentBase::setConfigurationValue public function
FrontendEnvironmentBase::setTransliteration public function Sets the transliteration service.
FrontendEnvironmentBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
FrontendEnvironmentBase::transliteration protected function Wraps the transliteration service.
FrontendEnvironmentBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm
FrontendEnvironmentBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 4
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 2
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.
PluginWithFormsTrait::getFormClass public function Implements \Drupal\Core\Plugin\PluginWithFormsInterface::getFormClass().
PluginWithFormsTrait::hasFormClass public function Implements \Drupal\Core\Plugin\PluginWithFormsInterface::hasFormClass().
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
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.
TestEnvironment::defaultConfiguration public function Gets default configuration for this plugin. Overrides FrontendEnvironmentBase::defaultConfiguration
TestEnvironment::frontEndEnvironmentForm public function Overrides FrontendEnvironmentBase::frontEndEnvironmentForm
TestEnvironment::frontEndEnvironmentFormValidate public function Overrides FrontendEnvironmentBase::frontEndEnvironmentFormValidate
TestEnvironment::frontEndEnvironmentSubmit public function Overrides FrontendEnvironmentBase::frontEndEnvironmentSubmit
TestEnvironment::getAdditionalDeployFormElements public function Allows the plugin to add elements to the deployment form. Overrides FrontendEnvironmentInterface::getAdditionalDeployFormElements
TestEnvironment::getBuildHookDetails public function Get the info to trigger the hook based on the configuration of the plugin. Overrides FrontendEnvironmentInterface::getBuildHookDetails
TestEnvironment::preDeploymentTrigger public function React before a build is triggered. Overrides FrontendEnvironmentBase::preDeploymentTrigger