Skip to content
Snippets Groups Projects
Commit 0d6c3d2a authored by git's avatar git Committed by Yas Naoi
Browse files

Issue #3018938 by shidat, RoshniPatel.addweb, Masami, yas: Comply with Drupal coding standard (3)

parent 6625b9ca
No related branches found
No related tags found
No related merge requests found
Showing
with 122 additions and 55 deletions
......@@ -3,12 +3,13 @@
/**
* @file
* Provides server template functionality for each cloud sub-system.
* Works with Cloud module.
*
* Works with Cloud module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\cloud\Entity\CloudConfig;
/**
* Implements hook_help().
......@@ -81,7 +82,7 @@ function cloud_server_template_theme_suggestions_cloud_server_template(array $va
/**
* Implements hook_cloud_config_delete().
*/
function cloud_server_template_cloud_config_delete(\Drupal\cloud\Entity\CloudConfig $cloud_config) {
function cloud_server_template_cloud_config_delete(CloudConfig $cloud_config) {
$ids = \Drupal::entityQuery('cloud_server_template')
->condition('cloud_context', $cloud_config->getCloudContext())
->execute();
......@@ -92,4 +93,4 @@ function cloud_server_template_cloud_config_delete(\Drupal\cloud\Entity\CloudCon
$entity_manager->getStorage('cloud_server_template')->delete($entities);
}
}
\ No newline at end of file
}
......@@ -5,6 +5,8 @@
* Hooks related to cloud_server_template module.
*/
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
/**
* @addtogroup hooks
* @{
......@@ -14,13 +16,14 @@
* Alter the route array after a template is launched.
*
* @param array $route
* Associate array with route_name, params
* Associate array with route_name, params.
* @param \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $cloud_server_template
* A Cloud Server Template object.
*/
function hook_cloud_server_template_post_launch_redirect_alter(array &$route, Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $cloud_server_template) {
function hook_cloud_server_template_post_launch_redirect_alter(array &$route, CloudServerTemplateInterface $cloud_server_template) {
}
/**
* @} End of "addtogroup hooks".
*/
\ No newline at end of file
*/
......@@ -19,7 +19,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class CloudServerTemplateController extends ControllerBase implements ContainerInjectionInterface, CloudServerTemplateControllerInterface {
/**
* The ServerTemplatePluginManager
* The ServerTemplatePluginManager.
*
* @var \Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManager
*/
protected $serverTemplatePluginManager;
......@@ -35,9 +36,9 @@ class CloudServerTemplateController extends ControllerBase implements ContainerI
* Constructs an OperationsController object.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match
* The route match.
* @param \Drupal\cloud_server_template\Controller\CloudServerTemplatePluginManagerInterface $server_template_plugin_manager
* The server template plugin manager
* The server template plugin manager.
*/
public function __construct(RouteMatchInterface $route_match, CloudServerTemplatePluginManagerInterface $server_template_plugin_manager) {
$this->routeMatch = $route_match;
......@@ -223,7 +224,7 @@ class CloudServerTemplateController extends ControllerBase implements ContainerI
$redirect_route = $this->serverTemplatePluginManager->launch($cloud_server_template);
// Let other modules alter the redirect after a server template has been launched.
\Drupal::moduleHandler()->invokeAll('cloud_server_template_post_launch_redirect_alter', [&$redirect_route, $cloud_server_template]);
return $this->redirect($redirect_route['route_name'], isset($redirect_route['params']) ? $redirect_route['params']: []);
return $this->redirect($redirect_route['route_name'], isset($redirect_route['params']) ? $redirect_route['params'] : []);
}
}
......@@ -5,14 +5,16 @@ namespace Drupal\cloud_server_template\Controller;
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
/**
* Common interfaces for the CloudServerTemplateControllerInterface
* Common interfaces for the CloudServerTemplateControllerInterface.
*/
interface CloudServerTemplateControllerInterface {
/**
* Launch Operation
* @return mixed
* Launch Operation.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirect response object that may be returned by the controller.
*/
public function launch(CloudServerTemplateInterface $cloud_server_template);
}
\ No newline at end of file
}
......@@ -10,7 +10,6 @@ use Drupal\cloud\Controller\CloudContentListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link;
/**
* Provides a list controller for CloudServerTemplate entity.
*
......@@ -45,7 +44,7 @@ class CloudServerTemplateListBuilder extends CloudContentListBuilder {
'entity.cloud_server_template.canonical',
[
'cloud_server_template' => $entity->id(),
'cloud_context' => $entity->getCloudContext()
'cloud_context' => $entity->getCloudContext(),
]
);
......
......@@ -269,7 +269,7 @@ class CloudServerTemplate extends RevisionableContentEntityBase implements Cloud
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
# TODO: make this an entity reference to config entity? For now, leave as string
// @TODO: make this an entity reference to config entity? For now, leave as string
$fields['cloud_context'] = BaseFieldDefinition::create('string')
->setLabel(t('Cloud Provider Machine Name'))
->setRequired(TRUE)
......@@ -326,7 +326,7 @@ class CloudServerTemplate extends RevisionableContentEntityBase implements Cloud
}
/**
* Clear the menu, render cache and rebuild the routers
* Clear the menu, render cache and rebuild the routers.
*/
private function updateCache() {
// Clear block and menu cache.
......
......@@ -16,6 +16,7 @@ use Drupal\user\EntityOwnerInterface;
interface CloudServerTemplateInterface extends ContentEntityInterface, RevisionLogInterface, EntityChangedInterface, EntityOwnerInterface, CloudContextInterface {
// Add get/set methods for your configuration properties here.
/**
* Gets the Cloud Server Template name.
*
......
......@@ -12,26 +12,28 @@ use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
/**
* Provides confirmation when launching an instance
* Provides confirmation when launching an instance.
*/
class CloudServerTemplateLaunchConfirm extends ContentEntityConfirmFormBase {
/**
* The ServerTemplatePluginManager
* The ServerTemplatePluginManager.
*
* @var \Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManager
*/
protected $serverTemplatePluginManager;
/**
* Construct a CloudServerTemplateLaunchConfirm object.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_manager
* The entity manager.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @var \Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManager
* The ServerTemplatePluginManager
* @param \Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManager $server_template_plugin_manager
* The server template plugin manager
*/
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL, CloudServerTemplatePluginManagerInterface $server_template_plugin_manager) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
......
......@@ -6,33 +6,33 @@ use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Common interfaces for a cloud server template
* Common interfaces for a cloud server template.
*
* @package Drupal\cloud_server_template\Plugin
*/
interface CloudServerTemplatePluginInterface {
/**
* Get the entity bundle defined for a particular plugin
* Get the entity bundle defined for a particular plugin.
*
* @return string
* The entity bundle used to store and interact with a particular cloud
* The entity bundle used to store and interact with a particular cloud
*/
public function getEntityBundleName();
/**
* Method is responsible for interacting with the implementing cloud's launch
* functionality.
* The server template contains all the information needed for that particular cloud
* Method is responsible for interacting with the implementing cloud's launch functionality.
*
* The server template contains all the information needed for that particular cloud.
*
* @param \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $cloud_server_template
* A Cloud Server Template object.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* Form state if launch is called from a form
* Form state if launch is called from a form.
*
* @return array
* An associative array with a redirect route and any parameters to build the route.
* An associative array with a redirect route and any parameters to build the route.
*/
public function launch(CloudServerTemplateInterface $cloud_server_template, FormStateInterface $form_state = NULL);
}
\ No newline at end of file
}
......@@ -4,6 +4,7 @@ namespace Drupal\cloud_server_template\Plugin;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Defines an interface for cloud_server_template_plugin managers.
......@@ -11,21 +12,26 @@ use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
interface CloudServerTemplatePluginManagerInterface extends PluginManagerInterface {
/**
* Load a plugin using the cloud_context
* Load a plugin using the cloud_context.
*
* @param $cloud_context
* @return
* loaded CloudServerTemplatePlugin
* @param string $cloud_context
* Cloud context string.
*
* @return CloudServerTemplatePluginInterface
* loaded CloudServerTemplatePlugin.
*/
public function loadPluginVariant($cloud_context);
/**
* Launch a cloud server template
* Launch a cloud server template.
*
* @param \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $cloud_server_template
* @param $form_state
* Form state array
* A Cloud Server Template object.
* @param FormStateInterface $form_state
* Form state if launch is called from a form.
*
* @return mixed
* An associative array with a redirect route and any parameters to build the route.
*/
public function launch(CloudServerTemplateInterface $cloud_server_template, $form_state = NULL);
......
......@@ -8,15 +8,20 @@ use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides cloud context bundles and cloud server templates.
*/
class CloudServerTemplateCloudContextBundleDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The entity type bundle info.
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entity_type_bundle_info;
protected $entityTypeBundleInfo;
/**
* CloudConfigPlugin
* The CloudConfigPluginManager.
*
* @var \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface
*/
protected $cloudConfigPluginManager;
......@@ -25,12 +30,12 @@ class CloudServerTemplateCloudContextBundleDeriver extends DeriverBase implement
* Constructs new AwsCloudLocalTasks.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type manager
* The entity type manager.
* @param \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud config plugin manager
* The cloud config plugin manager.
*/
public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info, CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
$this->entity_type_bundle_info = $entity_type_bundle_info;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->cloudConfigPluginManager = $cloud_config_plugin_manager;
}
......@@ -51,7 +56,7 @@ class CloudServerTemplateCloudContextBundleDeriver extends DeriverBase implement
// Loop through all cloud_config bundles and build server template links.
// @TODO: not all implementing clouds will have server_templates
// @TODO: Add support for identifying which clouds have server_templates
$bundles = $this->entity_type_bundle_info->getBundleInfo('cloud_config');
$bundles = $this->entityTypeBundleInfo->getBundleInfo('cloud_config');
foreach ($bundles as $key => $bundle) {
$entities = $this->cloudConfigPluginManager->loadConfigEntities($key);
foreach ($entities as $entity) {
......
......@@ -8,16 +8,21 @@ use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
* Provides plugin definitions for local action.
*/
class CloudServerTemplateLocalAction extends LocalActionDefault {
/**
* The ServerTemplatePluginManager
* The ServerTemplatePluginManager.
*
* @var \Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManager
*/
protected $serverTemplatePluginManager;
/**
* @{inheritdoc}
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, CloudServerTemplatePluginManagerInterface $server_template_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider);
......
......@@ -8,15 +8,21 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides plugin definitions for custom local menu.
*/
class CloudServerTemplateMenuLinks extends DeriverBase implements ContainerDeriverInterface {
/**
* The entity type bundle info.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entity_type_bundle_info;
protected $entityTypeBundleInfo;
/**
* CloudConfigPlugin
* The cloud config plugin manager.
*
* @var \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface
*/
protected $cloudConfigPluginManager;
......@@ -25,12 +31,12 @@ class CloudServerTemplateMenuLinks extends DeriverBase implements ContainerDeriv
* Constructs new AwsCloudLocalTasks.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type manager
* The entity type bundle info.
* @param \Drupal\cloud\Plugin\CloudConfigPluginManagerInterface $cloud_config_plugin_manager
* The cloud config plugin manager
* The cloud config plugin manager.
*/
public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info, CloudConfigPluginManagerInterface $cloud_config_plugin_manager) {
$this->entity_type_bundle_info = $entity_type_bundle_info;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->cloudConfigPluginManager = $cloud_config_plugin_manager;
}
......@@ -51,7 +57,7 @@ class CloudServerTemplateMenuLinks extends DeriverBase implements ContainerDeriv
// Loop through all cloud_config bundles and build server template links.
// @TODO: not all implementing clouds will have server_templates
// @TODO: Add support for identifying which clouds have server_templates
$bundles = $this->entity_type_bundle_info->getBundleInfo('cloud_config');
$bundles = $this->entityTypeBundleInfo->getBundleInfo('cloud_config');
foreach ($bundles as $key => $bundle) {
$entities = $this->cloudConfigPluginManager->loadConfigEntities($key);
foreach ($entities as $entity) {
......
......@@ -5,6 +5,9 @@ namespace Drupal\cloud_server_template\Plugin\Derivative;
use Drupal\Core\Menu\LocalTaskDefault;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Provides plugin definitions for custom local task.
*/
class CloudServerTemplateTab extends LocalTaskDefault {
/**
......
......@@ -11,6 +11,7 @@ namespace Drupal\Tests\cloud_server_template\Functional;
use Drupal\Component\Utility\Random;
use Drupal\Tests\aws_cloud\Functional\Ec2\AwsCloudTestCase;
use Drupal\feeds\Feeds\Target\Integer;
/**
* Tests CloudServerTemplate.
......@@ -280,6 +281,9 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
$this->assertSession()->linkByHrefNotExists("server_template/$cloud_context/1/revisions/1/view");
}
/**
* Create server template test data.
*/
private function createServerTemplateTestData() {
$random = $this->random;
......@@ -310,6 +314,9 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
return $data;
}
/**
* Create image.
*/
private function createImage() {
$random = $this->random;
......@@ -322,6 +329,10 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
$image->save();
}
/**
* Create random vpcs
* @return string[][]|string[][][][] Random vpcs array.
*/
private function createRandomVpcs() {
$random = $this->random;
......@@ -343,6 +354,10 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
return $vpcs;
}
/**
* Create random subnets.
* @return string[][]|string[][][][] Random subnets array.
*/
private function createRandomSubnets() {
$random = $this->random;
......@@ -364,6 +379,14 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
return $subnets;
}
/**
* Update vpcs an subnets to mock data.
*
* @param array $vpcs
* vpcs array.
* @param array $subnets
* subnets array.
*/
private function updateVpcsAndSubnetsToMockData($vpcs, $subnets) {
$mock_data = $this->getMockDataFromConfig();
$mock_data['DescribeVpcs']['Vpcs'] = $vpcs;
......@@ -371,6 +394,16 @@ class CloudServerTemplateTest extends AwsCloudTestCase {
$this->updateMockDataToConfig($mock_data);
}
/**
* Get name from array.
* @param array $array
* vpcs or subnets array.
* @param Integer $index
* index of array.
* @param string $id_key_name
* key name of index.
* @return string value of array.
*/
private function getNameFromArray($array, $index, $id_key_name) {
// Get id.
$name = $array[$index][$id_key_name];
......
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