docbrown/lib/data_update_scripts/20220126102900_create_home_navigation_link.rb
Suzanne Aitchison f1864847e7
Make home link an admin-customisable navigation link (#16268)
* move home link to a customisable navlink

* add trailing slash for path

* update specs

* replace positions, set home link to -1

* add update script for adding home navigation link

* update data update script
2022-02-01 09:27:09 +00:00

20 lines
644 B
Ruby

module DataUpdateScripts
class CreateHomeNavigationLink
def run
NavigationLink.create_or_update_by_identity(
name: "Home",
url: URL.url("/"),
icon: File.read(Rails.root.join("app/assets/images/twemoji/house.svg")),
display_only_when_signed_in: false,
position: 1,
section: :default,
)
# Increment all other default section links to account for new home link, and update to be 1-based
NavigationLink.where(section: :default).find_each do |link|
new_position = link.position + 2
link.update_columns(position: new_position)
end
end
end
end