Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calendar_link
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
calendar_link
Commits
13cd2818
Commit
13cd2818
authored
6 years ago
by
Christopher C. Wells
Browse files
Options
Downloads
Patches
Plain Diff
Support both DateTime and DrupalDateTime objects.
parent
0aca67c1
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Twig/CalendarLinkTwigExtension.php
+14
-6
14 additions, 6 deletions
src/Twig/CalendarLinkTwigExtension.php
with
14 additions
and
6 deletions
src/Twig/CalendarLinkTwigExtension.php
+
14
−
6
View file @
13cd2818
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\calendar_link\Twig
;
use
Drupal\calendar_link
\CalendarLinkException
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Spatie\CalendarLinks\Exceptions\InvalidLink
;
use
Spatie\CalendarLinks\Link
;
...
...
@@ -53,9 +54,9 @@ class CalendarLinkTwigExtension extends \Twig_Extension {
* Generator key to use for link building.
* @param string $title
* Calendar entry title.
* @param \DateTime $from
* @param
\Drupal\Core\Datetime\DrupalDateTime|
\DateTime $from
* Calendar entry start date and time.
* @param \DateTime $to
* @param
\Drupal\Core\Datetime\DrupalDateTime|
\DateTime $to
* Calendar entry end date and time.
* @param bool $all_day
* Indicator for an "all day" calendar entry.
...
...
@@ -67,12 +68,19 @@ class CalendarLinkTwigExtension extends \Twig_Extension {
* @return string
* URL for the specific calendar type.
*/
public
function
calendarLink
(
$type
,
$title
,
\DateTime
$from
,
\DateTime
$to
,
$all_day
=
FALSE
,
$description
=
''
,
$address
=
''
)
{
public
function
calendarLink
(
$type
,
$title
,
$from
,
$to
,
$all_day
=
FALSE
,
$description
=
''
,
$address
=
''
)
{
if
(
!
isset
(
self
::
$types
[
$type
]))
{
throw
new
CalendarLinkException
(
$this
->
t
(
'Invalid calendar link type.'
));
}
try
{
if
(
$from
instanceof
DrupalDateTime
)
{
$from
=
$from
->
getPhpDateTime
();
}
if
(
$to
instanceof
DrupalDateTime
)
{
$to
=
$to
->
getPhpDateTime
();
}
$link
=
Link
::
create
(
$title
,
$from
,
$to
,
$all_day
);
}
catch
(
InvalidLink
$e
)
{
...
...
@@ -95,9 +103,9 @@ class CalendarLinkTwigExtension extends \Twig_Extension {
*
* @param string $title
* Calendar entry title.
* @param \DateTime $from
* @param
\Drupal\Core\Datetime\DrupalDateTime|
\DateTime $from
* Calendar entry start date and time.
* @param \DateTime $to
* @param
\Drupal\Core\Datetime\DrupalDateTime|
\DateTime $to
* Calendar entry end date and time.
* @param bool $all_day
* Indicator for an "all day" calendar entry.
...
...
@@ -111,7 +119,7 @@ class CalendarLinkTwigExtension extends \Twig_Extension {
* - type_name: Human-readable name for the calendar type.
* - url: URL for the specific calendar type.
*/
public
function
calendarLinks
(
$title
,
\DateTime
$from
,
\DateTime
$to
,
$all_day
=
FALSE
,
$description
=
''
,
$address
=
''
)
{
public
function
calendarLinks
(
$title
,
$from
,
$to
,
$all_day
=
FALSE
,
$description
=
''
,
$address
=
''
)
{
$links
=
[];
foreach
(
self
::
$types
as
$type
=>
$name
)
{
...
...
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