function gathercontent_update_8401 in GatherContent 8.5
Same name and namespace in other branches
- 8.4 gathercontent.install \gathercontent_update_8401()
Convert previous version mapping type to the new one.
File
- ./
gathercontent.install, line 146 - Install and uninstall script for GatherContent module.
Code
function gathercontent_update_8401() {
$mapping_ids = \Drupal::entityQuery('gathercontent_mapping')
->execute();
if (empty($mapping_ids)) {
throw new Exception("Operation failed: Template not mapped.");
}
foreach ($mapping_ids as $mapping_id) {
$mapping = Mapping::load($mapping_id);
$mapping_data = unserialize($mapping
->getData());
if (!empty($mapping_data)) {
foreach ($mapping_data as &$pane) {
if (!empty($pane['elements']) && (!isset($pane['type']) || $pane['type'] !== 'metatag')) {
foreach ($pane['elements'] as &$field) {
if ($field !== 'title') {
$config = FieldConfig::loadByName('node', $mapping
->getContentType(), $field);
if ($config) {
$id = $config
->id();
if (!empty($id)) {
$field = $id;
}
}
}
}
}
}
$mapping
->setData(serialize($mapping_data));
$mapping
->setUpdatedDrupal(time());
$mapping
->save();
}
}
}