function commerce_bulk_install in Commerce Bulk 8
Implements hook_install().
File
- ./
commerce_bulk.install, line 13 - Install and uninstall functions for the commerce_bulk module.
Code
function commerce_bulk_install() {
$config = \Drupal::configFactory();
$all = $config
->listAll('core.entity_form_display.commerce_product_variation.');
foreach ($all as $name) {
$variation = $config
->getEditable($name);
if (!$variation
->get('hidden.sku')) {
$sku = $variation
->get('content.sku');
}
else {
$hidden = $variation
->get('hidden');
unset($hidden['sku']);
$variation
->set('hidden', $hidden);
$sku = [
'settings' => [
'size' => 60,
'placeholder' => "",
],
'weight' => -4,
'region' => 'content',
'third_party_settings' => [],
];
}
$sku['type'] = 'commerce_bulk_sku';
$sku['settings'] += [
'custom_label' => "",
'uniqid_enabled' => TRUE,
'more_entropy' => FALSE,
'hide' => FALSE,
'prefix' => "sku-",
'suffix' => "",
'maximum' => 500,
];
$variation
->set('content.sku', $sku);
$variation
->save();
}
}