Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
[PRODDEV-329] Allow site admins to remove menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
oyermolenko committed Dec 7, 2021
1 parent 46aac33 commit 5f37532
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
4 changes: 4 additions & 0 deletions config/install/openy_gated_content.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ top_menu:
background_color_light: '#F2F2F2'
links_color_dark: '#ffffff'
background_color_dark: 'black'
menu_config:
schedule: false
favorites: false
categories: false
14 changes: 7 additions & 7 deletions js/gated-content/dist/gated-content.umd.min.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions js/gated-content/src/components/TopMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
:color="fontColor"
></CloseIcon>
</button>
<div @click="menuOpen=false">
<div @click="menuOpen=false" v-if="!hideMenuItem('schedule')">
<router-link
:to="{ name: 'Schedule' }"
:style="fontStyleObject"
Expand All @@ -32,7 +32,7 @@
<ScheduleIcon :color="fontColor"></ScheduleIcon>Schedule
</router-link>
</div>
<div @click="menuOpen=false">
<div @click="menuOpen=false" v-if="!hideMenuItem('favorites')">
<router-link
:to="{ name: 'Favorites' }"
:style="fontStyleObject"
Expand All @@ -41,7 +41,7 @@
<FavoritesIcon :color="fontColor"></FavoritesIcon>Favorites
</router-link>
</div>
<div @click="menuOpen=false">
<div @click="menuOpen=false" v-if="!hideMenuItem('categories')">
<router-link
:to="{ name: 'CategoryListing', params: { type: 'video' } }"
:style="fontStyleObject"
Expand Down Expand Up @@ -120,5 +120,13 @@ export default {
};
},
},
methods: {
hideMenuItem(item) {
if (!this.getAppSettings || !this.getAppSettings.menu_config[item]) {
return false;
}
return this.getAppSettings.menu_config[item];
},
},
};
</script>
25 changes: 23 additions & 2 deletions openy_gated_content.install
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ function openy_gated_content_update_8004() {
* Remove field_link_to_gated_content_app completely.
*/
function openy_gated_content_update_8005() {
FieldConfig::loadByName('paragraph', 'gated_content_login', 'field_link_to_gated_content_app')->delete();
FieldStorageConfig::loadByName('paragraph', 'field_link_to_gated_content_app')->delete();
FieldConfig::loadByName('paragraph', 'gated_content_login', 'field_link_to_gated_content_app')
->delete();
FieldStorageConfig::loadByName('paragraph', 'field_link_to_gated_content_app')
->delete();
}

/**
Expand Down Expand Up @@ -503,3 +505,22 @@ function openy_gated_content_update_8024() {
'openy_gated_content.welcome_email_settings',
]);
}

/**
* Set Top Items Visibility Default Settings.
*/
function openy_gated_content_update_8025() {
$config_updater = \Drupal::service('openy_upgrade_tool.param_updater');
$config_dir = drupal_get_path('module', 'openy_gated_content') . '/config/install/';
$config_name = 'openy_gated_content.settings';
$config = $config_dir . $config_name . '.yml';
$config_updater->update($config, $config_name, 'menu_config');
$components = [
'schedule',
'favorites',
'categories',
];
foreach ($components as $id) {
$config_updater->update($config, $config_name, "menu_config.$id");
}
}
35 changes: 35 additions & 0 deletions src/Form/GCSettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
],
];

$this->menuVisibilitySettings($form, $config);

$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
Expand All @@ -160,6 +162,39 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
return $form;
}

/**
* Helper method to add menu configs.
*
* @param array $form
* Array of the form configuration to attach the form elements to.
* @param \Drupal\Core\Config\Config $config
* Virtual Y config object.
*/
protected function menuVisibilitySettings(array &$form, Config $config) {
$form['app_settings']['menu_config'] = [
'#type' => 'fieldset',
'#title' => $this->t('Top Items Visibility Settings'),
'schedule' => [
'#title' => $this->t('Hide Schedule'),
'#description' => $this->t("If checked 'Schedule' menu item won't be visible."),
'#type' => 'checkbox',
'#default_value' => $config->get('menu_config.schedule') ?? FALSE,
],
'favorites' => [
'#title' => $this->t('Hide Favorites'),
'#description' => $this->t("If checked 'Favorites' menu item won't be visible."),
'#type' => 'checkbox',
'#default_value' => $config->get('menu_config.favorites') ?? FALSE,
],
'categories' => [
'#title' => $this->t('Hide Categories'),
'#description' => $this->t("If checked 'Categories' menu item won't be visible."),
'#type' => 'checkbox',
'#default_value' => $config->get('menu_config.categories') ?? FALSE,
]
];
}

/**
* Helper method that adds form elements for Virtual Y Components.
*
Expand Down

0 comments on commit 5f37532

Please sign in to comment.