Unverified Commit 3ea43896 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3205866 by danflanagan8, phenaproxima: media_requirements() should...

Issue #3205866 by danflanagan8, phenaproxima: media_requirements() should report missing source fields

(cherry picked from commit d8b4e40b)
parent 1a5f7f75
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line
@@ -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;
      }

+3 −0
Original line number Diff line number Diff line
@@ -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.");
  }

}