class BehaviorSettingsManager in Rabbit Hole 8
Same name and namespace in other branches
- 2.x src/BehaviorSettingsManager.php \Drupal\rabbit_hole\BehaviorSettingsManager
Provides operations for bundles configuration.
Hierarchy
- class \Drupal\rabbit_hole\BehaviorSettingsManager implements BehaviorSettingsManagerInterface
Expanded class hierarchy of BehaviorSettingsManager
1 string reference to 'BehaviorSettingsManager'
1 service uses BehaviorSettingsManager
File
- src/
BehaviorSettingsManager.php, line 11
Namespace
Drupal\rabbit_holeView source
class BehaviorSettingsManager implements BehaviorSettingsManagerInterface {
/**
* Drupal\Core\Config\ConfigFactory definition.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* Constructor.
*/
public function __construct(ConfigFactory $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public function saveBehaviorSettings(array $settings, $entity_type_id, $entity_id = NULL) {
$id = $this
->generateBehaviorSettingsFullId($entity_type_id, $entity_id);
$entity = BehaviorSettings::load($id);
if ($entity === NULL) {
$entity_array = [
'id' => $id,
];
$entity_array += $settings;
$entity = BehaviorSettings::create($entity_array);
}
else {
foreach ($settings as $key => $setting) {
$entity
->set($key, $setting);
}
}
$entity
->set('entity_type_id', $entity_type_id);
$entity
->set('entity_id', $entity_id);
$entity
->save();
}
/**
* {@inheritdoc}
*/
public function loadBehaviorSettingsAsConfig($entity_type_id, $entity_id = NULL) {
$actual = $this->configFactory
->get('rabbit_hole.behavior_settings.' . $this
->generateBehaviorSettingsFullId($entity_type_id, $entity_id));
if (!$actual
->isNew()) {
return $actual;
}
else {
return $this->configFactory
->get('rabbit_hole.behavior_settings.default');
}
}
/**
* {@inheritdoc}
*/
public function loadBehaviorSettingsAsEditableConfig($entity_type_id, $entity_id, $is_bundle = FALSE) {
$actual = $this->configFactory
->getEditable('rabbit_hole.behavior_settings.' . $this
->generateBehaviorSettingsFullId($entity_type_id, $entity_id));
return !$actual
->isNew() ? $actual : NULL;
}
/**
* Generate a full ID based on entity type label, bundle label and entity id.
*
* @param string $entity_type_id
* The entity type (e.g. node) as a string.
* @param string $entity_id
* The entity ID as a string.
*
* @return string
* The full id appropriate for a BehaviorSettings config entity.
*/
private function generateBehaviorSettingsFullId($entity_type_id, $entity_id = '') {
return $entity_type_id . (isset($entity_id) ? '_' . $entity_id : '');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BehaviorSettingsManager:: |
protected | property | Drupal\Core\Config\ConfigFactory definition. | |
BehaviorSettingsManager:: |
private | function | Generate a full ID based on entity type label, bundle label and entity id. | |
BehaviorSettingsManager:: |
public | function |
Load behaviour settings for an entity or bundle, or load the defaults. Overrides BehaviorSettingsManagerInterface:: |
|
BehaviorSettingsManager:: |
public | function |
Load behaviour settings for an entity or bundle, or return NULL. Overrides BehaviorSettingsManagerInterface:: |
|
BehaviorSettingsManager:: |
public | function |
Save behavior settings for an entity or bundle. Overrides BehaviorSettingsManagerInterface:: |
|
BehaviorSettingsManager:: |
public | function | Constructor. |