class PanelsDisplayManager in Panels 8.4
Same name and namespace in other branches
- 8.3 src/PanelsDisplayManager.php \Drupal\panels\PanelsDisplayManager
A service that manages Panels displays.
Hierarchy
- class \Drupal\panels\PanelsDisplayManager implements PanelsDisplayManagerInterface uses SchemaCheckTrait
Expanded class hierarchy of PanelsDisplayManager
1 string reference to 'PanelsDisplayManager'
1 service uses PanelsDisplayManager
File
- src/
PanelsDisplayManager.php, line 13
Namespace
Drupal\panelsView source
class PanelsDisplayManager implements PanelsDisplayManagerInterface {
use SchemaCheckTrait {
checkConfigSchema as private;
}
/**
* @var \Drupal\Core\Display\VariantManager
*/
protected $variantManager;
/**
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
/**
* @param \Drupal\Core\Display\VariantManager $variant_manager
*/
public function __construct(VariantManager $variant_manager, TypedConfigManagerInterface $typed_config_manager) {
$this->variantManager = $variant_manager;
$this->typedConfigManager = $typed_config_manager;
}
/**
* {@inheritdoc}
*/
public function createDisplay($layout = NULL, $builder = NULL) {
$display = $this->variantManager
->createInstance('panels_variant', []);
// Set the default builder and layout.
// @todo: load the defaults from config somewhere.
$display
->setLayout($layout ?: 'layout_onecol');
$display
->setBuilder($builder ?: 'standard');
return $display;
}
/**
* Validates the config against the schema.
*
* @param array $config
* The configuration data.
*
* @throws \Exception
* If the configuration doesn't validate.
*/
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));
}
}
/**
* {@inheritdoc}
*/
public function importDisplay(array $config, $validate = TRUE) {
// Validate against the schema if requested.
if ($validate) {
$this
->validate($config);
}
return $this->variantManager
->createInstance('panels_variant', $config);
}
/**
* {@inheritdoc}
*/
public function exportDisplay(PanelsDisplayVariant $display) {
return $display
->getConfiguration();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PanelsDisplayManager:: |
protected | property | ||
PanelsDisplayManager:: |
protected | property | ||
PanelsDisplayManager:: |
public | function |
Create a new panels display. Overrides PanelsDisplayManagerInterface:: |
|
PanelsDisplayManager:: |
public | function |
Export configuration from a panels display. Overrides PanelsDisplayManagerInterface:: |
|
PanelsDisplayManager:: |
public | function |
Creates a panels display from exported configuration. Overrides PanelsDisplayManagerInterface:: |
|
PanelsDisplayManager:: |
protected | function | Validates the config against the schema. | |
PanelsDisplayManager:: |
public | function | ||
SchemaCheckTrait:: |
protected | property | The configuration object name under test. | |
SchemaCheckTrait:: |
protected | property | The config schema wrapper object for the configuration object under test. | |
SchemaCheckTrait:: |
public | function | Checks the TypedConfigManager has a valid schema for the configuration. | |
SchemaCheckTrait:: |
protected | function | Helper method to check data type. |