Skip to content
Snippets Groups Projects
Commit 38bec013 authored by Eric Bremner's avatar Eric Bremner Committed by Kevin Paxman
Browse files

ISTWCMS-4104: adding form alter to hide elements in metatags

parent b9af3745
No related branches found
No related tags found
1 merge request!56ISTWCMS-4104: adding defaults for metatags
......@@ -370,3 +370,33 @@ function uw_cfg_common_form_menu_link_edit_alter(array &$form, FormStateInterfac
// Do not allow the home page to be parent of any item.
unset($form['menu_parent']['#options']['main:uw_base_profile.front_page']);
}
/**
* Implements hook_form_alter().
*
* Hide/disable metatag information on our nodes.
*/
function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
// Ensure that we are on a UW content type node.
if (preg_match('/node_uw.*add_form/', $form_id) || preg_match('/node_uw.*edit_form/', $form_id)) {
// Ensure that the node has metatag information.
if (isset($form['field_uw_meta_tags'])) {
// Hide elements under advanced settings.
$form['field_uw_meta_tags']['widget'][0]['advanced']['canonical_url']['#access'] = FALSE;
$form['field_uw_meta_tags']['widget'][0]['advanced']['shortlink_url']['#access'] = FALSE;
// Hide elements under open graph.
$form['field_uw_meta_tags']['widget'][0]['open_graph']['og_type']['#access'] = FALSE;
$form['field_uw_meta_tags']['widget'][0]['open_graph']['og_url']['#access'] = FALSE;
$form['field_uw_meta_tags']['widget'][0]['open_graph']['og_updated_time']['#access'] = FALSE;
$form['field_uw_meta_tags']['widget'][0]['open_graph']['og_locale']['#access'] = FALSE;
// Hide elements under Twitter settings.
$form['field_uw_meta_tags']['widget'][0]['twitter_cards']['twitter_cards_page_url']['#access'] = FALSE;
$form['field_uw_meta_tags']['widget'][0]['twitter_cards']['twitter_cards_page_url']['#access'] = FALSE;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment