You are here

public function BehaviorSettingsManager::saveBehaviorSettings in Rabbit Hole 8

Same name and namespace in other branches
  1. 2.x src/BehaviorSettingsManager.php \Drupal\rabbit_hole\BehaviorSettingsManager::saveBehaviorSettings()

Save behavior settings for an entity or bundle.

Parameters

array $settings: The settings for the BehaviorSettings entity.

string $entity_type_id: The entity type (e.g. node) as a string.

string $entity_id: The entity ID as a string.

Overrides BehaviorSettingsManagerInterface::saveBehaviorSettings

File

src/BehaviorSettingsManager.php, line 30

Class

BehaviorSettingsManager
Provides operations for bundles configuration.

Namespace

Drupal\rabbit_hole

Code

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();
}