Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
3fb92dbe
Commit
3fb92dbe
authored
3 years ago
by
Eric Bremner
Committed by
Kevin Paxman
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4939: adding update hook to set default num of items for listing blocks
parent
1e80c71e
No related branches found
No related tags found
1 merge request
!129
Feature/istwcms 4939 ebremner listing blocks num items
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uw_cfg_common.install
+114
-0
114 additions, 0 deletions
uw_cfg_common.install
with
114 additions
and
0 deletions
uw_cfg_common.install
+
114
−
0
View file @
3fb92dbe
...
...
@@ -6,6 +6,7 @@
*/
use
Drupal\taxonomy\Entity\Term
;
use
\Drupal\node\Entity\Node
;
use
Drupal\uw_cfg_common
\UwPermissions\UwPermissions
;
/**
...
...
@@ -239,3 +240,116 @@ function _uw_cfg_common_create_term($taxonomy_name, $vocab_machine_name, $weight
// Return the taxonomy term id.
return
$new_term
->
id
();
}
/**
* Set default settings for listing page blocks.
*/
function
uw_cfg_common_update_8101
()
{
// Block ids that need to be changed.
$block_ids
=
[
'views_block:uw_view_blogs-blogs_listing_block'
,
'views_block:uw_view_events-events_listing_block'
,
'views_block:uw_view_news_items-news_items_listing_block'
,
];
// Load all the nodes.
$nodes
=
\Drupal\node\Entity\Node
::
loadMultiple
();
// Step through each node and set the default setting
// to 3 on listing blocks.
foreach
(
$nodes
as
$node
)
{
// Flag to save the node, have this to save processing
// time if we don't need to save the node after the checks.
$save_node_flag
=
FALSE
;
// Load the layout and sections.
$layout
=
$node
->
get
(
'layout_builder__layout'
);
$sections
=
$layout
->
getSections
();
// Step through each of the sections.
foreach
(
$sections
as
$section
)
{
// Load the components for the section.
$components
=
$section
->
getComponents
();
// Step through each of the components.
foreach
(
$components
as
$component
)
{
// If this component is one that needs to be changed,
// then check for setting and change if required.
if
(
in_array
(
$component
->
getPluginId
(),
$block_ids
))
{
// Load the config for the block.
$configurations
=
$component
->
get
(
'configuration'
);
// If the config is none of 5, it needs to be changed to 3.
if
(
$configurations
[
'items_per_page'
]
==
'none'
||
$configurations
[
'items_per_page'
]
==
'5'
)
{
// Change the config and save the component.
$configurations
[
'items_per_page'
]
=
'3'
;
$component
->
setConfiguration
(
$configurations
);
// Set the save node flag so that we know to
// save this node as the last step in the loop.
$save_node_flag
=
TRUE
;
}
}
}
// If we need to save the node, then save it.
if
(
$save_node_flag
)
{
$node
->
save
();
}
}
// Load all the revisions for the node.
$vids
=
\Drupal
::
service
(
'entity_type.manager'
)
->
getStorage
(
'node'
)
->
revisionIds
(
$node
);
// Step through each revision, and check if we have to
// change the settings for the listing blocks.
foreach
(
$vids
as
$vid
)
{
// Flag to see if we have to save the revision.
$save_revision_flag
=
FALSE
;
// Load the revision node.
$revision_node
=
\Drupal
::
entityManager
()
->
getStorage
(
'node'
)
->
loadRevision
(
$vid
);
// Comments from here down are the same as above.
$layout
=
$revision_node
->
get
(
'layout_builder__layout'
);
$sections
=
$layout
->
getSections
();
foreach
(
$sections
as
$section
)
{
$components
=
$section
->
getComponents
();
foreach
(
$components
as
$component
)
{
if
(
in_array
(
$component
->
getPluginId
(),
$block_ids
))
{
$configurations
=
$component
->
get
(
'configuration'
);
if
(
$configurations
[
'items_per_page'
]
==
'none'
||
$configurations
[
'items_per_page'
]
==
'5'
)
{
$configurations
[
'items_per_page'
]
=
'3'
;
$component
->
setConfiguration
(
$configurations
);
$save_revision_flag
=
TRUE
;
}
}
}
}
if
(
$save_revision_flag
)
{
$revision_node
->
save
();
}
}
}
}
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