Skip to content

Commit

Permalink
FE2-37: Misc checks and formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
searnest-e3 committed Nov 1, 2021
1 parent 8804565 commit d91cccc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
17 changes: 12 additions & 5 deletions docroot/modules/custom/foia_cfo/src/Controller/CFOController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public function getCouncil(): CacheableJsonResponse {
// Title and body of the Council node.
$response['title'] = $council_node->label();

if ($council_node->get('body')) {
if (
!empty($council_node->get('body'))
&& !empty($council_node->get('body')->getValue()[0]['value'])
) {
$body = \Drupal::service('foia_cfo.default')->absolutePathFormatter($council_node->get('body')->getValue()[0]['value']);
$response['body'] = $body;
}
Expand Down Expand Up @@ -279,10 +282,10 @@ public function getCommittees(): CacheableJsonResponse {
* @param \Drupal\node\Entity\Node $committee
* Node object of the committee passed as argument through routing.
*
* @return \Drupal\Core\Cache\CacheableJsonResponse|false
* @return \Drupal\Core\Cache\CacheableJsonResponse
* Returns json object or false if the node did not load.
*/
public function getCommittee(Node $committee) {
public function getCommittee(Node $committee): CacheableJsonResponse {

if (!empty($committee) && $committee->isPublished()) {

Expand All @@ -296,7 +299,11 @@ public function getCommittee(Node $committee) {
];

// Add body HTML if any - use absolute links.
if ($committee->hasField('body') && !empty($committee->get('body'))) {
if (
$committee->hasField('body')
&& !empty($committee->get('body'))
&& !empty($committee->get('body')->getValue()[0]['value'])
) {
$response['committee_body'] = \Drupal::service('foia_cfo.default')->absolutePathFormatter($committee->get('body')->getValue()[0]['value']);
}

Expand All @@ -319,7 +326,7 @@ public function getCommittee(Node $committee) {
else {

// Not a valid committee or not published.
return FALSE;
return new CacheableJsonResponse([]);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public function getMeetings(): CacheableJsonResponse {
* @param \Drupal\node\Entity\Node $meeting
* Node object of the meeting passed as argument through routing.
*
* @return \Drupal\Core\Cache\CacheableJsonResponse|false
* @return \Drupal\Core\Cache\CacheableJsonResponse
* Returns json object or false if the node did not load.
*/
public function getMeeting(Node $meeting) {
public function getMeeting(Node $meeting): CacheableJsonResponse {

if (!empty($meeting) && $meeting->isPublished()) {

Expand Down Expand Up @@ -221,7 +221,7 @@ public function getMeeting(Node $meeting) {
else {

// Not a valid meeting or not published.
return FALSE;
return new CacheableJsonResponse([]);

}

Expand Down

0 comments on commit d91cccc

Please sign in to comment.