Loading modules/cloud_service_providers/openstack/openstack.install +47 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Component\Serialization\Yaml; use Drupal\openstack\Entity\OpenStackQuota; /** * Implements hook_install(). Loading Loading @@ -2828,3 +2829,49 @@ function openstack_update_8321() { drupal_flush_all_caches(); } /** * Add status and *_new fields to openstack quota. */ function openstack_update_8322() { $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); $entity_type = 'openstack_quota'; $field_manager = \Drupal::service('entity_field.manager'); $definitions = $field_manager->getBaseFieldDefinitions($entity_type); // Add *_new field for the editable field. foreach (OpenStackQuota::getEditableFieldSets() as $field_set) { foreach ($field_set['fields'] as $field_name) { if (empty($definitions[$field_name])) { continue; } // Copy field. $fields["{$field_name}_new"] = BaseFieldDefinition::createFromFieldStorageDefinition($definitions[$field_name]); } } $fields['status'] = BaseFieldDefinition::create('string') ->setRequired(TRUE) ->setLabel(t('Status')) ->setDescription(t('The status of the application.')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); foreach ($fields ?: [] as $name => $definition) { $definition_update_manager->installFieldStorageDefinition( $name, $entity_type, 'openstack', $definition ); } drupal_flush_all_caches(); } modules/cloud_service_providers/openstack/src/Entity/OpenStackQuota.php +75 −0 Original line number Diff line number Diff line Loading @@ -652,6 +652,55 @@ class OpenStackQuota extends CloudContentEntityBase implements OpenStackQuotaInt return $this->set('refreshed', $time); } /** * Get editable field sets. * * @return array * Editable field sets. */ public static function getEditableFieldSets(): array { return [ [ 'name' => 'quota_compute', 'title' => t('Compute'), 'fields' => [ 'instances', 'cores', 'ram', 'metadata_items', 'key_pairs', 'server_groups', 'server_group_members', 'injected_files', 'injected_file_content_bytes', 'injected_file_path_bytes', ], ], [ 'name' => 'quota_volume', 'title' => t('Volume'), 'fields' => [ 'volumes', 'snapshots', 'gigabytes', ], ], [ 'name' => 'quota_network', 'title' => t('Network'), 'fields' => [ 'network', 'subnet', 'port', 'router', 'floatingip', 'security_group', 'security_group_rule', ], ], ]; } /** * {@inheritdoc} */ Loading Loading @@ -1239,6 +1288,32 @@ class OpenStackQuota extends CloudContentEntityBase implements OpenStackQuotaInt ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); // Add *_new field for the editable field. foreach (self::getEditableFieldSets() as $field_set) { foreach ($field_set['fields'] as $field_name) { $definition = $fields[$field_name]; $definition->setName("{$field_name}_new"); // Create a new field. $new_definition = BaseFieldDefinition::createFromFieldStorageDefinition($definition); $fields["{$field_name}_new"] = $new_definition; // Restore the name of definition. $definition->setName($field_name); } } $fields['status'] = BaseFieldDefinition::create('string') ->setRequired(TRUE) ->setLabel(t('Status')) ->setDescription(t('The status of the application.')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); return $fields; } Loading modules/cloud_service_providers/openstack/src/Form/OpenStackQuotaEditForm.php +6 −43 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\openstack\Form; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm; use Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; Loading @@ -23,8 +22,10 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\cloud\Service\CloudServiceInterface; use Drupal\cloud\Traits\CloudContentEntityTrait; use Drupal\openstack\Entity\OpenStackQuota; use Drupal\openstack\Traits\OpenStackFormSelectTrait; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** Loading Loading @@ -194,48 +195,7 @@ class OpenStackQuotaEditForm extends AwsCloudContentForm { '#markup' => $entity->getName(), ]; $field_sets = [ [ 'name' => 'quota_compute', 'title' => $this->t('Compute'), 'fields' => [ 'instances', 'cores', 'ram', 'metadata_items', 'key_pairs', 'server_groups', 'server_group_members', 'injected_files', 'injected_file_content_bytes', 'injected_file_path_bytes', ], ], [ 'name' => 'quota_volume', 'title' => $this->t('Volume'), 'fields' => [ 'volumes', 'snapshots', 'gigabytes', ], ], [ 'name' => 'quota_network', 'title' => $this->t('Network'), 'fields' => [ 'network', 'subnet', 'port', 'router', 'floatingip', 'security_group', 'security_group_rule', ], ], ]; foreach ($field_sets as $field_set) { foreach (OpenStackQuota::getEditableFieldSets() as $field_set) { $form[$field_set['name']] = [ '#type' => 'details', '#title' => $field_set['title'], Loading @@ -246,6 +206,9 @@ class OpenStackQuotaEditForm extends AwsCloudContentForm { foreach ($field_set['fields'] as $field) { $form[$field_set['name']][$field] = $form[$field]; unset($form[$field]); // Hide *_new fields. unset($form["{$field}_new"]); } } Loading Loading
modules/cloud_service_providers/openstack/openstack.install +47 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Component\Serialization\Yaml; use Drupal\openstack\Entity\OpenStackQuota; /** * Implements hook_install(). Loading Loading @@ -2828,3 +2829,49 @@ function openstack_update_8321() { drupal_flush_all_caches(); } /** * Add status and *_new fields to openstack quota. */ function openstack_update_8322() { $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); $entity_type = 'openstack_quota'; $field_manager = \Drupal::service('entity_field.manager'); $definitions = $field_manager->getBaseFieldDefinitions($entity_type); // Add *_new field for the editable field. foreach (OpenStackQuota::getEditableFieldSets() as $field_set) { foreach ($field_set['fields'] as $field_name) { if (empty($definitions[$field_name])) { continue; } // Copy field. $fields["{$field_name}_new"] = BaseFieldDefinition::createFromFieldStorageDefinition($definitions[$field_name]); } } $fields['status'] = BaseFieldDefinition::create('string') ->setRequired(TRUE) ->setLabel(t('Status')) ->setDescription(t('The status of the application.')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); foreach ($fields ?: [] as $name => $definition) { $definition_update_manager->installFieldStorageDefinition( $name, $entity_type, 'openstack', $definition ); } drupal_flush_all_caches(); }
modules/cloud_service_providers/openstack/src/Entity/OpenStackQuota.php +75 −0 Original line number Diff line number Diff line Loading @@ -652,6 +652,55 @@ class OpenStackQuota extends CloudContentEntityBase implements OpenStackQuotaInt return $this->set('refreshed', $time); } /** * Get editable field sets. * * @return array * Editable field sets. */ public static function getEditableFieldSets(): array { return [ [ 'name' => 'quota_compute', 'title' => t('Compute'), 'fields' => [ 'instances', 'cores', 'ram', 'metadata_items', 'key_pairs', 'server_groups', 'server_group_members', 'injected_files', 'injected_file_content_bytes', 'injected_file_path_bytes', ], ], [ 'name' => 'quota_volume', 'title' => t('Volume'), 'fields' => [ 'volumes', 'snapshots', 'gigabytes', ], ], [ 'name' => 'quota_network', 'title' => t('Network'), 'fields' => [ 'network', 'subnet', 'port', 'router', 'floatingip', 'security_group', 'security_group_rule', ], ], ]; } /** * {@inheritdoc} */ Loading Loading @@ -1239,6 +1288,32 @@ class OpenStackQuota extends CloudContentEntityBase implements OpenStackQuotaInt ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); // Add *_new field for the editable field. foreach (self::getEditableFieldSets() as $field_set) { foreach ($field_set['fields'] as $field_name) { $definition = $fields[$field_name]; $definition->setName("{$field_name}_new"); // Create a new field. $new_definition = BaseFieldDefinition::createFromFieldStorageDefinition($definition); $fields["{$field_name}_new"] = $new_definition; // Restore the name of definition. $definition->setName($field_name); } } $fields['status'] = BaseFieldDefinition::create('string') ->setRequired(TRUE) ->setLabel(t('Status')) ->setDescription(t('The status of the application.')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'string', 'weight' => -5, ]) ->setReadOnly(TRUE); return $fields; } Loading
modules/cloud_service_providers/openstack/src/Form/OpenStackQuotaEditForm.php +6 −43 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\openstack\Form; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Drupal\aws_cloud\Form\Ec2\AwsCloudContentForm; use Drupal\aws_cloud\Service\AwsCloud\AwsCloudOperationsServiceInterface; use Drupal\aws_cloud\Service\Ec2\Ec2ServiceInterface; Loading @@ -23,8 +22,10 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountInterface; use Drupal\cloud\Service\CloudServiceInterface; use Drupal\cloud\Traits\CloudContentEntityTrait; use Drupal\openstack\Entity\OpenStackQuota; use Drupal\openstack\Traits\OpenStackFormSelectTrait; use Drupal\openstack\Service\OpenStackOperationsServiceInterface; use Drupal\openstack\Service\OpenStackServiceFactoryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** Loading Loading @@ -194,48 +195,7 @@ class OpenStackQuotaEditForm extends AwsCloudContentForm { '#markup' => $entity->getName(), ]; $field_sets = [ [ 'name' => 'quota_compute', 'title' => $this->t('Compute'), 'fields' => [ 'instances', 'cores', 'ram', 'metadata_items', 'key_pairs', 'server_groups', 'server_group_members', 'injected_files', 'injected_file_content_bytes', 'injected_file_path_bytes', ], ], [ 'name' => 'quota_volume', 'title' => $this->t('Volume'), 'fields' => [ 'volumes', 'snapshots', 'gigabytes', ], ], [ 'name' => 'quota_network', 'title' => $this->t('Network'), 'fields' => [ 'network', 'subnet', 'port', 'router', 'floatingip', 'security_group', 'security_group_rule', ], ], ]; foreach ($field_sets as $field_set) { foreach (OpenStackQuota::getEditableFieldSets() as $field_set) { $form[$field_set['name']] = [ '#type' => 'details', '#title' => $field_set['title'], Loading @@ -246,6 +206,9 @@ class OpenStackQuotaEditForm extends AwsCloudContentForm { foreach ($field_set['fields'] as $field) { $form[$field_set['name']][$field] = $form[$field]; unset($form[$field]); // Hide *_new fields. unset($form["{$field}_new"]); } } Loading