Skip to content
Snippets Groups Projects
Commit 2775c437 authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3087534 by Xiaohua Guan, yas: Fix "Error: Call to a member function buildListHeader()"

parent 12053f39
No related branches found
No related tags found
No related merge requests found
......@@ -15,4 +15,4 @@ services:
plugin.manager.cloud_server_template_plugin:
class: Drupal\cloud\Plugin\cloud\server_template\CloudServerTemplatePluginManager
arguments: ['@module_handler', '@cache.discovery']
arguments: ['@module_handler', '@cache.discovery', '@string_translation', '@messenger']
......@@ -8,7 +8,10 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\cloud\Entity\CloudServerTemplateInterface;
/**
......@@ -16,6 +19,15 @@ use Drupal\cloud\Entity\CloudServerTemplateInterface;
*/
class CloudServerTemplatePluginManager extends DefaultPluginManager implements CloudServerTemplatePluginManagerInterface {
use StringTranslationTrait;
/**
* The Messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
private $messenger;
/**
* Provides default values for all cloud_server_template_plugin plugins.
*
......@@ -33,11 +45,25 @@ class CloudServerTemplatePluginManager extends DefaultPluginManager implements C
* The module handler.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
*/
public function __construct(ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend) {
public function __construct(
ModuleHandlerInterface $module_handler,
CacheBackendInterface $cache_backend,
TranslationInterface $string_translation,
MessengerInterface $messenger
) {
// Add more services as required.
$this->moduleHandler = $module_handler;
$this->setCacheBackend($cache_backend, 'cloud_server_template_plugin', ['cloud_server_template_plugin']);
// Setup the $this->t().
$this->stringTranslation = $string_translation;
$this->messenger = $messenger;
}
/**
......@@ -82,6 +108,7 @@ class CloudServerTemplatePluginManager extends DefaultPluginManager implements C
break;
}
}
return $plugin;
}
......@@ -90,6 +117,23 @@ class CloudServerTemplatePluginManager extends DefaultPluginManager implements C
*/
public function launch(CloudServerTemplateInterface $cloud_server_template, FormStateInterface $form_state = NULL) {
$plugin = $this->loadPluginVariant($cloud_server_template->getCloudContext());
if ($plugin === FALSE) {
$message = $this->t(
'Cannot load cloud server template plugin: %cloud_context', [
'%cloud_context' => $cloud_server_template->getCloudContext(),
]
);
$this->messenger->addMessage($message);
return [
'route_name' => 'entity.cloud_server_template.canonical',
'params' => [
'cloud_server_template' => $cloud_server_template->id(),
'cloud_context' => $cloud_server_template->getCloudContext(),
],
];
}
return $plugin->launch($cloud_server_template, $form_state);
}
......@@ -98,6 +142,16 @@ class CloudServerTemplatePluginManager extends DefaultPluginManager implements C
*/
public function buildListHeader($cloud_context) {
$plugin = $this->loadPluginVariant($cloud_context);
if ($plugin === FALSE) {
$message = $this->t(
'Cannot load cloud server template plugin: %cloud_context', [
'%cloud_context' => $cloud_context,
]
);
$this->messenger->addMessage($message);
return [];
}
return $plugin->buildListHeader();
}
......@@ -106,6 +160,16 @@ class CloudServerTemplatePluginManager extends DefaultPluginManager implements C
*/
public function buildListRow(CloudServerTemplateInterface $entity) {
$plugin = $this->loadPluginVariant($entity->getCloudContext());
if ($plugin === FALSE) {
$message = $this->t(
'Cannot load cloud server template plugin: %cloud_context', [
'%cloud_context' => $entity->getCloudContext(),
]
);
$this->messenger->addMessage($message);
return [];
}
return $plugin->buildListRow($entity);
}
......
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