Loading core/modules/media/media.install +24 −9 Original line number Diff line number Diff line Loading @@ -120,22 +120,37 @@ function media_requirements($phase) { } } // When a new media type with an image source is created we're configuring // the default entity view display using the 'large' image style. // Unfortunately, if a site builder has deleted the 'large' image style, // we need some other image style to use, but at this point, we can't // really know the site builder's intentions. So rather than do something // surprising, we're leaving the embedded media without an image style and // adding a warning that the site builder might want to add an image style. // @see Drupal\media\Plugin\media\Source\Image::prepareViewDisplay $module_handler = \Drupal::service('module_handler'); foreach (MediaType::loadMultiple() as $type) { // Load the default display. $display = \Drupal::service('entity_display.repository') ->getViewDisplay('media', $type->id()); // Check for missing source field definition. $source_field_definition = $type->getSource()->getSourceFieldDefinition($type); if (empty($source_field_definition) || !is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { if (empty($source_field_definition)) { $requirements['media_missing_source_field_' . $type->id()] = [ 'title' => t('Media'), 'description' => t('The source field definition for the %type media type is missing.', [ '%type' => $type->label(), ] ), 'severity' => REQUIREMENT_ERROR, ]; continue; } // When a new media type with an image source is created we're // configuring the default entity view display using the 'large' image // style. Unfortunately, if a site builder has deleted the 'large' image // style, we need some other image style to use, but at this point, we // can't really know the site builder's intentions. So rather than do // something surprising, we're leaving the embedded media without an // image style and adding a warning that the site builder might want to // add an image style. // @see Drupal\media\Plugin\media\Source\Image::prepareViewDisplay if (!is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { continue; } Loading core/modules/media/tests/src/Functional/MediaRequirementsTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -26,10 +26,13 @@ public function testMissingSourceFieldDefinition() { $field_storage_definition = $field_definition->getFieldStorageDefinition(); $field_definition->delete(); $field_storage_definition->delete(); $valid_media_type = $this->createMediaType('test'); $this->drupalLogin($this->rootUser); $this->drupalGet('/admin/reports/status'); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains("The source field definition for the {$media_type->label()} media type is missing."); $this->assertSession()->pageTextNotContains("The source field definition for the {$valid_media_type->label()} media type is missing."); } } Loading
core/modules/media/media.install +24 −9 Original line number Diff line number Diff line Loading @@ -120,22 +120,37 @@ function media_requirements($phase) { } } // When a new media type with an image source is created we're configuring // the default entity view display using the 'large' image style. // Unfortunately, if a site builder has deleted the 'large' image style, // we need some other image style to use, but at this point, we can't // really know the site builder's intentions. So rather than do something // surprising, we're leaving the embedded media without an image style and // adding a warning that the site builder might want to add an image style. // @see Drupal\media\Plugin\media\Source\Image::prepareViewDisplay $module_handler = \Drupal::service('module_handler'); foreach (MediaType::loadMultiple() as $type) { // Load the default display. $display = \Drupal::service('entity_display.repository') ->getViewDisplay('media', $type->id()); // Check for missing source field definition. $source_field_definition = $type->getSource()->getSourceFieldDefinition($type); if (empty($source_field_definition) || !is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { if (empty($source_field_definition)) { $requirements['media_missing_source_field_' . $type->id()] = [ 'title' => t('Media'), 'description' => t('The source field definition for the %type media type is missing.', [ '%type' => $type->label(), ] ), 'severity' => REQUIREMENT_ERROR, ]; continue; } // When a new media type with an image source is created we're // configuring the default entity view display using the 'large' image // style. Unfortunately, if a site builder has deleted the 'large' image // style, we need some other image style to use, but at this point, we // can't really know the site builder's intentions. So rather than do // something surprising, we're leaving the embedded media without an // image style and adding a warning that the site builder might want to // add an image style. // @see Drupal\media\Plugin\media\Source\Image::prepareViewDisplay if (!is_a($source_field_definition->getItemDefinition()->getClass(), ImageItem::class, TRUE)) { continue; } Loading
core/modules/media/tests/src/Functional/MediaRequirementsTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -26,10 +26,13 @@ public function testMissingSourceFieldDefinition() { $field_storage_definition = $field_definition->getFieldStorageDefinition(); $field_definition->delete(); $field_storage_definition->delete(); $valid_media_type = $this->createMediaType('test'); $this->drupalLogin($this->rootUser); $this->drupalGet('/admin/reports/status'); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains("The source field definition for the {$media_type->label()} media type is missing."); $this->assertSession()->pageTextNotContains("The source field definition for the {$valid_media_type->label()} media type is missing."); } }