From 2e57fbfee6a546d1169506be98699c1b80efffa4 Mon Sep 17 00:00:00 2001 From: bach Date: Tue, 20 Jun 2023 18:26:15 +0200 Subject: [PATCH] related flag missing bug fix in materio_flag module --- .../src/Controller/MaterioFlagController.php | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/web/modules/custom/materio_flag/src/Controller/MaterioFlagController.php b/web/modules/custom/materio_flag/src/Controller/MaterioFlagController.php index 01819af6..7eac230f 100644 --- a/web/modules/custom/materio_flag/src/Controller/MaterioFlagController.php +++ b/web/modules/custom/materio_flag/src/Controller/MaterioFlagController.php @@ -65,32 +65,42 @@ class MaterioFlagController extends ControllerBase { $data = []; foreach ($colls as $id => $collection) { - $flag_id = $collection->getRelatedFlag()->id(); + $relatedflag = $collection->getRelatedFlag(); + if ($relatedflag) { + $flag_id = $relatedflag->id(); + + // get the items + $itemsids = $this->flagListsService->getFlagListItemIds($flag_id,$id); + $items = []; + foreach ($this->flagListsService->getFlagListItems($itemsids) as $id => $item) { + // $items[] = array( + // 'id' => $id, + // 'name' => $item->getName(), + // 'connected_entity_id' => $item->getConnectedEntityId(), + // ); + $items[] = (int)$item->getConnectedEntityId(); + } + // $items_uuids = []; + // foreach ($items as $nid) { + // $node = $this->entityTypeManager->getStorage('node')->load($nid); + // $items_uuids[] = $node->uuid(); + // } + + $data[$collection->id()] = array( + "id" => $collection->id(), + "name" => $collection->getName(), + "flag_id" => $flag_id, + "items" => $items + // "items_uuids" => $items_uuids + ); + } else { + \Drupal::logger('materio_flag')->notice('%colname (%colid): Collection\'s Related flag does not exists.', + [ + '%colid' => $collection->id(), + '%colname' => $collection->getName() + ]); - // get the items - $itemsids = $this->flagListsService->getFlagListItemIds($flag_id,$id); - $items = []; - foreach ($this->flagListsService->getFlagListItems($itemsids) as $id => $item) { - // $items[] = array( - // 'id' => $id, - // 'name' => $item->getName(), - // 'connected_entity_id' => $item->getConnectedEntityId(), - // ); - $items[] = (int)$item->getConnectedEntityId(); } - // $items_uuids = []; - // foreach ($items as $nid) { - // $node = $this->entityTypeManager->getStorage('node')->load($nid); - // $items_uuids[] = $node->uuid(); - // } - - $data[$collection->id()] = array( - "id" => $collection->id(), - "name" => $collection->getName(), - "flag_id" => $flag_id, - "items" => $items - // "items_uuids" => $items_uuids - ); } return new JsonResponse($data);