isEnabled(); } } // Create checkbox for hiding menu links. $form['menu']['link']['place_in_menu'] = [ '#type' => 'checkbox', '#title' => t('Add menu link'), '#weight' => -50, '#default_value' => $enabled, ]; // Hide menu fields that do not apply when the menu link is not enabled. $hide_state = [ 'invisible' => [ 'input[name="menu[place_in_menu]"]' => ['checked' => FALSE], ], ]; $form['menu']['link']['title']['#states'] = $hide_state; $form['menu']['link']['description']['#states'] = $hide_state; $form['menu']['link']['weight']['#states'] = $hide_state; } } /** * Form submit handler. */ function _uw_sites_all_form_node_form_submit(array $form, FormStateInterface &$form_state): void { // For new nodes of content types that use Layout Builder, redirect to layout // tab. $nid = $form_state->getValue('nid'); $form_id = $form_state->getBuildInfo()['form_id']; $fieldDefinitions = $form['#process'][1][0]->get('fieldDefinitions'); if ($nid && substr($form_id, -10) !== '_edit_form' && isset($fieldDefinitions['layout_builder__layout'])) { $form_state->setRedirect('layout_builder.overrides.node.view', ['node' => $nid]); } // If a page is in the site hierarchy, enable or disabled its menu item based // on place_in_menu selection. $in_hierarchy = $form_state->getValue(['menu', 'enabled']); if ($in_hierarchy) { $entity_id = (int) $form_state->getValue(['menu', 'entity_id']); $enabled = (bool) $form_state->getValue(['menu', 'place_in_menu']); $menu_link = MenuLinkContent::load($entity_id); // If JS is disabled, "Menu link title" will not be automatically filled. If // the title is empty, no link will be created and the following will error. // So, only run these if the menu link exists. if ($menu_link) { $menu_link->set('enabled', $enabled); $menu_link->save(); } } } /** * Implements hook_link_alter(). */ function uw_sites_all_link_alter(&$variables) { if ($variables['text'] == 'All recent content') { $variables['text'] = t('@text', ['@text' => 'Manage Content']); } } /** * Implements hook_page_attachments(). */ function uw_sites_all_page_attachments(array &$page) { $is_admin = \Drupal::service('router.admin_context')->isAdminRoute(); if ($is_admin) { $page['#attached']['library'][] = 'uw_sites_all/uw-sites-all-adminimal'; return; } } /** * Implements template_preprocess_block(). */ function uw_sites_all_preprocess_block(&$variables) { // Get the arguments of the URL and separate into parts. $args = explode('/', \Drupal::service('path.current')->getPath()); // If the last argument is layout, we are on a layout page, // so set the variable to true. if (in_array('layout', $args) || in_array('layout_builder', $args)) { $variables['in_layout_builder'] = TRUE; } } /** * Implements hook_update_projects_alter(). */ function uw_sites_all_update_projects_alter(&$projects) { foreach ($projects as &$project) { // Removes -uw_wcms (and any trailing numbers) from version numbers so // Drupal reports updates properly. $project['info']['version'] = preg_replace('/-uw_wcms\d*$/', '', $project['info']['version']); } } /** * Implements hook_ENTITY_TYPE_presave(). */ function uw_sites_all_webform_presave(WebformInterface $webform): void { // Add a Webform CAPTCHA component to each newly-created Webform. if ($webform->isNew() && empty($webform->getElementsRaw())) { $elements = [ 'captcha' => [ '#type' => 'captcha', ], ]; $webform->setElements($elements); } }