public function FrontendEnvironmentForm::form in Build Hooks 3.x
Same name and namespace in other branches
- 8.2 src/Form/FrontendEnvironmentForm.php \Drupal\build_hooks\Form\FrontendEnvironmentForm::form()
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ FrontendEnvironmentForm.php, line 49
Class
- FrontendEnvironmentForm
- Class StaticFrontEnvironmentForm.
Namespace
Drupal\build_hooks\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/** @var \Drupal\build_hooks\Entity\FrontendEnvironmentInterface $entity */
$entity = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $entity
->label(),
'#description' => $this
->t("Label for the Frontend environment."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#default_value' => $entity
->id(),
'#machine_name' => [
'exists' => '\\Drupal\\build_hooks\\Entity\\FrontendEnvironment::load',
],
'#disabled' => !$entity
->isNew(),
];
$form['url'] = [
'#type' => 'url',
'#title' => $this
->t('Url'),
'#maxlength' => 255,
'#default_value' => $entity
->getUrl(),
'#description' => $this
->t("Url at which this environment is available for viewing."),
'#required' => TRUE,
];
$deployment_strategy_allowed_values = [
TriggerInterface::DEPLOYMENT_STRATEGY_MANUAL => $this
->t('<strong>Manually only</strong>: deploys are triggered only by submitting the deployment form.'),
TriggerInterface::DEPLOYMENT_STRATEGY_CRON => $this
->t('<strong>On cron</strong>: a deployment will be triggered for this environment at each cron run.'),
TriggerInterface::DEPLOYMENT_STRATEGY_ENTITYSAVE => $this
->t('<strong>When content is updated</strong>: deploy this environment when one of the logged entities is added, modified or deleted.'),
];
$form['deployment_strategy'] = [
'#type' => 'radios',
'#title' => $this
->t('Deployment strategy.'),
'#default_value' => $entity
->getDeploymentStrategy() ? $entity
->getDeploymentStrategy() : TriggerInterface::DEPLOYMENT_STRATEGY_MANUAL,
'#options' => $deployment_strategy_allowed_values,
'#description' => $this
->t('You can choose here how the deployments should be triggered for this environment.'),
];
$form['weight'] = [
'#type' => 'number',
'#title' => $this
->t('Weight'),
'#max' => 100,
'#min' => -100,
'#size' => 3,
'#default_value' => $entity
->getWeight() ? $entity
->getWeight() : 0,
'#description' => $this
->t("Set the weight, lighter environments will be rendered first in the toolbar."),
'#required' => TRUE,
];
$form['#tree'] = TRUE;
$form['settings'] = [];
$subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
$form['settings'] = $this
->getPluginForm($entity
->getPlugin())
->buildConfigurationForm($form['settings'], $subform_state);
return $form;
}