Skip to content
Snippets Groups Projects
Commit 742bd81b authored by Eric Bremner's avatar Eric Bremner Committed by Martin Leblanc
Browse files

ISTWCMS-5204: restricting the types of crops on the media upload based on node

parent 470cb444
No related branches found
No related tags found
1 merge request!180ISTWCMS-5204: updating node theming to use a free flowing image
......@@ -756,6 +756,49 @@ function uw_cfg_common_form_alter(array &$form, FormStateInterface $form_state,
$form['field_uw_meta_tags']['widget'][0]['twitter_cards']['twitter_cards_page_url']['#access'] = FALSE;
}
}
// If we are on the media upload form, we want to restrict
// what crops are available.
if ($form_id == 'media_library_add_form_upload') {
// If the crop widget is on the form, unset certain crops.
if (isset($form['media'][0]['fields']['field_media_image']['widget'][0]['#crop_list'])) {
// Get the parameters from the request, this was the only
// way to get out what the bundle was. Since this is a new
// form call from media_library, we could not use get current
// path or uri, since it would only return /media_library.
// The media library parameters has everything listed for the
// node and the node types.
$media_lib_parameters = \Drupal::request()->query->get('media_library_opener_parameters');
// If there are media lib parameters, process them.
if ($media_lib_parameters) {
// If there is a bundle on the parameters, continue
// to process.
if (isset($media_lib_parameters['bundle'])) {
// If this is a contact, remove all the responsive crops.
// If anything else, remove the portrait crop.
if ($media_lib_parameters['bundle'] == 'uw_ct_contact') {
foreach ($form['media'][0]['fields']['field_media_image']['widget'][0]['#crop_list'] as $index => $crop) {
if ($crop !== 'uw_crop_portrait') {
unset($form['media'][0]['fields']['field_media_image']['widget'][0]['#crop_list'][$index]);
}
}
}
else {
foreach ($form['media'][0]['fields']['field_media_image']['widget'][0]['#crop_list'] as $index => $crop) {
if ($crop == 'uw_crop_portrait') {
unset($form['media'][0]['fields']['field_media_image']['widget'][0]['#crop_list'][$index]);
}
}
}
}
}
}
}
}
/**
......
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