diff --git a/changelogs/DP-45856.yml b/changelogs/DP-45856.yml new file mode 100644 index 0000000000..40fd39f99d --- /dev/null +++ b/changelogs/DP-45856.yml @@ -0,0 +1,41 @@ +# +# Write your changelog entry here. Every pull request must have a changelog yml file. +# +# Change types: +# ############################################################################# +# You can use one of the following types: +# - Added: For new features. +# - Changed: For changes to existing functionality. +# - Deprecated: For soon-to-be removed features. +# - Removed: For removed features. +# - Fixed: For any bug fixes. +# - Security: In case of vulnerabilities. +# +# Format +# ############################################################################# +# The format is crucial. Please follow the examples below. For reference, the requirements are: +# - All 3 parts are required and you must include "Type", "description" and "issue". +# - "Type" must be left aligned and followed by a colon. +# - "description" must be indented with 2 spaces followed by a colon +# - "issue" must be indented with 4 spaces followed by a colon. +# - "issue" is for the Jira ticket number only e.g. DP-1234 +# - No extra spaces, indents, or blank lines are allowed. +# +# Example: +# ############################################################################# +# Fixed: +# - description: Fixes scrolling on edit pages in Safari. +# issue: DP-13314 +# +# You may add more than 1 description & issue for each type using the following format: +# Changed: +# - description: Automating the release branch. +# issue: DP-10166 +# - description: Second change item that needs a description. +# issue: DP-19875 +# - description: Third change item that needs a description along with an issue. +# issue: DP-19843 +# +Fixed: + - description: Hide metadata related to robots noindex on the form. + issue: DP-45856 diff --git a/docroot/modules/custom/mass_metatag/mass_metatag.module b/docroot/modules/custom/mass_metatag/mass_metatag.module index 7387c43dc9..7b147db873 100644 --- a/docroot/modules/custom/mass_metatag/mass_metatag.module +++ b/docroot/modules/custom/mass_metatag/mass_metatag.module @@ -825,6 +825,7 @@ function mass_metatag_form_node_form_alter(&$form, FormStateInterface $form_stat // Hide the following metatags from the advanced section. $subsection_advanced = [ + 'robots', 'geo_placename', 'geo_position', 'geo_region', @@ -860,6 +861,72 @@ function mass_metatag_form_node_form_alter(&$form, FormStateInterface $form_stat } } +/** + * Implements hook_form_alter(). + */ +function mass_metatag_form_alter(&$form, FormStateInterface $form_state, $form_id) { + if ($form_id !== 'views_bulk_operations_configure_action') { + return; + } + + $form_data = $form_state->get('views_bulk_operations'); + if (empty($form_data['action_id']) || $form_data['action_id'] !== 'views_bulk_edit') { + return; + } + + $terms = [ + 'robots', + 'noindex', + 'nofollow', + 'nosnippet', + 'max-snippet', + 'max-image-preview', + 'max-video-preview', + ]; + mass_metatag_hide_elements_by_terms($form, $terms); +} + +/** + * Hide elements whose key/title contains any of the given terms. + * + * @param array $elements + * Form element tree to inspect and alter. + * @param array $hide_terms + * Terms matched against each element key/title. + */ +function mass_metatag_hide_elements_by_terms(array &$elements, array $hide_terms) { + foreach ($elements as $key => &$element) { + if (!is_array($element)) { + continue; + } + + $matches = FALSE; + $key_string = strtolower((string) $key); + foreach ($hide_terms as $term) { + if (str_contains($key_string, $term)) { + $matches = TRUE; + break; + } + } + + if (!$matches && isset($element['#title'])) { + $title = strtolower(strip_tags((string) $element['#title'])); + foreach ($hide_terms as $term) { + if (str_contains($title, $term)) { + $matches = TRUE; + break; + } + } + } + + if ($matches) { + $element['#access'] = FALSE; + } + + mass_metatag_hide_elements_by_terms($element, $hide_terms); + } +} + /** * Implements hook_metatags_attachments_alter(). */