Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check we're not trying to delete default media thumbnails #854

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Form/ConfirmDeleteMediaAndFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$file = File::load($target_id);
if ($file) {
if (!$file->access('delete', $this->currentUser)) {
// May not be allowed access because it is a default thumbnail for media type.
if ($field->getName() == 'thumbnail') {
$default_thumbnail_filename = $entity->getSource()->getPluginDefinition()['default_thumbnail_filename'];
$default_thumbnail_uri = \Drupal::config('media.settings')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be using dependency injection instead of the \Drupal thing... up in the ::create() method, to load up the config factory, and either pass it to the constructor to get the particular config object and then to do so inside the constructor, or to grab and pass the config object in the ::create() method to the constructor.

->get('icon_base_uri') . '/' . $default_thumbnail_filename;
if ($default_thumbnail_uri == $file->getFileUri()) {
continue;
}
}
$inaccessible_entities[] = $file;
continue;
}
Expand Down