Skip to content
Snippets Groups Projects
Commit e753c3e5 authored by Davyd Burianuvatyi's avatar Davyd Burianuvatyi
Browse files

Issue #3388288: Update Contact/Hours behavior

parent 518ac9fe
No related branches found
No related tags found
1 merge request!18feat: Issue [#3388288]: Update Contact/Hours behavior
......@@ -13,7 +13,7 @@
*/
getDayOfWeek: function (tz) {
// ISO day of week. returns a string of day of week, e.g. Mon, Tue, etc.
return moment().tz(tz).format('DDD');
return moment().tz(tz).format('ddd');
},
/**
......@@ -45,6 +45,7 @@
$todayHours.html(exceptions[todayString]);
}
else {
console.log(222);
$todayHours.html(hoursData[dayOfWeek]);
}
}
......
......@@ -6,7 +6,7 @@ branch_hours:
assets/css/branch-hours.css: { preprocess: true }
hours_today:
version: 1.1
version: 1.2
js:
assets/js/hours_today.js: { minified: false }
dependencies:
......
......@@ -3,6 +3,7 @@
namespace Drupal\lb_branch_hours_blocks\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Render\Markup;
......@@ -43,6 +44,13 @@ class BranchHoursBlock extends BlockBase implements ContainerFactoryPluginInterf
*/
protected $node;
/**
* Current node
*
* @var \Drupal\node\Entity\Node
*/
protected $node_current;
/**
* Branch Hours Helper service.
*
......@@ -115,6 +123,7 @@ class BranchHoursBlock extends BlockBase implements ContainerFactoryPluginInterf
$this->node = reset($entities);
}
else if ($node->hasField('field_facility_loc') && !$node->get('field_facility_loc')->isEmpty()) {
$this->node_current = $node;
$entities = $node->get('field_facility_loc')->referencedEntities();
$this->node = reset($entities);
}
......@@ -124,8 +133,16 @@ class BranchHoursBlock extends BlockBase implements ContainerFactoryPluginInterf
return [];
}
$branch_hours = $this->branchHoursHelper->getBranchHours($this->node);
$holiday_hours = $this->branchHoursHelper->getBranchHolidayHours($this->node);
if ($this->node_current &&
$this->node_current->hasField('field_branch_hours') &&
!$this->node_current->get('field_branch_hours')->isEmpty()) {
$branch_hours = $this->branchHoursHelper->getBranchHours($this->node_current);
$holiday_hours = $this->branchHoursHelper->getBranchHolidayHours($this->node_current);
}
else {
$branch_hours = $this->branchHoursHelper->getBranchHours($this->node);
$holiday_hours = $this->branchHoursHelper->getBranchHolidayHours($this->node);
}
$build = [
'branch_name' => [
......@@ -139,7 +156,7 @@ class BranchHoursBlock extends BlockBase implements ContainerFactoryPluginInterf
'#type' => 'inline_template',
'#template' => '<a href="tel:{{ branch_phone }}"><i class="fa fa-phone" aria-hidden="true"></i> {{ branch_phone }} </a>',
'#context' => [
'branch_phone' => $this->node->field_location_phone->value,
'branch_phone' => $this->getOverriddenField('field_location_phone')->value,
],
],
'branch_address' => [
......@@ -153,7 +170,7 @@ class BranchHoursBlock extends BlockBase implements ContainerFactoryPluginInterf
'#type' => 'inline_template',
'#template' => '<a href="mailto:{{ branch_email }}"><i class="fas fa-envelope"></i> {{ branch_email }} </a>',
'#context' => [
'branch_email' => $this->node->field_location_email->value,
'branch_email' => $this->getOverriddenField('field_location_email')->value,
],
],
'branch_today_hours' => [
......@@ -202,7 +219,7 @@ class BranchHoursBlock extends BlockBase implements ContainerFactoryPluginInterf
* @return \Drupal\Component\Render\MarkupInterface|string
*/
protected function getAddress() {
$address = $this->node->get('field_location_address')->first();
$address = $this->getOverriddenField('field_location_address')->first();
if ($address) {
$address_array = $address->toArray();
$location_address = "{$address_array['address_line1']}, {$address_array['locality']}<br /> {$address_array['administrative_area']} {$address_array['postal_code']}";
......@@ -223,4 +240,20 @@ class BranchHoursBlock extends BlockBase implements ContainerFactoryPluginInterf
return [];
}
/**
* Get the field from the current node if is not empty or from a related location node
*
* @param string $fieldName
* @return FieldItemListInterface field value
*/
protected function getOverriddenField($fieldName) {
if ($this->node_current &&
$this->node_current->hasField($fieldName) &&
!$this->node_current->get($fieldName)->isEmpty()) {
return $this->node_current->get($fieldName);
}
return $this->node->get($fieldName);
}
}
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