iframe_consent-1.0.x-dev/src/Service/IframeConsentSettings.php
src/Service/IframeConsentSettings.php
<?php
namespace Drupal\iframe_consent\Service;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
/**
* Class to handle iframe consent settings.
*
* @package Drupal\iframe_consent\Service
*/
class IframeConsentSettings implements IframeConsentSettingsInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public function get(string $setting_name) {
return $this->getSettings()->get($setting_name);
}
/**
* {@inheritdoc}
*/
public function getConsentGroupLabelById(string $id): string {
$consent_groups = $this->getConsentGroupsList();
return $consent_groups[$id] ?? '';
}
/**
* {@inheritdoc}
*/
public function getConsentGroupsList(): array {
$consent_groups = $this->getSettings()->get('consent_groups') ?? [];
$consent_groups_by_id = [];
foreach ($consent_groups as $group) {
$consent_groups_by_id[$group['id']] = $group['label'];
}
return $consent_groups_by_id;
}
/**
* {@inheritdoc}
*/
public function getProvider(): string {
return $this->getSettings()->get('provider');
}
/**
* {@inheritdoc}
*/
public function getSettings(): ImmutableConfig {
return $this->configFactory->get('iframe_consent.settings');
}
/**
* {@inheritdoc}
*/
public function isEnabled(): bool {
return $this->getSettings()->get('enabled');
}
}
