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

Issue #3047694 by baldwinlouie, yas, Xiaohua Guan: Merge cloud_server_template and cloud module

parent f4e58ff8
No related branches found
No related tags found
No related merge requests found
Showing
with 82 additions and 67 deletions
<?php
namespace Drupal\cloud_server_template\Controller;
namespace Drupal\cloud\Controller;
use Drupal\cloud\Controller\CloudContentListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Link;
......
......@@ -218,6 +218,7 @@ class CloudConfig extends RevisionableContentEntityBase implements CloudConfigIn
*/
public function delete() {
parent::delete();
$this->deleteServerTemplate();
$this->updateCache();
}
......@@ -241,6 +242,22 @@ class CloudConfig extends RevisionableContentEntityBase implements CloudConfigIn
\Drupal::service('plugin.cache_clearer')->clearCachedDefinitions();
}
/**
* Delete server templates after cloud config deletion.
*/
private function deleteServerTemplate() {
$ids = \Drupal::entityQuery('cloud_server_template')
->condition('cloud_context', $this->getCloudContext())
->execute();
if (count($ids)) {
/* @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager */
$entity_manager = \Drupal::entityTypeManager();
$entities = $entity_manager->getStorage('cloud_server_template')
->loadMultiple($ids);
$entity_manager->getStorage('cloud_server_template')->delete($entities);
}
}
/**
* Check if a specific cloud_context exists.
*
......
......@@ -42,15 +42,14 @@ class CloudConfigViewsData extends EntityViewsData {
],
];
if ($this->moduleHandler->moduleExists('cloud_server_template')) {
$data[$entity_type_id]['list_server_templates_' . $entity_type_id] = [
'field' => [
'title' => $this->t('Server Templates'),
'help' => $this->t('Provide a listing link to server template'),
'id' => 'cloud_list_templates',
],
];
}
$data[$entity_type_id]['list_server_templates_' . $entity_type_id] = [
'field' => [
'title' => $this->t('Server Templates'),
'help' => $this->t('Provide a listing link to server template'),
'id' => 'cloud_list_templates',
],
];
return $data;
}
......
<?php
namespace Drupal\cloud_server_template\Entity;
namespace Drupal\cloud\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
......@@ -20,22 +20,22 @@ use Drupal\user\UserInterface;
* label = @Translation("Cloud Server Template"),
* bundle_label = @Translation("Cloud Server Template type"),
* handlers = {
* "storage" = "Drupal\cloud_server_template\CloudServerTemplateStorage",
* "storage" = "Drupal\cloud\CloudServerTemplateStorage",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\cloud_server_template\Controller\CloudServerTemplateListBuilder",
* "views_data" = "Drupal\cloud_server_template\Entity\CloudServerTemplateViewsData",
* "translation" = "Drupal\cloud_server_template\CloudServerTemplateTranslationHandler",
* "list_builder" = "Drupal\cloud\Controller\CloudServerTemplateListBuilder",
* "views_data" = "Drupal\cloud\Entity\CloudServerTemplateViewsData",
* "translation" = "Drupal\cloud\CloudServerTemplateTranslationHandler",
*
* "form" = {
* "default" = "Drupal\cloud_server_template\Form\CloudServerTemplateForm",
* "add" = "Drupal\cloud_server_template\Form\CloudServerTemplateForm",
* "edit" = "Drupal\cloud_server_template\Form\CloudServerTemplateForm",
* "delete" = "Drupal\cloud_server_template\Form\CloudServerTemplateDeleteForm",
* "launch" = "Drupal\cloud_server_template\Form\CloudServerTemplateLaunchConfirm",
* "default" = "Drupal\cloud\Form\CloudServerTemplateForm",
* "add" = "Drupal\cloud\Form\CloudServerTemplateForm",
* "edit" = "Drupal\cloud\Form\CloudServerTemplateForm",
* "delete" = "Drupal\cloud\Form\CloudServerTemplateDeleteForm",
* "launch" = "Drupal\cloud\Form\CloudServerTemplateLaunchConfirm",
* },
* "access" = "Drupal\cloud_server_template\Controller\CloudServerTemplateAccessControlHandler",
* "access" = "Drupal\cloud\Controller\CloudServerTemplateAccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\cloud_server_template\Routing\CloudServerTemplateHtmlRouteProvider",
* "html" = "Drupal\cloud\Routing\CloudServerTemplateHtmlRouteProvider",
* },
* },
* base_table = "cloud_server_template",
......
<?php
namespace Drupal\cloud_server_template\Entity;
namespace Drupal\cloud\Entity;
use Drupal\cloud\CloudContextInterface;
use Drupal\Core\Entity\ContentEntityInterface;
......@@ -29,7 +29,7 @@ interface CloudServerTemplateInterface extends ContentEntityInterface, RevisionL
* @param string $name
* The Cloud Server Template name.
*
* @return \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @return \Drupal\cloud\Entity\CloudServerTemplateInterface
* The called Cloud Server Template entity.
*/
public function setName($name);
......@@ -48,7 +48,7 @@ interface CloudServerTemplateInterface extends ContentEntityInterface, RevisionL
* @param int $timestamp
* The Cloud Server Template creation timestamp.
*
* @return \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @return \Drupal\cloud\Entity\CloudServerTemplateInterface
* The called Cloud Server Template entity.
*/
public function setCreatedTime($timestamp);
......@@ -70,7 +70,7 @@ interface CloudServerTemplateInterface extends ContentEntityInterface, RevisionL
* TRUE to set this Cloud Server Template to published, FALSE to set it to
* unpublished.
*
* @return \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @return \Drupal\cloud\Entity\CloudServerTemplateInterface
* The called Cloud Server Template entity.
*/
public function setPublished($published);
......@@ -89,7 +89,7 @@ interface CloudServerTemplateInterface extends ContentEntityInterface, RevisionL
* @param int $timestamp
* The UNIX timestamp of when this revision was created.
*
* @return \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @return \Drupal\cloud\Entity\CloudServerTemplateInterface
* The called Cloud Server Template entity.
*/
public function setRevisionCreationTime($timestamp);
......@@ -108,7 +108,7 @@ interface CloudServerTemplateInterface extends ContentEntityInterface, RevisionL
* @param int $uid
* The user ID of the revision author.
*
* @return \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @return \Drupal\cloud\Entity\CloudServerTemplateInterface
* The called Cloud Server Template entity.
*/
public function setRevisionUserId($uid);
......
<?php
namespace Drupal\cloud_server_template\Entity;
namespace Drupal\cloud\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
......@@ -12,14 +12,14 @@ use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
* label = @Translation("Cloud Server Template type"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\cloud_server_template\CloudServerTemplateTypeListBuilder",
* "list_builder" = "Drupal\cloud\CloudServerTemplateTypeListBuilder",
* "form" = {
* "add" = "Drupal\cloud_server_template\Form\CloudServerTemplateTypeForm",
* "edit" = "Drupal\cloud_server_template\Form\CloudServerTemplateTypeForm",
* "delete" = "Drupal\cloud_server_template\Form\CloudServerTemplateTypeDeleteForm"
* "add" = "Drupal\cloud\Form\CloudServerTemplateTypeForm",
* "edit" = "Drupal\cloud\Form\CloudServerTemplateTypeForm",
* "delete" = "Drupal\cloud\Form\CloudServerTemplateTypeDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\cloud_server_template\Routing\CloudServerTemplateTypeHtmlRouteProvider",
* "html" = "Drupal\cloud\Routing\CloudServerTemplateTypeHtmlRouteProvider",
* },
* },
* config_prefix = "cloud_server_template_type",
......
<?php
namespace Drupal\cloud_server_template\Entity;
namespace Drupal\cloud\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
......
<?php
namespace Drupal\cloud_server_template\Entity;
namespace Drupal\cloud\Entity;
use Drupal\views\EntityViewsData;
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityRepositoryInterface;
......@@ -46,7 +46,7 @@ class CloudServerTemplateForm extends ContentEntityForm {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $cloud_context = '') {
/* @var $entity \Drupal\cloud_server_template\Entity\CloudServerTemplate */
/* @var $entity \Drupal\cloud\Entity\CloudServerTemplate */
$form = parent::buildForm($form, $form_state);
if (!$this->entity->isNew()) {
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManagerInterface;
use Drupal\cloud\Plugin\CloudServerTemplatePluginManagerInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -19,7 +19,7 @@ class CloudServerTemplateLaunchConfirm extends ContentEntityConfirmFormBase {
/**
* The ServerTemplatePluginManager.
*
* @var \Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManager
* @var \Drupal\cloud\Plugin\CloudServerTemplatePluginManager
*/
protected $serverTemplatePluginManager;
......@@ -32,7 +32,7 @@ class CloudServerTemplateLaunchConfirm extends ContentEntityConfirmFormBase {
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\cloud_server_template\Plugin\CloudServerTemplatePluginManagerInterface $server_template_plugin_manager
* @param \Drupal\cloud\Plugin\CloudServerTemplatePluginManagerInterface $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) {
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -22,7 +22,7 @@ class CloudServerTemplateRevisionDeleteForm extends ConfirmFormBase {
/**
* The Cloud Server Template revision.
*
* @var \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @var \Drupal\cloud\Entity\CloudServerTemplateInterface
*/
protected $revision;
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
......@@ -8,7 +8,7 @@ use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Url;
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
use Drupal\cloud\Entity\CloudServerTemplateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -23,7 +23,7 @@ class CloudServerTemplateRevisionRevertForm extends ConfirmFormBase {
/**
* The Cloud Server Template revision.
*
* @var \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @var \Drupal\cloud\Entity\CloudServerTemplateInterface
*/
protected $revision;
......@@ -150,12 +150,12 @@ class CloudServerTemplateRevisionRevertForm extends ConfirmFormBase {
/**
* Prepares a revision to be reverted.
*
* @param \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $revision
* @param \Drupal\cloud\Entity\CloudServerTemplateInterface $revision
* The revision to be reverted.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface
* @return \Drupal\cloud\Entity\CloudServerTemplateInterface
* The prepared revision ready to be stored.
*/
protected function prepareRevertedRevision(CloudServerTemplateInterface $revision, FormStateInterface $form_state) {
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
use Drupal\cloud\Entity\CloudServerTemplateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -93,7 +93,7 @@ class CloudServerTemplateRevisionRevertTranslationForm extends CloudServerTempla
protected function prepareRevertedRevision(CloudServerTemplateInterface $revision, FormStateInterface $form_state) {
$revert_untranslated_fields = $form_state->getValue('revert_untranslated_fields');
/** @var \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $default_revision */
/** @var \Drupal\cloud\Entity\CloudServerTemplateInterface $default_revision */
$latest_revision = $this->CloudServerTemplateStorage->load($revision->id());
$latest_revision_translation = $latest_revision->getTranslation($this->langcode);
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
......
<?php
namespace Drupal\cloud_server_template\Form;
namespace Drupal\cloud\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Messenger\Messenger;
......@@ -59,7 +59,7 @@ class CloudServerTemplateTypeForm extends EntityForm {
'#type' => 'machine_name',
'#default_value' => $cloud_server_template_type->id(),
'#machine_name' => [
'exists' => '\Drupal\cloud_server_template\Entity\CloudServerTemplateType::load',
'exists' => '\Drupal\cloud\Entity\CloudServerTemplateType::load',
],
'#disabled' => !$cloud_server_template_type->isNew(),
];
......
<?php
namespace Drupal\cloud_server_template\Plugin;
namespace Drupal\cloud\Plugin;
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
use Drupal\cloud\Entity\CloudServerTemplateInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Common interfaces for a cloud server template.
*
* @package Drupal\cloud_server_template\Plugin
* @package Drupal\cloud\Plugin
*/
interface CloudServerTemplatePluginInterface {
......@@ -26,7 +26,7 @@ interface CloudServerTemplatePluginInterface {
* The server template contains all the information needed for that particular
* cloud.
*
* @param \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $cloud_server_template
* @param \Drupal\cloud\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.
......
<?php
namespace Drupal\cloud_server_template\Plugin;
namespace Drupal\cloud\Plugin;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
......@@ -9,7 +9,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
use Drupal\cloud\Entity\CloudServerTemplateInterface;
/**
* Provides the default cloud_server_template_plugin manager.
......
<?php
namespace Drupal\cloud_server_template\Plugin;
namespace Drupal\cloud\Plugin;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\cloud_server_template\Entity\CloudServerTemplateInterface;
use Drupal\cloud\Entity\CloudServerTemplateInterface;
use Drupal\Core\Form\FormStateInterface;
/**
......@@ -25,7 +25,7 @@ interface CloudServerTemplatePluginManagerInterface extends PluginManagerInterfa
/**
* Launch a cloud server template.
*
* @param \Drupal\cloud_server_template\Entity\CloudServerTemplateInterface $cloud_server_template
* @param \Drupal\cloud\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.
......
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