function media_entity_browser_form_entity_embed_dialog_alter in Media Entity Browser 8
Implements hook_form_FORM_ID_alter().
File
- ./
media_entity_browser.module, line 34 - The module file for media_entity_browser.
Code
function media_entity_browser_form_entity_embed_dialog_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// @todo, work around some issues in entity browser.
if ($embed_button = $form_state
->get('embed_button')) {
$browser = $embed_button
->getTypePlugin()
->getConfigurationValue('entity_browser');
// Check that we're using file_browser. @todo, check the browser by the view
// instead of hard-coding browser IDs.
if (in_array($browser, [
'media_browser',
'media_entity_browser',
])) {
// Override the first step of the form, if we're using media_browser.
if ($form['actions']['save_modal']['#ajax']['callback'] == '::submitSelectStep') {
// Add a library which handles our special "Select Media" button.
$form['#attached']['library'][] = 'media_entity_browser/entity_embed';
// Visually hide the "Next" button.
$form['actions']['save_modal']['#attributes']['class'][] = 'visually-hidden';
$form['actions']['save_modal']['#weight'] = 1;
// Add a button that matches our normal UX, which clicks the hidden button
// within the modal's iFrame.
$form['actions']['save_modal_alt'] = [
'#type' => 'submit',
'#value' => t('Select Media'),
'#attributes' => [
'class' => [
'entity-browser-modal-submit',
],
],
'#button_type' => 'primary',
'#weight' => 0,
];
}
}
}
}