function webform_update_8036 in Webform 6.x
Same name and namespace in other branches
- 8.5 includes/webform.install.update.inc \webform_update_8036()
Issue #2867855: Add category support to webform config entity.
File
- includes/
webform.install.update.inc, line 783 - Archived Webform update hooks.
Code
function webform_update_8036() {
// Add an empty category to all webforms.
_webform_update_webform_settings();
// Must resave all Webform config lookup keys.
// @see \Drupal\Core\Config\Entity\Query\QueryFactory::updateConfigKeyStore
/** @var \Drupal\webform\WebformInterface[] $webforms */
$webforms = Webform::loadMultiple();
foreach ($webforms as $webform) {
$title = $webform
->get('title');
if (preg_match('/^(Test: ([^:]+))/', $title, $match)) {
$webform
->set('category', $match[1]);
}
elseif (preg_match('/^Example:/', $title)) {
$webform
->set('category', 'Example');
}
elseif (preg_match('/^Demo:/', $title)) {
$webform
->set('category', 'Demo');
}
else {
$webform
->set('category', '');
}
$webform
->save();
}
}