DashboardLazyBuildBase.php in Dashboards with Layout Builder 8
File
src/Plugin/DashboardLazyBuildBase.php
View source
<?php
namespace Drupal\dashboards\Plugin;
use Drupal\Component\Serialization\Json;
abstract class DashboardLazyBuildBase extends DashboardBase implements DashboardLazyBuildInterface {
public static function lazyBuildPreRender(string $pluginId, string $configuration) : array {
$configuration = Json::decode($configuration);
$plugin = \Drupal::service('plugin.manager.dashboard')
->createInstance($pluginId, $configuration);
return static::lazyBuild($plugin, $configuration);
}
public function buildRenderArray($configuration) : array {
return [
'#lazy_builder' => [
static::class . '::lazyBuildPreRender',
[
$this
->getPluginId(),
Json::encode($configuration),
],
],
'#create_placeholder' => TRUE,
];
}
}