node_singles-3.0.2/node_singles.install
node_singles.install
<?php
/**
* @file
* Install, update and uninstall functions for the Node Singles module.
*/
use Drupal\node\Entity\NodeType;
/**
* Set defaults for the new label settings.
*/
function node_singles_update_8001(): void {
$config = \Drupal::configFactory()->getEditable('node_singles.settings');
$values = [
'label' => 'Single',
'label_collection' => 'Singles',
'label_singular' => 'single node',
'label_plural' => 'single nodes',
'label_count' => [
'singular' => '@count single node',
'plural' => '@count single nodes',
],
];
foreach ($values as $key => $value) {
if (!$config->get($key)) {
$config->set($key, $value);
}
}
$config->save();
}
/**
* Fix node type third_party_settings config schema.
*/
function node_singles_update_8002(): void {
foreach (NodeType::loadMultiple() as $nodeType) {
$setting = $nodeType->getThirdPartySetting('node_singles', 'is_single');
if (is_int($setting)) {
$nodeType->setThirdPartySetting('node_singles', 'is_single', (bool) $setting);
$nodeType->save();
}
}
}
