Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
smart_date
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
smart_date
Commits
8e94cbd6
Commit
8e94cbd6
authored
1 year ago
by
Dieter Holvoet
Committed by
Martin Anderson-Clutz
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3348541
by DieterHolvoet: start_time and end_time properties don't work
parent
042b49d2
No related branches found
No related tags found
2 merge requests
!166
Resolve #3303444 "Date only range expands"
,
!49
Issue #3348541: start_time and end_time properties don't work
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/Field/FieldType/DateTimeComputed.php
+72
-0
72 additions, 0 deletions
src/Plugin/Field/FieldType/DateTimeComputed.php
src/Plugin/Field/FieldType/SmartDateItem.php
+0
-1
0 additions, 1 deletion
src/Plugin/Field/FieldType/SmartDateItem.php
with
72 additions
and
1 deletion
src/Plugin/Field/FieldType/DateTimeComputed.php
0 → 100644
+
72
−
0
View file @
8e94cbd6
<?php
namespace
Drupal\smart_date\Plugin\Field\FieldType
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\Core\TypedData\DataDefinitionInterface
;
use
Drupal\Core\TypedData\TypedDataInterface
;
use
Drupal\Core\TypedData\TypedData
;
/**
* A computed property for dates of Smart Date field items.
*/
class
DateTimeComputed
extends
TypedData
{
/**
* Cached computed date.
*
* @var \DateTime|null
*/
protected
$date
=
NULL
;
/**
* {@inheritdoc}
*/
public
function
__construct
(
DataDefinitionInterface
$definition
,
$name
=
NULL
,
TypedDataInterface
$parent
=
NULL
)
{
parent
::
__construct
(
$definition
,
$name
,
$parent
);
if
(
!
$definition
->
getSetting
(
'date source'
))
{
throw
new
\InvalidArgumentException
(
"The definition's 'date source' key has to specify the name of the date property to be computed."
);
}
}
/**
* {@inheritdoc}
*/
public
function
getValue
()
{
if
(
$this
->
date
!==
NULL
)
{
return
$this
->
date
;
}
/** @var \Drupal\Core\Field\FieldItemInterface $item */
$item
=
$this
->
getParent
();
$value
=
$item
->
{(
$this
->
definition
->
getSetting
(
'date source'
))};
// A date cannot be created from a NULL value.
if
(
$value
===
NULL
)
{
return
NULL
;
}
try
{
$date
=
DrupalDateTime
::
createFromTimestamp
(
$value
);
if
(
$date
instanceof
DrupalDateTime
&&
!
$date
->
hasErrors
())
{
$this
->
date
=
$date
;
}
}
catch
(
\Exception
$e
)
{
// @todo Handle this.
}
return
$this
->
date
;
}
/**
* {@inheritdoc}
*/
public
function
setValue
(
$value
,
$notify
=
TRUE
)
{
$this
->
date
=
$value
;
// Notify the parent of any changes.
if
(
$notify
&&
isset
(
$this
->
parent
))
{
$this
->
parent
->
onChange
(
$this
->
name
);
}
}
}
This diff is collapsed.
Click to expand it.
src/Plugin/Field/FieldType/SmartDateItem.php
+
0
−
1
View file @
8e94cbd6
...
...
@@ -6,7 +6,6 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use
Drupal\Core\Field\FieldStorageDefinitionInterface
;
use
Drupal\Core\Field\Plugin\Field\FieldType\TimestampItem
;
use
Drupal\Core\TypedData\DataDefinition
;
use
Drupal\datetime\DateTimeComputed
;
/**
* Plugin implementation of the 'smartdate' field type.
...
...
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