diff --git a/core/modules/media/media.install b/core/modules/media/media.install index 83b6a35c..a828c82a 100644 --- a/core/modules/media/media.install +++ b/core/modules/media/media.install @@ -135,39 +135,42 @@ function media_requirements($phase) { // Load the default display. $display = \Drupal::service('entity_display.repository') ->getViewDisplay('media', $type->id()); + if ($type->getSource()) { + $source_field_definition = $type->getSource()->getSourceFieldDefinition($type); + if ($source_field_definition) { + if (!is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { + continue; + } - $source_field_definition = $type->getSource()->getSourceFieldDefinition($type); - if (!is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { - continue; - } - - $component = $display->getComponent($source_field_definition->getName()); - if (empty($component) || $component['type'] !== 'image' || !empty($component['settings']['image_style'])) { - continue; - } + $component = $display->getComponent($source_field_definition->getName()); + if (empty($component) || $component['type'] !== 'image' || !empty($component['settings']['image_style'])) { + continue; + } - $action_item = ''; - if ($module_handler->moduleExists('field_ui') && \Drupal::currentUser()->hasPermission('administer media display')) { - $url = Url::fromRoute('entity.entity_view_display.media.default', [ - 'media_type' => $type->id(), - ])->toString(); - $action_item = new TranslatableMarkup('If you would like to change this, add an image style to the %field_name field.', - [ - '%field_name' => $source_field_definition->label(), - ':display' => $url, - ]); + $action_item = ''; + if ($module_handler->moduleExists('field_ui') && \Drupal::currentUser()->hasPermission('administer media display')) { + $url = Url::fromRoute('entity.entity_view_display.media.default', [ + 'media_type' => $type->id(), + ])->toString(); + $action_item = new TranslatableMarkup('If you would like to change this, add an image style to the %field_name field.', + [ + '%field_name' => $source_field_definition->label(), + ':display' => $url, + ]); + } + $requirements['media_default_image_style_' . $type->id()] = [ + 'title' => t('Media'), + 'description' => new TranslatableMarkup('The default display for the %type media type is not currently using an image style on the %field_name field. Not using an image style can lead to much larger file downloads. @action_item', + [ + '%field_name' => $source_field_definition->label(), + '@action_item' => $action_item, + '%type' => $type->label(), + ] + ), + 'severity' => REQUIREMENT_WARNING, + ]; + } } - $requirements['media_default_image_style_' . $type->id()] = [ - 'title' => t('Media'), - 'description' => new TranslatableMarkup('The default display for the %type media type is not currently using an image style on the %field_name field. Not using an image style can lead to much larger file downloads. @action_item', - [ - '%field_name' => $source_field_definition->label(), - '@action_item' => $action_item, - '%type' => $type->label(), - ] - ), - 'severity' => REQUIREMENT_WARNING, - ]; } }