Skip to content

Commit

Permalink
feat: Remove the ability for existing events to add new sections
Browse files Browse the repository at this point in the history
  • Loading branch information
codechefmarc committed Sep 14, 2023
1 parent d03fe3a commit 1daa987
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,61 @@ public function updateExistingPageLock() {
}
}

/**
* Update existing events to disable adding more sections.
*/
public function updateExistingEventsLock() {
// Find all event nodes to update existing.
$nids = \Drupal::entityQuery('node')
->accessCheck(FALSE)
->condition('type', 'event')
->execute();

foreach ($nids as $nid) {
$node = Node::load($nid);
$layout = $node->get('layout_builder__layout');

/** @var \Drupal\layout_builder\Field\LayoutSectionItemList $layout */
$sections = $layout->getSections();
foreach ($sections as $section) {
if ($section->getLayoutSettings()['label'] == '') {
$section->setThirdPartySetting(
'layout_builder_lock',
'lock',
[
6 => 6,
7 => 7,
]
);

$this->updateTempStore(function (&$stored_data) {
if ($stored_data->data['section_storage']->getContext('entity')->getContextData()->getEntity()->bundle() == 'event') {
$section_storage = $stored_data->data['section_storage'];
$sections = $section_storage->getSections();
foreach ($sections as $key => $section) {
if ($section->getLayoutSettings()['label'] == '') {
$sectionToUpdate = $key;
}
}
$section_storage
->getSection($sectionToUpdate)
->setThirdPartySetting(
'layout_builder_lock',
'lock',
[
6 => 6,
7 => 7,
]
);
}
});

$node->save();
}
}
}
}

/**
* Updates Post Meta for existing nodes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ function ys_layouts_deploy_9001() {
// Replaces old title section with new post meta block.
$updateExistingNodes->updateExistingPostMeta();
}

/**
* Updates events to disable adding new sections.
*/
function ys_layouts_deploy_9002() {
$updateExistingNodes = new UpdateExistingNodes();
$updateExistingNodes->updateExistingEventsLock();
}

0 comments on commit 1daa987

Please sign in to comment.