Skip to content
Snippets Groups Projects
Commit bc36cf0b authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-5128: adding services to node theming

parent acfcb78a
No related branches found
No related tags found
1 merge request!172Feature/istwcms 5128 ebremner theme node services
......@@ -136,6 +136,7 @@ class UWService implements UWServiceInterface {
'uw_ct_news_item',
'uw_ct_profile',
'uw_ct_web_page',
'uw_ct_service',
];
break;
......
......@@ -78,6 +78,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);
......@@ -515,6 +519,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.
*
......
......@@ -96,7 +96,13 @@ 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).
......@@ -104,6 +110,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);
......@@ -125,8 +136,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.
......@@ -230,6 +246,42 @@ class UwNodeFieldValue {
return $tags;
}
/**
* Gets a plain text field or fields.
*
* @param 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) {
// 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;
}
}
/**
* {@inheritDoc}
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment