Loading drowl_media.module +31 −0 Original line number Diff line number Diff line Loading @@ -83,3 +83,34 @@ function drowl_media_field_widget_form_alter(&$element, FormStateInterface $form } } } /** * Implements hook_field_widget_media_library_widget_form_alter(). * * Adds a "Create new Slideshow" button beneath "Select slideshow" media library * widget button. This is a *workaround* to provide a link for slideshow creation * as "Slideshow" is a custom media source, which doesn't provide a create itself. */ function drowl_media_field_widget_media_library_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) { if (!empty($element['#target_bundles']) && in_array("slideshow", $element['#target_bundles'])) { // Change the regular "Add"-label, so its clear to the user that this means // "Reference to existing Slideshows" $element["open_button"]["#value"] = t('Select Slideshow'); // Add further "Create Slideshow"-Button, opens the Slideshow create form in a new tab $element['#field_suffix']['empty_selection'] = [ '#type' => 'link', '#title' => t('Create new Slideshow'), '#url' => \Drupal\Core\Url::fromRoute('entity.media.add_form', ['media_type' => 'slideshow']), '#attributes' => [ 'target' => '_blank', 'class' => ['button', 'primary'], // Preparation to open the dialog in a modal, but as we can not // simply set the created slideshow, we didn't proceed here yet: // 'class' => ['button', 'primary', 'use-ajax'], // 'data-dialog-type' => 'modal', // 'data-dialog-options' => '{width: 90%, height: 80%}', ], '#weight' => 99, ]; } } Loading
drowl_media.module +31 −0 Original line number Diff line number Diff line Loading @@ -83,3 +83,34 @@ function drowl_media_field_widget_form_alter(&$element, FormStateInterface $form } } } /** * Implements hook_field_widget_media_library_widget_form_alter(). * * Adds a "Create new Slideshow" button beneath "Select slideshow" media library * widget button. This is a *workaround* to provide a link for slideshow creation * as "Slideshow" is a custom media source, which doesn't provide a create itself. */ function drowl_media_field_widget_media_library_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) { if (!empty($element['#target_bundles']) && in_array("slideshow", $element['#target_bundles'])) { // Change the regular "Add"-label, so its clear to the user that this means // "Reference to existing Slideshows" $element["open_button"]["#value"] = t('Select Slideshow'); // Add further "Create Slideshow"-Button, opens the Slideshow create form in a new tab $element['#field_suffix']['empty_selection'] = [ '#type' => 'link', '#title' => t('Create new Slideshow'), '#url' => \Drupal\Core\Url::fromRoute('entity.media.add_form', ['media_type' => 'slideshow']), '#attributes' => [ 'target' => '_blank', 'class' => ['button', 'primary'], // Preparation to open the dialog in a modal, but as we can not // simply set the created slideshow, we didn't proceed here yet: // 'class' => ['button', 'primary', 'use-ajax'], // 'data-dialog-type' => 'modal', // 'data-dialog-options' => '{width: 90%, height: 80%}', ], '#weight' => 99, ]; } }