Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
WCMS
uw_sites_all
Commits
c75d4908
Commit
c75d4908
authored
Sep 10, 2021
by
Eric Bremner
Browse files
ISTWCMS-5009: adding installing default UW menu items on new site install
parent
1382d871
Changes
1
Hide whitespace changes
Inline
Side-by-side
uw_sites_all.install
View file @
c75d4908
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
* Install, update and uninstall for UW Sites all.
* Install, update and uninstall for UW Sites all.
*/
*/
use
Drupal\Core\Url
;
use
Drupal\menu_link_content
\
Entity\MenuLinkContent
;
use
Drupal\user\Entity\Role
;
use
Drupal\user\Entity\Role
;
/**
/**
...
@@ -35,6 +37,64 @@ function uw_sites_all_install() {
...
@@ -35,6 +37,64 @@ function uw_sites_all_install() {
// Remove default "contact" form.
// Remove default "contact" form.
\
Drupal
::
entityTypeManager
()
->
getStorage
(
'webform'
)
->
load
(
'contact'
)
->
delete
();
\
Drupal
::
entityTypeManager
()
->
getStorage
(
'webform'
)
->
load
(
'contact'
)
->
delete
();
// Get the menu items.
$menu_items
=
_uw_sites_all_get_menu_items
();
// Step through each menu item and create a menu link.
foreach
(
$menu_items
as
$menu_item
)
{
// Create the URL from the route name.
$url
=
URL
::
fromRoute
(
$menu_item
[
'route_name'
])
->
toString
();
// Create the actual menu link.
MenuLinkContent
::
create
([
'title'
=>
$menu_item
[
'title'
],
'link'
=>
[
'uri'
=>
'internal:'
.
$url
],
'menu_name'
=>
$menu_item
[
'menu_name'
],
'weight'
=>
$menu_item
[
'weight'
],
])
->
save
();
}
}
/**
* Helper function to return the UW default menu links.
*
* @return array[]
* Array of UW specific menu links.
*/
function
_uw_sites_all_get_menu_items
():
array
{
return
[
'Blog'
=>
[
'title'
=>
'Blog'
,
'menu_name'
=>
'main'
,
'route_name'
=>
'view.uw_view_blogs.blog_page'
,
'weight'
=>
50
,
'enabled'
=>
TRUE
,
],
'Events'
=>
[
'title'
=>
'Events'
,
'menu_name'
=>
'main'
,
'route_name'
=>
'view.uw_view_events.event_page'
,
'weight'
=>
55
,
'enabled'
=>
TRUE
,
],
'News'
=>
[
'title'
=>
'News'
,
'menu_name'
=>
'main'
,
'route_name'
=>
'view.uw_view_news_items.news_page'
,
'weight'
=>
60
,
'enabled'
=>
TRUE
,
],
'Catalogs'
=>
[
'title'
=>
'Catalogs'
,
'menu_name'
=>
'main'
,
'route_name'
=>
'view.uw_view_news_items.news_page'
,
'weight'
=>
60
,
'enabled'
=>
FALSE
,
],
];
}
}
/**
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment