Skip to content
Snippets Groups Projects
Commit 59fda418 authored by Martin Leblanc's avatar Martin Leblanc
Browse files

Merge branch 'feature/ISTWCMS-5128-ebremner-theme-node-services' into '1.0.x'

Feature/istwcms 5128 ebremner theme node services

See merge request !172
parents f0eb46b4 523b82f0
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;
......
......@@ -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.
*
......
......@@ -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;
}
......
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