Skip to content
Snippets Groups Projects
Verified Commit 702aba79 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3276845 by shalini_jha, chris burge, smustgrave, bramdriesen, larowlan:...

Issue #3276845 by shalini_jha, chris burge, smustgrave, bramdriesen, larowlan: MediaSourceBase::getSourceFieldName() doesn't check character max
parent bc6599bf
Branches
Tags
9 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!11131[10.4.x-only-DO-NOT-MERGE]: Issue ##2842525 Ajax attached to Views exposed filter form does not trigger callbacks,!10786Issue #3490579 by shalini_jha, mstrelan: Add void return to all views...,!5423Draft: Resolve #3329907 "Test2",!3478Issue #3337882: Deleted menus are not removed from content type config,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation
Pipeline #384480 passed with warnings
Pipeline: drupal

#384495

    Pipeline: drupal

    #384490

      Pipeline: drupal

      #384488

        ......@@ -6,6 +6,7 @@
        use Drupal\Core\Entity\Display\EntityFormDisplayInterface;
        use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
        use Drupal\Core\Entity\EntityFieldManagerInterface;
        use Drupal\Core\Entity\EntityTypeInterface;
        use Drupal\Core\Entity\EntityTypeManagerInterface;
        use Drupal\Core\Field\FieldTypePluginManagerInterface;
        use Drupal\Core\Form\FormStateInterface;
        ......@@ -314,10 +315,16 @@ protected function getSourceFieldName() {
        // Iterate at least once, until no field with the generated ID is found.
        do {
        $id = $base_id;
        // Limit the base field name to the maximum allowed length.
        $id = (strlen($base_id) > EntityTypeInterface::ID_MAX_LENGTH) ? substr($base_id, 0, EntityTypeInterface::ID_MAX_LENGTH) : $base_id;
        // If we've tried before, increment and append the suffix.
        if ($tries) {
        $id .= '_' . $tries;
        // Ensure the suffixed field name does not exceed the maximum allowed length.
        if (strlen($id) > EntityTypeInterface::ID_MAX_LENGTH) {
        $id = substr($base_id, 0, (EntityTypeInterface::ID_MAX_LENGTH - strlen('_' . $tries))) . '_' . $tries;
        }
        }
        $field = $storage->load('media.' . $id);
        $tries++;
        ......
        ......@@ -21,3 +21,7 @@ media.source.test_hidden_source_field:
        media.source.test_different_displays:
        type: media.source.test
        label: 'Test media source with different source field displays'
        media.source.test_source_with_a_really_long_name:
        type: media.source.test
        label: 'Test source with a really long name'
        <?php
        declare(strict_types=1);
        namespace Drupal\media_test_source\Plugin\media\Source;
        use Drupal\Core\StringTranslation\TranslatableMarkup;
        use Drupal\media\Attribute\MediaSource;
        /**
        * Provides test media source.
        */
        #[MediaSource(
        id: 'test_source_with_a_really_long_name',
        label: new TranslatableMarkup('Test source with a really long name'),
        description: new TranslatableMarkup('Test source with a really long name.'),
        allowed_field_types: ['string'],
        )]
        class TestSourceWithAReallyLongName extends Test {
        }
        ......@@ -516,6 +516,43 @@ public function testSourceFieldCreation(): void {
        $this->assertEquals('Test source with constraints', $field->label(), 'Incorrect label is used.');
        $this->assertSame('test_constraints_type', $field->getTargetBundle(), 'Field is not targeting correct bundle.');
        // Test a source with a long machine name.
        $type = MediaType::create([
        'id' => 'test_type_fail',
        'label' => 'Test type - Fail',
        'source' => 'test_source_with_a_really_long_name',
        ]);
        $type->save();
        /** @var \Drupal\field\Entity\FieldConfig $field */
        $field = $type->getSource()->createSourceField($type);
        /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
        $field_storage = $field->getFieldStorageDefinition();
        $field_storage->save();
        // Field configuration depends on the field storage, which must be saved first.
        $field->save();
        // Test long field name is truncated.
        $this->assertSame('field_media_test_source_with_a_r', $field_storage->getName(), 'Incorrect field name is used.');
        $type = MediaType::create([
        'id' => 'test_type_fail_2',
        'label' => 'Test type - Fail 2',
        'source' => 'test_source_with_a_really_long_name',
        ]);
        $type->save();
        /** @var \Drupal\field\Entity\FieldConfig $field */
        $field = $type->getSource()->createSourceField($type);
        /** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
        $field_storage = $field->getFieldStorageDefinition();
        $field_storage->save();
        // Field configuration depends on the field storage, which must be saved first.
        $field->save();
        // Test long field name is truncated.
        $this->assertSame('field_media_test_source_with_a_1', $field_storage->getName(), 'Incorrect field name is used.');
        // Test that new source fields respect the configured field prefix, no
        // prefix at all if that's what's configured.
        $this->installConfig('field_ui');
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment