Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lb_branch_hours_blocks
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
lb_branch_hours_blocks
Commits
e753c3e5
Commit
e753c3e5
authored
1 year ago
by
Davyd Burianuvatyi
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3388288
: Update Contact/Hours behavior
parent
518ac9fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
feat: Issue [#3388288]: Update Contact/Hours behavior
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
assets/js/hours_today.js
+2
-1
2 additions, 1 deletion
assets/js/hours_today.js
lb_branch_hours_blocks.libraries.yml
+1
-1
1 addition, 1 deletion
lb_branch_hours_blocks.libraries.yml
src/Plugin/Block/BranchHoursBlock.php
+38
-5
38 additions, 5 deletions
src/Plugin/Block/BranchHoursBlock.php
with
41 additions
and
7 deletions
assets/js/hours_today.js
+
2
−
1
View file @
e753c3e5
...
...
@@ -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
]);
}
}
...
...
This diff is collapsed.
Click to expand it.
lb_branch_hours_blocks.libraries.yml
+
1
−
1
View file @
e753c3e5
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Block/BranchHoursBlock.php
+
38
−
5
View file @
e753c3e5
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment