Skip to content
Snippets Groups Projects
Commit c477aae5 authored by Yas Naoi's avatar Yas Naoi
Browse files

Issue #2736821: aws_cloud - Supported Availability Zone selection in a create volume form

parent b1138060
No related branches found
No related tags found
No related merge requests found
<?php
// Updated by yas 2016/09/11
// Updated by yas 2016/06/04
// Updated by yas 2016/05/31
// Updated by yas 2016/05/30
......@@ -12,6 +13,7 @@ use Drupal\cloud\Form\CloudContentForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\Language;
use Drupal\aws_cloud\Controller\Ec2\ApiController;
use Drupal\aws_cloud\Entity\Config\Config;
/**
* Form controller for the Volume entity create form.
......@@ -24,6 +26,22 @@ class VolumeCreateForm extends CloudContentForm {
* Overrides Drupal\Core\Entity\EntityFormController::buildForm().
*/
public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = '') {
$cloudContext = Config::load($cloud_context);
if(isset($cloudContext)) {
$cloud_type = $cloudContext->cloud_type();
$this->apiController = new ApiController($this->query_factory);
}
else {
$status = 'error';
$message = $this->t("Not found: AWS Cloud provider '@cloud_context'", array(
'@cloud_context' => $cloud_context,
));
drupal_set_message($message, $status);
}
/* @var $entity \Drupal\aws_cloud\Entity\Ec2\Volume */
$form = parent::buildForm($form, $form_state);
......@@ -61,11 +79,13 @@ class VolumeCreateForm extends CloudContentForm {
'#required' => FALSE,
);
$availability_zones = $this->apiController->getAvailabilityZones($cloudContext);
$form['availability_zone'] = array(
'#type' => 'textfield',
'#type' => 'select',
'#title' => $this->t('Availability Zone'),
'#size' => 60,
'#default_value' => $entity->availability_zone(),
'#options' => $availability_zones,
// Pick up the first availability zone in the array
'#default_value' => array_shift($availability_zones),
'#weight' => -5,
'#required' => TRUE,
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment