class TestEnvironment in Build Hooks 8.2
Same name and namespace in other branches
- 3.x 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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\build_hooks\Plugin\FrontendEnvironmentBase implements FrontendEnvironmentInterface, PluginWithFormsInterface uses PluginWithFormsTrait, StringTranslationTrait
- class \Drupal\build_hooks_test\Plugin\FrontendEnvironment\TestEnvironment
- class \Drupal\build_hooks\Plugin\FrontendEnvironmentBase implements FrontendEnvironmentInterface, PluginWithFormsInterface uses PluginWithFormsTrait, StringTranslationTrait
Expanded class hierarchy of TestEnvironment
File
- tests/
modules/ build_hooks_test/ src/ Plugin/ FrontendEnvironment/ TestEnvironment.php, line 18
Namespace
Drupal\build_hooks_test\Plugin\FrontendEnvironmentView 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');
}
}