Skip to content

Commit

Permalink
Formatting updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
joegl committed Aug 14, 2023
1 parent 5323232 commit 122b4ef
Showing 1 changed file with 23 additions and 36 deletions.
59 changes: 23 additions & 36 deletions docroot/profiles/sdss/sdss_profile/sdss_profile.install
Original file line number Diff line number Diff line change
Expand Up @@ -31,65 +31,52 @@ function sdss_profile_update_9000(&$sandbox) {
/** @var \Drupal\node\NodeInterface[] $nodes */
$nodes = $node_storage->loadMultiple($node_ids);
foreach ($nodes as $node) {
// Pull all paragraphs off the news nodes.
/** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $components */
$components = $node->get('su_news_components');
// Create empty array to store paragraphs that are not in a layout section.
$unsectioned_paragraphs = [];

// Only continue if the node has components.
if(count($components) > 0 ) {

// Loop through the components.
if (!isEmpty($components)) {
/** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $component */
foreach($components as $component) {
foreach ($components as $component) {
/** @var \Drupal\paragraphs\ParagraphInterface $paragraph */
$paragraph = $paragraph_storage->loadRevision($component->getValue()['target_revision_id']);
$parent_uuid = $paragraph->getBehaviorSetting('layout_paragraphs', 'parent_uuid');
$parent_layout = $paragraph->getBehaviorSetting('layout_paragraphs', 'parent_uuid');

// If the paragraph is already in a layout or the paragraph type IS a
// layout section, do nothing.
if(
!is_null($parent_uuid)
|| $paragraph->getParagraphType()->id() == 'stanford_layout'
) continue;
if (
$parent_layout ||
$paragraph->getParagraphType()->id() == 'stanford_layout'
) {
continue;
}

// Add paragraph to the unsectioned_paragraphs array.
$unsectioned_paragraphs[] = $paragraph;
}

// Check if there are unsectioned paragraphs.
if(count($unsectioned_paragraphs) > 0) {

// Create a stanford_layout paragraph to move un-sectioned components
// into.
$new_paragraph_section = $paragraph_storage->create([
if ($unsectioned_paragraphs) {
$section_paragraph = $paragraph_storage->create([
'type' => 'stanford_layout',
]);
$new_paragraph_section->setBehaviorSettings('layout_paragraphs',
[
$section_paragraph_layout_settings = [
'layout' => 'layout_paragraphs_sdss_1_column',
'parent_uuid' => NULL,
'region' => NULL,
]);
$new_paragraph_section->save();
];
$section_paragraph->setBehaviorSettings('layout_paragraphs', $section_paragraph_layout_settings);
$section_paragraph->save();
$parent_uuid = $section_paragraph->uuid();

// Loop through unsectioned paragraphs.
foreach($unsectioned_paragraphs as $unsectioned_paragraph) {
// Assign the paragraph to the newly created section paragraph and
// save the paragraph.
$unsectioned_paragraph->setBehaviorSettings('layout_paragraphs',
[
foreach ($unsectioned_paragraphs as $unsectioned_paragraph) {
$unsectioned_paragraph_settings = [
'region' => 'main',
'parent_uuid' => $new_paragraph_section->uuid(),
]);
'parent_uuid' => $parent_uuid,
];
$unsectioned_paragraph->setBehaviorSettings('layout_paragraphs', $unsectioned_paragraph_settings);
$unsectioned_paragraph->save();
}

// Add the layout section paragraph to the node and save the node.
$node->su_news_components[] = [
'target_id' => $new_paragraph_section->id(),
'target_revision_id' => $new_paragraph_section->getRevisionId(),
'target_id' => $section_paragraph->id(),
'target_revision_id' => $section_paragraph->getRevisionId(),
];
$node->save();
}
Expand Down

0 comments on commit 122b4ef

Please sign in to comment.