Skip to content
Snippets Groups Projects

WCMS-870: Fixing E/C usecase where saved nid is not numeric.

Merged Igor Biki requested to merge feature/WCMS-870-ibiki-expand_collapse_nid_not_numeric into 1.1.x
@@ -275,13 +275,20 @@ class UwCblExpandCollapse extends BlockBase implements ContainerFactoryPluginInt
$node = NULL;
// If there is an e/c group, load in the node. If
// there is not, we are on a add more call with no group
// there is not, we are on an add more call with no group
// set yet.
if (isset($ecs[$i]['group']) && $ecs[$i]['group'] !== NULL) {
if (!empty($ecs[$i]['group']) && ($nid = (int) $ecs[$i]['group']) !== 0) {
// Load the node based on the nid.
$node = $this->entityTypeManager->getStorage('node')->load($ecs[$i]['group']);
$node = EntityAutocomplete::getEntityLabels([$node]);
$node = $this->entityTypeManager->getStorage('node')->load($nid);
if ($node) {
$node = EntityAutocomplete::getEntityLabels([$node]);
}
// If node is not loaded, skip ec block.
else {
continue;
}
}
// The first column of the table, that will house the arrows
@@ -332,8 +339,8 @@ class UwCblExpandCollapse extends BlockBase implements ContainerFactoryPluginInt
];
// Get the operations links based on if this has a group.
if (isset($ecs[$i]['group'])) {
$links = $this->uwExpandCollapseGetOperationsLinks($ecs[$i]['group']);
if (($nid = (int) $ecs[$i]['group']) !== 0) {
$links = $this->uwExpandCollapseGetOperationsLinks($nid);
}
else {
$links = $this->uwExpandCollapseGetOperationsLinks();
@@ -570,11 +577,37 @@ class UwCblExpandCollapse extends BlockBase implements ContainerFactoryPluginInt
// Step through each item and get only the ecs
// that are not empty.
foreach ($items as $item) {
foreach ($items as $index => $item) {
// Get the value of the group.
$group = $this->getGroupFromInput($item['group_info']['group']);
// If the group is null, just continue on, the block
// submit will take care of removing it later.
if ($group === NULL) {
continue;
}
// Validate group is numeric (node id), and also if it is, that it points
// to correct content type node (expand collapse group).
if (($nid = (int) $group)) {
$node = $this->entityTypeManager->getStorage('node')->loadByProperties([
'type' => 'uw_ct_expand_collapse_group',
'nid' => $nid,
]);
if (!$node) {
$error = $this->t('There are no matching expand/collapse groups found.');
$form_state->setError($cf['settings']['items_fieldset']['items'][$index]['group_info']['group'], $error);
return;
}
}
else {
$error = $this->t('There are no content items matching "@item"', ['@item' => $item['group_info']['group']]);
$form_state->setError($cf['settings']['items_fieldset']['items'][$index]['group_info']['group'], $error);
return;
}
// Get the actual entered value.
$item = $item['group_info']['group'];
Loading