Skip to content
Snippets Groups Projects

ISTWCMS-7275: Rename "publication" to "reference" in custom block.

Open Igor Biki requested to merge feature/ISTWCMS-7275-ibiki-publications_rename into 1.1.x
1 file
+ 60
8
Compare changes
  • Side-by-side
  • Inline
@@ -19,6 +19,9 @@ function uw_custom_blocks_post_update_references_block_titles_updates(&$sandbox)
// Has to use batching, for all!!!! Maybe splitting it to 3 (node, rev, temp).
// Extrapolate common functionality into a separate function to process
// sections/components.
// $storage = \Drupal::entityTypeManager()->getStorage('node');
// $query = $storage->getQuery();
$query = \Drupal::entityQuery('node');
@@ -30,7 +33,7 @@ function uw_custom_blocks_post_update_references_block_titles_updates(&$sandbox)
$operations[] = [
'_uw_custom_blocks_post_update_references_block_titles_updates_batch_start',
[$count],
$count,
];
foreach ($chunks as $chunk) {
@@ -40,6 +43,10 @@ function uw_custom_blocks_post_update_references_block_titles_updates(&$sandbox)
];
}
$operations[] = [
'_uw_custom_blocks_post_update_references_block_titles_updates_batch_temp_storage',
];
$batch = [
'title' => t('Updating block titles.'),
'progressive' => TRUE,
@@ -53,19 +60,25 @@ function uw_custom_blocks_post_update_references_block_titles_updates(&$sandbox)
function _uw_custom_blocks_post_update_references_block_titles_updates_batch_start($count, &$context): void {
$context['results']['total'] = $count;
$context['results']['processed'] = 0;
$context['results']['updated'] = 0;
}
function _uw_custom_blocks_post_update_references_block_titles_updates_operation($nid, &$context): void {
if (!isset($context['results']['processed'])) {
$context['results']['processed'] = 0;
}
$node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
$node->setSyncing(TRUE);
$save_needed = FALSE;
if ($node) {
$node->setSyncing(TRUE);
$save_needed = FALSE;
$layout_builder = $node->get('layout_builder__layout');
if ($layout_builder) {
foreach ($layout_builder->getSections() as &$section) {
foreach ($section?->getComponents() as &$component) {
foreach ($section?->getComponents() as $component) {
if ($component->getPluginId() == 'uw_cbl_publication_search') {
$configuration = $component->get('configuration');
@@ -81,15 +94,54 @@ function _uw_custom_blocks_post_update_references_block_titles_updates_operation
if ($save_needed) {
$node->save();
$context['results']['updated']++;
}
}
$revisions = \Drupal::entityTypeManager()->getStorage('node')->revisionIds($node);;
if (!isset($context['results']['processed'])) {
$context['results']['processed'] = 0;
foreach ($revisions as $revision) {
$revision = \Drupal::entityTypeManager()->getStorage('node')->loadRevision($revision);
if ($revision) {
$revision->setSyncing(TRUE);
$revision_save_needed = FALSE;
$layout_builder = $revision->get('layout_builder__layout');
if ($layout_builder) {
foreach ($layout_builder->getSections() as &$section) {
foreach ($section?->getComponents() as $component) {
if ($component->getPluginId() == 'uw_cbl_publication_search') {
$configuration = $component->get('configuration');
if ($configuration['label'] == 'Publication reference search') {
$configuration['label'] = 'Reference search';
$component->set('configuration', $configuration);
$revision_save_needed = TRUE;
}
}
}
}
}
if ($revision_save_needed) {
$revision->save();
$context['results']['updated']++;
}
$context['results']['processed']++;
}
}
$context['results']['processed']++;
}
$context['results']['processed']++;
}
function _uw_custom_blocks_post_update_references_block_titles_updates_batch_temp_storage(&$context) {
// Make sure to load temp storage, and loop over sections there.
}
function _uw_custom_blocks_post_update_references_block_titles_updates_finished($success, $results) {
Loading