ConfigManagerService.php in Layout Builder Base 8
File
src/ConfigManagerService.php
View source
<?php
namespace Drupal\layout_builder_base;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\layout_builder_base\Form\SettingsForm;
class ConfigManagerService implements ConfigManagerServiceInterface {
protected $configFactory;
protected $layoutBuilderBaseSettings;
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
$this->layoutBuilderBaseSettings = $config_factory
->get('layout_builder_base.settings');
}
public function getOverrideOptionsFromPropertyName($property) {
$options = [];
$config_name = SettingsForm::getOverrideConfigName($property);
$config_value = $this->layoutBuilderBaseSettings
->get($config_name);
if (!empty($config_value)) {
$options_values = explode(PHP_EOL, $config_value);
foreach ($options_values as $option_value) {
$data = array_map('trim', explode('|', $option_value));
$options[$data[0]] = count($data) === 2 ? $data[1] : $data[0];
}
}
return $options;
}
public function getMergedOptionsWithOverrides(array $options, $property) {
$override_options = $this
->getOverrideOptionsFromPropertyName($property);
if (in_array('<none>', $override_options)) {
$options = [];
}
else {
$options = !empty($override_options) ? $override_options : $options;
}
return $options;
}
}