diff --git a/src/Service/UWService.php b/src/Service/UWService.php index de7600a29398ac52ab98570f5a3a35d5178898a0..f379597f31916ef7fb632da346383ccdb34bd8b0 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -136,6 +136,7 @@ class UWService implements UWServiceInterface { 'uw_ct_news_item', 'uw_ct_profile', 'uw_ct_web_page', + 'uw_ct_service', ]; break; diff --git a/src/Service/UwNodeContent.php b/src/Service/UwNodeContent.php index 7cfdc469d25798ffc74aadff55c4081227e56dbc..934ef7e25bdf69fddf7523d2be94650e4668a3ab 100644 --- a/src/Service/UwNodeContent.php +++ b/src/Service/UwNodeContent.php @@ -80,6 +80,10 @@ class UwNodeContent { case 'uw_ct_profile': $content_data = $this->getProfileContent($node_flags); break; + + case 'uw_ct_service': + $content_data = $this->getServiceContent($node_flags); + break; } return $this->uwNodeData->getNodeData($node, $view_mode, $content_data); @@ -526,6 +530,63 @@ class UwNodeContent { return $content_data; } + /** + * Get the node content for service content type. + * + * @param array $node_flags + * The flags for the node. + * + * @return array + * Array of content to get from the node. + */ + public function getServiceContent(array $node_flags): array { + + // Get the content data. + $content_data = $this->setupContentData($node_flags); + + if ($node_flags['get_header']) { + $content_data['header']['status'] = $this->addToContentData('select', 'field_uw_service_status'); + } + + // Setup the actual content. + if ($node_flags['get_content']) { + $content_data['content'] = $this->addToContentData('content', 'field_uw_service_summary'); + } + + // Get the footer for the profile. + if ($node_flags['get_footer']) { + $content_data['footer']['service_information']['has_children'] = TRUE; + $content_data['footer']['service_information']['status'] = $this->addToContentData('select', 'field_uw_service_status'); + $content_data['footer']['service_information']['categories'] = $this->addToContentData('terms', ['field_uw_service_category']); + + $content_data['footer']['service_details']['has_children'] = TRUE; + $content_data['footer']['service_details']['popularity'] = $this->addToContentData('plain_text', 'field_uw_service_popularity'); + $content_data['footer']['service_details']['use_service'] = $this->addToContentData( + 'terms', + [ + 'field_uw_service_audience', + ] + ); + $content_data['footer']['service_details']['whats_available'] = $this->addToContentData('multiple_plain_text', 'field_uw_service_available'); + $content_data['footer']['service_details']['request_service'] = $this->addToContentData('formatted_text', 'field_uw_service_request'); + $content_data['footer']['service_details']['minimum_notice'] = $this->addToContentData('plain_text', 'field_uw_service_notice'); + $content_data['footer']['service_details']['average_length'] = $this->addToContentData('plain_text', 'field_uw_service_length'); + $content_data['footer']['service_details']['pricing_cost'] = $this->addToContentData('formatted_text', 'field_uw_service_cost'); + $content_data['footer']['service_details']['support'] = $this->addToContentData('formatted_text', 'field_uw_service_support'); + + $content_data['footer']['service_hours']['has_children'] = TRUE; + $content_data['footer']['service_hours']['hours'] = $this->addToContentData('hours', 'field_uw_service_hours'); + + $content_data['footer']['location_info'] = [ + 'has_children' => TRUE, + 'address' => $this->addToContentData('address', 'field_uw_service_location', 'Location address'), + 'map' => $this->addToContentData('map', 'field_uw_service_location_coord', 'Location coordinates'), + ]; + } + + return $content_data; + } + /** * Gets the most recent date. * diff --git a/src/Service/UwNodeFieldValue.php b/src/Service/UwNodeFieldValue.php index 8639d8b124d7b464a2e8bc3d670f3bd1977c7cee..794ac06d6b552e31d8153bb772f3d07dccebd249 100644 --- a/src/Service/UwNodeFieldValue.php +++ b/src/Service/UwNodeFieldValue.php @@ -103,7 +103,14 @@ class UwNodeFieldValue { // Office hours field type. if ($type == 'hours') { - return $node->$field_name->view(); + + $hours = $node->$field_name->view(); + if (isset($hours['#title'])) { + return $hours; + } + else { + return []; + } } // Date field type (smart dates). @@ -111,6 +118,11 @@ class UwNodeFieldValue { return $this->getDates($node, $field_name, $view_mode); } + // Select list field. + if ($type == 'select') { + return $node->$field_name->value; + } + // Taxonomy terms field type. if ($type == 'terms') { return $this->getTermsField($node, $field_name); @@ -132,8 +144,13 @@ class UwNodeFieldValue { } // Plain text field type (textbox). - if ($type == 'plain_text') { - return $node->$field_name->value; + if ($type == 'plain_text' || $type == 'multiple_plain_text') { + if ($type == 'multiple_plain_text') { + return $this->getPlainText($node, $field_name, TRUE); + } + else { + return $this->getPlainText($node, $field_name); + } } // Source or hero image field type. @@ -237,6 +254,44 @@ class UwNodeFieldValue { return $tags; } + /** + * Gets a plain text field or fields. + * + * @param \Drupal\node\Entity\Node $node + * The node. + * @param string $field_name + * The field name. + * @param bool $multiple + * Flag if multiple plain text. + * + * @return mixed + * Plain text values. + */ + public function getPlainText(Node $node, string $field_name, bool $multiple = FALSE) { + + $plain_text = []; + + // If there are no multiple plain text, just return value. + // If there are multiple plain text, step through and + // get the values. + if (!$multiple) { + return $node->$field_name->value; + } + else { + + // Get the values of the plain text field. + $values = $node->$field_name->getValue(); + + // Step through each and get the actual value. + foreach ($values as $value) { + $plain_text[] = $value['value']; + } + + // Return array of plain text. + return $plain_text; + } + } + /** * Prepares image for theme. * @@ -497,6 +552,8 @@ class UwNodeFieldValue { * * @return array * List of terms with name and link. + * + * @throws \Drupal\Core\Entity\EntityMalformedException */ public function getTermsFromEntityField(EntityReferenceFieldItemListInterface $values, string $type = NULL): array { @@ -586,6 +643,7 @@ class UwNodeFieldValue { * A converted date to a string. */ public function getDate(array $date, string $type): string { + $return_date = ''; if ($type == 'event') { @@ -608,6 +666,7 @@ class UwNodeFieldValue { $return_date = date(self::DATE_FORMAT_DATE_ONLY, $date['value']) . ' (all day)'; } } + return $return_date; }