Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
ws_event
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
ws_event
Commits
c8e8ca83
Commit
c8e8ca83
authored
2 years ago
by
Davyd Burianuvatyi
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3341675
: Add data for create event in calendar
parent
f2b5fc6f
Branches
Branches containing commit
Tags
1.0.13
Tags containing commit
1 merge request
!16
Resolve #3343868 "Initial implementation"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/Block/EventInfoBlock.php
+63
-2
63 additions, 2 deletions
src/Plugin/Block/EventInfoBlock.php
templates/block--lb-event-info.html.twig
+13
-1
13 additions, 1 deletion
templates/block--lb-event-info.html.twig
with
76 additions
and
3 deletions
src/Plugin/Block/EventInfoBlock.php
+
63
−
2
View file @
c8e8ca83
...
...
@@ -3,12 +3,16 @@
namespace
Drupal\ws_event\Plugin\Block
;
use
Drupal\Core\Block\BlockBase
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Link
;
use
Drupal\Core\Logger\LoggerChannelFactoryInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Render\Markup
;
use
Drupal\Core\Routing\CurrentRouteMatch
;
use
Drupal\Core\Url
;
use
Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface
;
use
Drupal\node\NodeInterface
;
use
Drupal\ws_event
\EventDataHelper
;
use
LinkedIn\Exception
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
...
...
@@ -53,6 +57,13 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
*/
protected
$eventDataHelper
;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
* Constructs a new EventInfoBlock instance.
*
...
...
@@ -70,12 +81,13 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
* * @param \Drupal\ws_event\EventDataHelper $eventDataHelper
* Event data helper service.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
CurrentRouteMatch
$currentRouteMatch
,
EventDataHelper
$eventDataHelper
,
LoggerChannelFactoryInterface
$loggerFactory
)
{
public
function
__construct
(
array
$configuration
,
$plugin_id
,
$plugin_definition
,
CurrentRouteMatch
$currentRouteMatch
,
EventDataHelper
$eventDataHelper
,
LoggerChannelFactoryInterface
$loggerFactory
,
EntityTypeManagerInterface
$entityTypeManager
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
currentRouteMatch
=
$currentRouteMatch
;
$this
->
eventDataHelper
=
$eventDataHelper
;
$this
->
node
=
$currentRouteMatch
->
getParameter
(
'node'
);
$this
->
logger
=
$loggerFactory
->
get
(
'y_lb'
);
$this
->
entityTypeManager
=
$entityTypeManager
;
}
/**
...
...
@@ -88,7 +100,8 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
$plugin_definition
,
$container
->
get
(
'current_route_match'
),
$container
->
get
(
'ws_event.event_data_helper'
),
$container
->
get
(
'logger.factory'
)
$container
->
get
(
'logger.factory'
),
$container
->
get
(
'entity_type.manager'
),
);
}
...
...
@@ -125,9 +138,57 @@ class EventInfoBlock extends BlockBase implements ContainerFactoryPluginInterfac
'#location_address'
=>
$address
,
'#location_directions'
=>
$directions
,
];
if
(
$atcData
=
$this
->
getAtcData
())
{
$build
[
'#atc'
]
=
$atcData
;
}
return
$build
;
}
/**
* Add location and date information to event
*
* @return array
*/
protected
function
getAtcData
()
{
$datesField
=
$this
->
node
->
get
(
'field_event_dates'
)
->
getValue
();
if
(
empty
(
$datesField
[
0
]))
{
return
[];
}
$timezone
=
date_default_timezone_get
();
$startDt
=
DrupalDateTime
::
createFromFormat
(
DateTimeItemInterface
::
DATETIME_STORAGE_FORMAT
,
$datesField
[
0
][
'value'
],
DateTimeItemInterface
::
STORAGE_TIMEZONE
);
$startDt
->
setTimezone
(
timezone_open
(
$timezone
));
$endDt
=
DrupalDateTime
::
createFromFormat
(
DateTimeItemInterface
::
DATETIME_STORAGE_FORMAT
,
$datesField
[
0
][
'end_value'
],
DateTimeItemInterface
::
STORAGE_TIMEZONE
);
$endDt
->
setTimezone
(
timezone_open
(
$timezone
));
$description
=
''
;
$descriptionValue
=
$this
->
node
->
get
(
'body'
)
->
getValue
();
if
(
!
empty
(
$descriptionValue
)
&&
(
$description
=
$descriptionValue
[
0
][
'value'
]))
{
$description
=
strip_tags
(
$description
);
$description
=
strlen
(
$description
)
>
300
?
substr
(
$description
,
0
,
300
)
.
' ...'
:
$description
;
}
$datesAtc
=
[
'atc_date_start'
=>
$startDt
->
format
(
'Y-m-d H:i:s'
,
[
'timezone'
=>
$timezone
]),
'atc_date_end'
=>
$endDt
->
format
(
'Y-m-d H:i:s'
,
[
'timezone'
=>
$timezone
]),
'atc_timezone'
=>
$timezone
,
'atc_title'
=>
$this
->
node
->
getTitle
(),
'atc_description'
=>
$description
,
];
// Get locations.
$locationField
=
$this
->
node
->
get
(
'field_event_location'
)
->
getValue
();
$locationField
=
reset
(
$locationField
);
$location
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
load
(
$locationField
[
'target_id'
]);
if
(
$location
instanceof
NodeInterface
)
{
$locTitle
=
$location
->
getTitle
();
$datesAtc
[
'atc_location'
]
=
$locTitle
;
$datesAtc
[
'atc_organizer'
]
=
$locTitle
;
}
return
$datesAtc
;
}
/**
* Returns formatted Location address.
*
...
...
This diff is collapsed.
Click to expand it.
templates/block--lb-event-info.html.twig
+
13
−
1
View file @
c8e8ca83
...
...
@@ -45,5 +45,17 @@
{%
endif
%}
</div>
</div>
<div
class=
"addtocalendar"
></div>
<div
class=
"addtocalendar"
>
{%
if
content
[
'#atc'
]
%}
<var
class=
"atc_event"
>
<var
class=
"atc_date_start"
>
{{
content
[
'#atc'
]
.
atc_date_start
}}
</var>
<var
class=
"atc_date_end"
>
{{
content
[
'#atc'
]
.
atc_date_end
}}
</var>
<var
class=
"atc_timezone"
>
{{
content
[
'#atc'
]
.
atc_timezone
}}
</var>
<var
class=
"atc_title"
>
{{
content
[
'#atc'
]
.
atc_title
}}
</var>
<var
class=
"atc_description"
>
{{
content
[
'#atc'
]
.
atc_description
}}
</var>
<var
class=
"atc_location"
>
{{
content
[
'#atc'
]
.
atc_location
}}
</var>
<var
class=
"atc_organizer"
>
{{
content
[
'#atc'
]
.
atc_organizer
}}
</var>
</var>
{%
endif
%}
</div>
</div>
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