Skip to content

Instantly share code, notes, and snippets.

View banoodle's full-sized avatar

annebonham banoodle

View GitHub Profile
@banoodle
banoodle / your_module.module
Created February 6, 2021 03:51
Drupal 8 hook_form_media_form_alter hooks that add entity ids to entity edit forms
<?php
/**
* Implements hook_form_node_form_alter().
*/
function your_module_form_node_form_alter(&$form, &$form_state, $form_id) {
$node = \Drupal::request()->attributes->get('node');
// If it's the edit form as opposed to the add form.
if (!empty($node)) {
$orig_title = $node->getTitle();
@banoodle
banoodle / media_entity_download-open-not-download.patch
Created February 6, 2021 03:25
Drupal 8 Media Entity Download custom patch
diff --git a/src/Controller/DownloadController.php b/src/Controller/DownloadController.php
index 09bfdf6..0735f54 100644
--- a/src/Controller/DownloadController.php
+++ b/src/Controller/DownloadController.php
@@ -7,11 +7,9 @@ use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Drupal\media\MediaInterface;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpFoundation\ResponseHeaderBag;
<?php // If there is audio content, print it with it's description.
if (isset($content['field_audio_file'])) {
// Hide so we can display it later.
hide($content['field_audio_file']);
print '<div class="field-item">';
// Loop through each audio file.
$audiofiles = $content['field_audio_file']['#items'];
foreach ($audiofiles as $delta => $audiofile) {
$uri = $audiofile['uri'];
$audiopath = file_create_url($uri); // Converts uri to path format.