Skip to content

Commit 401d867

Browse files
authored
Merge pull request #59 from ASUWebPlatforms/WS2-1557
WS2-1557: Add validation when Degree listing page does not exist
2 parents 5b402fe + f9ad4cd commit 401d867

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Controller/AsuDegreePagesCreation.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Symfony\Component\DependencyInjection\ContainerInterface;
1010
use Drupal\asu_degree_rfi\AsuDegreeRfiDegreeSearchClient;
1111
use Drupal\asu_degree_rfi\AsuDegreeRfiInterface;
12+
use Symfony\Component\HttpFoundation\Response;
1213

1314
/**
1415
* Controller for the RFI component proxy to the Submit Handler Lambda.
@@ -39,8 +40,15 @@ public function load() {
3940
$path = \Drupal::service('path.current')->getPath();
4041
$pattern_url = AsuDegreeRfiInterface::ASU_DEGREE_RFI_DETAIL_PATH_PATTERN;
4142

43+
$node_storage = \Drupal::service('entity_type.manager')->getStorage('node');
44+
$split_path = explode('/', $path);
45+
46+
// Check if the Degree listing page exists.
47+
if ($split_path[6] == NULL || $node_storage->loadByProperties(['nid' => $split_path[6], 'type' => 'degree_listing_page']) == NULL) {
48+
return new Response(t('The Degree listing page with nid: @nid could not be found', ['@nid' => $split_path[6]]), 404);
49+
}
50+
4251
if (preg_match($pattern_url, $path)) {
43-
$split_path = explode('/', $path);
4452
$node = Node::create(['type' => 'degree_detail_page']);
4553
$degree_query = $this->degreeSearchClient->getDegreeByAcadPlan($split_path[3]);
4654
$title = isset($degree_query[0]['Descr100']) ? $degree_query[0]['Descr100'] : $split_path[3];

0 commit comments

Comments
 (0)