Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
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
drupal
Merge requests
!8670
adds install hook to set dates for created umami content
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
adds install hook to set dates for created umami content
issue/drupal-3399970:3399970-umami-content-is
into
11.x
Overview
0
Commits
4
Pipelines
4
Changes
2
Closed
Mark Conroy
requested to merge
issue/drupal-3399970:3399970-umami-content-is
into
11.x
6 months ago
Overview
0
Commits
4
Pipelines
4
Changes
2
Expand
Closes
#3399970
0
0
Merge request reports
Compare
11.x
version 3
6f3b9aa7
6 months ago
version 2
8de3bf82
6 months ago
version 1
59056cf5
6 months ago
11.x (base)
and
latest version
latest version
e862aece
4 commits,
6 months ago
version 3
6f3b9aa7
3 commits,
6 months ago
version 2
8de3bf82
2 commits,
6 months ago
version 1
59056cf5
1 commit,
6 months ago
2 files
+
54
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
core/profiles/demo_umami/modules/demo_umami_content/demo_umami_content.install
+
53
−
0
Options
@@ -18,6 +18,59 @@ function demo_umami_content_module_preinstall($module) {
}
}
/**
* Implements hook_install().
*/
function
demo_umami_content_install
(
$is_syncing
)
{
if
(
!
$is_syncing
)
{
$query
=
\Drupal
::
entityQuery
(
'node'
)
->
accessCheck
(
TRUE
);
$nids
=
$query
->
execute
();
if
(
empty
(
$nids
))
{
return
;
}
// Sort node IDs in descending order
rsort
(
$nids
);
$nodes
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
loadMultiple
(
$nids
);
// Use a counter to determine the "days ago" offset
$counter
=
1
;
foreach
(
$nodes
as
$node
)
{
// Get all translation languages for the node
$languages
=
$node
->
getTranslationLanguages
();
foreach
(
$languages
as
$language
)
{
// Load the translated version of the node.
$translatedNode
=
$node
->
getTranslation
(
$language
->
getId
());
try
{
// Use the counter to calculate "days ago".
$timestamp
=
strtotime
(
"-
{
$counter
}
days"
);
// Set the created and updated time for the translated node.
$translatedNode
->
setCreatedTime
(
$timestamp
);
$translatedNode
->
setChangedTime
(
$timestamp
);
// Check if the translation is the default language.
// If not, mark the translation as changed.
if
(
!
$translatedNode
->
isDefaultTranslation
())
{
$translatedNode
->
setNewRevision
(
FALSE
);
$translatedNode
->
isDefaultRevision
(
FALSE
);
$translatedNode
->
setRevisionTranslationAffected
(
TRUE
);
}
$translatedNode
->
save
();
}
catch
(
\Exception
$e
)
{
\Drupal
::
logger
(
'system'
)
->
error
(
$e
->
getMessage
());
}
}
// Increment the counter for the next node
$counter
++
;
}
}
}
/**
* Implements hook_uninstall().
*/
Loading