Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

1

Here are the necessary steps: Create a directory on the server. This is typically done via SSH. For instance assuming Apache under Ubuntu, the following command can be used: sudo -u www-data mkdir -p /var/www/html/web/sites/default/files/private Tell Drupal about your directory by editing your settings.php file. You need to have a line like the following: ...


1

I think this is the problem, you are trying to get the node from the route, only, you are not on a node route, you are on an entity_print route, so node is not available. As a side note, you should always check that the field exists before trying to get the value. Before you try something like this: $vars['field_name'] = $entity->get('field_name')->...


0

Thanks to @Kevin, I updated my code to function amap_file_download($uri) { $sFileName = \Drupal::service('file_system')->basename($uri); return array( 'Content-disposition' => 'attachment; filename="' . $sFileName . '"', ); } And it works!


1

in D7 this would happen with drupal_add_http_header() In other hooks that might have been true, but hook_file_download works the same in Drupal 8 as it did in Drupal 7, without using drupal_add_http_header. This is the documentation for both versions’ return value from that hook: If the user does not have permission to access the file, return -1. If the ...


0

The $this->sessionManager->start(); was not working anymore for me because of the last update. I changed it in to $this->sessionManager->regenerate();


0

As solution for site structure I use config synchronization, which is in Drupal 8 Core, and I use it with drush commands ("cex" - configuration export and "cim" - configuration import). For content sync I don't have much experience, but I saw new module that can be interesting solution: https://www.drupal.org/project/content_sync.


0

One of the reasons for this might also be mod_rewrite not being enabled in apache


1

The best way to implement this is not to set filename. Instead, you should set the #description of the file. In the following example, I have a media of a bundle called "file" and in it, I have a file field called "field_media_file". Then I set the description of each file to be the media name. if ($variables['media']->bundle() == 'file' && !...


2

For drupal 8, something like this will work, when used in a custom module: function my_module_field_widget_form_alter(&$element, FormStateInterface &$form_state, $context) { if (isset($element['#field_name']) && $element['#field_name'] === 'my_field_name') { $element['#process'][] = 'app_icon_image_file_validate'; return $element; ...


1

I don't believe the accepted answer is correct. You don't need to include the class. To get this to work, you need to make sure that the file you are passing the ZipArchiver constructor already exists - that is where I believe the original question was getting the error: Exception: Cannot open archive.zip To make sure the file you are passing to the ...


1

That is what, for example, the Drupal\locale\Form\ExportForm class does. See the code used in ExportForm::submitForm(). $response = new BinaryFileResponse($uri); $response->setContentDisposition('attachment', $filename); $form_state->setResponse($response); $response->setContentDisposition() sets the Content-Disposition header with the given ...


2

You can return a BinaryFileResponse from a controller, or as 4k4 has added: $response = new BinaryFileResponse(file_create_url("public://cal/211443-event.ics")); $form_state->setResponse($response);


0

function template_preprocess_media(array &$variables) { $media = $variables['media']; $name = $media->getName(); if (!empty($name)) { $mediaArray = $media->toArray(); if (!empty($mediaArray['field_media_file'][0]['target_id'])) { $fileId = $mediaArray['field_media_file'][0]['target_id']; $file = \Drupal\file\Entity\File::...


Top 50 recent answers are included