TestEnvironment.php in Build Hooks 8.2
File
tests/modules/build_hooks_test/src/Plugin/FrontendEnvironment/TestEnvironment.php
View source
<?php
namespace Drupal\build_hooks_test\Plugin\FrontendEnvironment;
use Drupal\build_hooks\BuildHookDetails;
use Drupal\build_hooks\Plugin\FrontendEnvironmentBase;
use Drupal\Core\Form\FormStateInterface;
class TestEnvironment extends FrontendEnvironmentBase {
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'whiz' => 'whang',
];
}
public function getBuildHookDetails() {
$details = new BuildHookDetails();
$details
->setOptions([
'hi' => 'there',
]);
$details
->setMethod('POST');
$details
->setUrl('http://example.com?whiz=' . $this->configuration['whiz']);
return $details;
}
public function getAdditionalDeployFormElements(FormStateInterface $form_state) {
return [
[
'#markup' => '<h3>Hi there</h3>',
],
];
}
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'],
],
];
}
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.'));
}
}
public function frontEndEnvironmentSubmit($form, FormStateInterface $form_state) {
parent::frontEndEnvironmentSubmit($form, $form_state);
$this->configuration['whiz'] = $form_state
->getValue('whiz');
}
}