function groupmenu_form_alter in Group Menu 8
Implements hook_form_alter().
File
- ./
groupmenu.module, line 68 - Gives the ability to create and manage menus for groups.
Code
function groupmenu_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_object = $form_state
->getFormObject();
// Filter menu options to group menus.
if ($form_object instanceof MenuLinkEditForm || $form_object instanceof MenuLinkContentForm) {
$account = \Drupal::currentUser();
if (!$account
->hasPermission('administer menu')) {
groupmenu_filter_parent_options($form['menu_parent']['#options']);
}
}
// Add setting to group node plugins to allow group menus.
if ($form_object instanceof GroupContentTypeForm) {
/** @var \Drupal\group\Entity\GroupContentType $group_content_type */
$group_content_type = $form_object
->getEntity();
if ($group_content_type
->getContentPlugin() instanceof GroupNode) {
$configuration = $group_content_type
->get('plugin_config');
$form['node_form_group_menu'] = [
'#type' => 'checkbox',
'#title' => t("Add group menus to node form"),
'#default_value' => isset($configuration['node_form_group_menu']) ? $configuration['node_form_group_menu'] : FALSE,
];
}
}
}