Loading config/schema/cloud.field.settings.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,9 @@ field.formatter.settings.entity_link: extra_route_parameter_entity_method: type: string label: 'Entity method for extra route parameter' link_description_parameter_entity_method: type: string label: 'Entity method for link description parameter' target_type_list: type: string label: 'Target type list' Loading modules/cloud_service_providers/aws_cloud/aws_cloud.install +47 −0 Original line number Diff line number Diff line Loading @@ -6,10 +6,12 @@ */ use Drupal\aws_cloud\Access\AwsCloudAccessInterface; use Drupal\aws_cloud\Entity\Ec2\AttachedInstanceLinkQuery; use Drupal\aws_cloud\Plugin\Field\Util\AwsCloudReservedKeyChecker; use Drupal\aws_cloud\Plugin\Field\Util\AwsCloudValueConverter; use Drupal\aws_cloud\Service\Pricing\PricingService; use Drupal\cloud\Entity\CloudConfig; use Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator; use Drupal\Component\Serialization\Yaml; use Drupal\Core\Config\FileStorage; use Drupal\Core\Database\Database; Loading Loading @@ -3768,3 +3770,48 @@ function aws_cloud_update_8273(): void { ]; \Drupal::service('cloud')->updateYmlDefinitions($files, 'aws_cloud'); } /** * Add attachment_device_name to aws_cloud_volume. */ function aws_cloud_update_8274() { $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); $field_name = 'attachment_device_name'; $field_storage_definition = $definition_update_manager->getFieldStorageDefinition( $field_name, 'aws_cloud_volume' ); if ($field_storage_definition) { $definition_update_manager->uninstallFieldStorageDefinition($field_storage_definition); } $field_storage_definition = BaseFieldDefinition::create('string') ->setLabel(t('Attachment to')) ->setDescription(t('Attachment to')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'entity_link', 'settings' => [ 'target_type' => 'aws_cloud_instance', 'field_name' => 'instance_id', 'link_description_parameter_entity_method' => 'getAttachmentDeviceName', 'html_generator_class' => EntityLinkWithDeviceNameHtmlGenerator::class, 'query_class' => AttachedInstanceLinkQuery::class, ], 'weight' => -5, ]) ->setReadOnly(TRUE); $definition_update_manager->installFieldStorageDefinition( $field_name, 'aws_cloud_volume', 'aws_cloud', $field_storage_definition ); $files = [ 'views.view.aws_cloud_volume.yml', ]; \Drupal::service('cloud')->updateYmlDefinitions($files, 'aws_cloud'); } modules/cloud_service_providers/aws_cloud/config/install/views.view.aws_cloud_volume.yml +4 −2 Original line number Diff line number Diff line Loading @@ -630,7 +630,8 @@ display: settings: target_type: aws_cloud_instance field_name: instance_id html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithShortNameHtmlGenerator link_description_parameter_entity_method: getAttachmentDeviceName html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator group_column: value group_columns: { } group_rows: true Loading Loading @@ -1374,7 +1375,8 @@ display: settings: target_type: aws_cloud_instance field_name: instance_id html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithShortNameHtmlGenerator link_description_parameter_entity_method: getAttachmentDeviceName html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator group_column: value group_columns: { } group_rows: true Loading modules/cloud_service_providers/aws_cloud/src/Entity/Ec2/AttachedInstanceLinkQuery.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php namespace Drupal\aws_cloud\Entity\Ec2; use Drupal\cloud\Service\Util\EntityLinkQuery; use Drupal\Core\Entity\EntityInterface; /** * Query generator for attached instance links on volume pages. */ class AttachedInstanceLinkQuery extends EntityLinkQuery { /** * {@inheritdoc} */ public function query(string $target_type, string $cloud_context, string $field_name, string $item, EntityInterface $entity = NULL): array { if (empty($entity) || !method_exists($entity, 'getAttachmentInformation')) { return []; } // To retrieve an AttachedInstance, // use VolumeInterface::getAttachmentInformation() to obtain the Attached // instance ID and search for the instance using it as the key. return $this->entityTypeManager ->getStorage($target_type) ->getQuery() ->accessCheck(TRUE) ->condition('cloud_context', $cloud_context) ->condition($field_name, $entity->getAttachmentInformation()) ->execute(); } } modules/cloud_service_providers/aws_cloud/src/Entity/Ec2/Volume.php +32 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\aws_cloud\Entity\Ec2; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\cloud\Entity\CloudContentEntityBase; use Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator; use Drupal\cloud\Service\Util\EntityLinkWithNameHtmlGenerator; /** Loading Loading @@ -115,6 +116,13 @@ class Volume extends CloudContentEntityBase implements VolumeInterface { return $this->get('attachment_information')->value; } /** * {@inheritdoc} */ public function getAttachmentDeviceName(): ?string { return $this->get('attachment_device_name')->value ?? ''; } /** * {@inheritdoc} */ Loading Loading @@ -248,6 +256,13 @@ class Volume extends CloudContentEntityBase implements VolumeInterface { return $this->set('attachment_information', $attachment_information); } /** * {@inheritdoc} */ public function setAttachmentDeviceName($attachment_device_name): VolumeInterface { return $this->set('attachment_device_name', $attachment_device_name); } /** * {@inheritdoc} * Loading Loading @@ -493,6 +508,23 @@ class Volume extends CloudContentEntityBase implements VolumeInterface { ], ]); $fields['attachment_device_name'] = BaseFieldDefinition::create('string') ->setLabel(t('Attachment to')) ->setDescription(t('Attachment to')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'entity_link', 'settings' => [ 'target_type' => 'aws_cloud_instance', 'field_name' => 'instance_id', 'link_description_parameter_entity_method' => 'getAttachmentDeviceName', 'html_generator_class' => EntityLinkWithDeviceNameHtmlGenerator::class, 'query_class' => AttachedInstanceLinkQuery::class, ], 'weight' => -5, ]) ->setReadOnly(TRUE); $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the entity was last edited.')); Loading Loading
config/schema/cloud.field.settings.schema.yml +3 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,9 @@ field.formatter.settings.entity_link: extra_route_parameter_entity_method: type: string label: 'Entity method for extra route parameter' link_description_parameter_entity_method: type: string label: 'Entity method for link description parameter' target_type_list: type: string label: 'Target type list' Loading
modules/cloud_service_providers/aws_cloud/aws_cloud.install +47 −0 Original line number Diff line number Diff line Loading @@ -6,10 +6,12 @@ */ use Drupal\aws_cloud\Access\AwsCloudAccessInterface; use Drupal\aws_cloud\Entity\Ec2\AttachedInstanceLinkQuery; use Drupal\aws_cloud\Plugin\Field\Util\AwsCloudReservedKeyChecker; use Drupal\aws_cloud\Plugin\Field\Util\AwsCloudValueConverter; use Drupal\aws_cloud\Service\Pricing\PricingService; use Drupal\cloud\Entity\CloudConfig; use Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator; use Drupal\Component\Serialization\Yaml; use Drupal\Core\Config\FileStorage; use Drupal\Core\Database\Database; Loading Loading @@ -3768,3 +3770,48 @@ function aws_cloud_update_8273(): void { ]; \Drupal::service('cloud')->updateYmlDefinitions($files, 'aws_cloud'); } /** * Add attachment_device_name to aws_cloud_volume. */ function aws_cloud_update_8274() { $definition_update_manager = \Drupal::entityDefinitionUpdateManager(); $field_name = 'attachment_device_name'; $field_storage_definition = $definition_update_manager->getFieldStorageDefinition( $field_name, 'aws_cloud_volume' ); if ($field_storage_definition) { $definition_update_manager->uninstallFieldStorageDefinition($field_storage_definition); } $field_storage_definition = BaseFieldDefinition::create('string') ->setLabel(t('Attachment to')) ->setDescription(t('Attachment to')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'entity_link', 'settings' => [ 'target_type' => 'aws_cloud_instance', 'field_name' => 'instance_id', 'link_description_parameter_entity_method' => 'getAttachmentDeviceName', 'html_generator_class' => EntityLinkWithDeviceNameHtmlGenerator::class, 'query_class' => AttachedInstanceLinkQuery::class, ], 'weight' => -5, ]) ->setReadOnly(TRUE); $definition_update_manager->installFieldStorageDefinition( $field_name, 'aws_cloud_volume', 'aws_cloud', $field_storage_definition ); $files = [ 'views.view.aws_cloud_volume.yml', ]; \Drupal::service('cloud')->updateYmlDefinitions($files, 'aws_cloud'); }
modules/cloud_service_providers/aws_cloud/config/install/views.view.aws_cloud_volume.yml +4 −2 Original line number Diff line number Diff line Loading @@ -630,7 +630,8 @@ display: settings: target_type: aws_cloud_instance field_name: instance_id html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithShortNameHtmlGenerator link_description_parameter_entity_method: getAttachmentDeviceName html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator group_column: value group_columns: { } group_rows: true Loading Loading @@ -1374,7 +1375,8 @@ display: settings: target_type: aws_cloud_instance field_name: instance_id html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithShortNameHtmlGenerator link_description_parameter_entity_method: getAttachmentDeviceName html_generator_class: Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator group_column: value group_columns: { } group_rows: true Loading
modules/cloud_service_providers/aws_cloud/src/Entity/Ec2/AttachedInstanceLinkQuery.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php namespace Drupal\aws_cloud\Entity\Ec2; use Drupal\cloud\Service\Util\EntityLinkQuery; use Drupal\Core\Entity\EntityInterface; /** * Query generator for attached instance links on volume pages. */ class AttachedInstanceLinkQuery extends EntityLinkQuery { /** * {@inheritdoc} */ public function query(string $target_type, string $cloud_context, string $field_name, string $item, EntityInterface $entity = NULL): array { if (empty($entity) || !method_exists($entity, 'getAttachmentInformation')) { return []; } // To retrieve an AttachedInstance, // use VolumeInterface::getAttachmentInformation() to obtain the Attached // instance ID and search for the instance using it as the key. return $this->entityTypeManager ->getStorage($target_type) ->getQuery() ->accessCheck(TRUE) ->condition('cloud_context', $cloud_context) ->condition($field_name, $entity->getAttachmentInformation()) ->execute(); } }
modules/cloud_service_providers/aws_cloud/src/Entity/Ec2/Volume.php +32 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\aws_cloud\Entity\Ec2; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\cloud\Entity\CloudContentEntityBase; use Drupal\cloud\Service\Util\EntityLinkWithDeviceNameHtmlGenerator; use Drupal\cloud\Service\Util\EntityLinkWithNameHtmlGenerator; /** Loading Loading @@ -115,6 +116,13 @@ class Volume extends CloudContentEntityBase implements VolumeInterface { return $this->get('attachment_information')->value; } /** * {@inheritdoc} */ public function getAttachmentDeviceName(): ?string { return $this->get('attachment_device_name')->value ?? ''; } /** * {@inheritdoc} */ Loading Loading @@ -248,6 +256,13 @@ class Volume extends CloudContentEntityBase implements VolumeInterface { return $this->set('attachment_information', $attachment_information); } /** * {@inheritdoc} */ public function setAttachmentDeviceName($attachment_device_name): VolumeInterface { return $this->set('attachment_device_name', $attachment_device_name); } /** * {@inheritdoc} * Loading Loading @@ -493,6 +508,23 @@ class Volume extends CloudContentEntityBase implements VolumeInterface { ], ]); $fields['attachment_device_name'] = BaseFieldDefinition::create('string') ->setLabel(t('Attachment to')) ->setDescription(t('Attachment to')) ->setDisplayOptions('view', [ 'label' => 'inline', 'type' => 'entity_link', 'settings' => [ 'target_type' => 'aws_cloud_instance', 'field_name' => 'instance_id', 'link_description_parameter_entity_method' => 'getAttachmentDeviceName', 'html_generator_class' => EntityLinkWithDeviceNameHtmlGenerator::class, 'query_class' => AttachedInstanceLinkQuery::class, ], 'weight' => -5, ]) ->setReadOnly(TRUE); $fields['changed'] = BaseFieldDefinition::create('changed') ->setLabel(t('Changed')) ->setDescription(t('The time that the entity was last edited.')); Loading