PanelsDisplayManager.php in Panels 8.3
File
src/PanelsDisplayManager.php
View source
<?php
namespace Drupal\panels;
use Drupal\Core\Config\Schema\SchemaCheckTrait;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Display\VariantManager;
use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
class PanelsDisplayManager implements PanelsDisplayManagerInterface {
use SchemaCheckTrait {
checkConfigSchema as private;
}
protected $variantManager;
protected $typedConfigManager;
public function __construct(VariantManager $variant_manager, TypedConfigManagerInterface $typed_config_manager) {
$this->variantManager = $variant_manager;
$this->typedConfigManager = $typed_config_manager;
}
public function createDisplay($layout = NULL, $builder = NULL) {
$display = $this->variantManager
->createInstance('panels_variant', []);
$display
->setLayout($layout ?: 'onecol');
$display
->setBuilder($builder ?: 'standard');
return $display;
}
protected function validate(array $config) {
$this->configName = 'display_variant.plugin.panels_variant';
$definition = $this->typedConfigManager
->getDefinition($this->configName);
$data_definition = $this->typedConfigManager
->buildDataDefinition($definition, $config);
$this->schema = $this->typedConfigManager
->create($data_definition, $config);
$errors = array();
foreach ($config as $key => $value) {
$errors = array_merge($errors, $this
->checkValue($key, $value));
}
if (!empty($errors)) {
$error_list = [];
foreach ($errors as $key => $error) {
$error_list[] = $key . ': ' . $error;
}
throw new \Exception("Config for Panels display doesn't validate: " . implode(', ', $error_list));
}
}
public function importDisplay(array $config, $validate = TRUE) {
if ($validate) {
$this
->validate($config);
}
return $this->variantManager
->createInstance('panels_variant', $config);
}
public function exportDisplay(PanelsDisplayVariant $display) {
return $display
->getConfiguration();
}
}