Skip to content
Snippets Groups Projects
Verified Commit a3655355 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3435906 by godotislate, afoerster: Default Images not rendered in layout builder

(cherry picked from commit 3cf0c074)
parent 8a1eead6
No related branches found
No related tags found
24 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #133176 passed
Pipeline: drupal

#133193

    Pipeline: drupal

    #133187

      Pipeline: drupal

      #133183

        +1
        ......@@ -22,6 +22,7 @@
        use Drupal\Core\Plugin\ContextAwarePluginInterface;
        use Drupal\Core\Session\AccountInterface;
        use Drupal\Core\StringTranslation\TranslatableMarkup;
        use Drupal\field\FieldConfigInterface;
        use Drupal\layout_builder\Plugin\Derivative\FieldBlockDeriver;
        use Psr\Log\LoggerInterface;
        use Symfony\Component\DependencyInjection\ContainerInterface;
        ......@@ -212,13 +213,7 @@ protected function blockAccess(AccountInterface $account) {
        }
        // Check to see if the field has any values or a default value.
        if ($field->isEmpty() && !$field->getFieldDefinition()->getDefaultValue($entity)) {
        // @todo Remove special handling of image fields after
        // https://www.drupal.org/project/drupal/issues/3005528.
        if ($field->getFieldDefinition()->getType() === 'image' && !empty($field->getFieldDefinition()->getSetting('default_image')['uuid'])) {
        return $access;
        }
        if ($field->isEmpty() && !$this->entityFieldHasDefaultValue()) {
        return $access->andIf(AccessResult::forbidden());
        }
        return $access;
        ......@@ -414,4 +409,33 @@ protected function getFormatter(array $parents, FormStateInterface $form_state)
        ]);
        }
        /**
        * Checks whether there is a default value set on the field.
        *
        * @return bool
        * TRUE if default value set, FALSE otherwise.
        */
        protected function entityFieldHasDefaultValue(): bool {
        $entity = $this->getEntity();
        $field = $entity->get($this->fieldName);
        $definition = $field->getFieldDefinition();
        if ($definition->getDefaultValue($entity)) {
        return TRUE;
        }
        // @todo Remove special handling of image fields after
        // https://www.drupal.org/project/drupal/issues/3005528.
        if ($definition->getType() !== 'image') {
        return FALSE;
        }
        $default_image = $definition->getSetting('default_image');
        // If we are dealing with a configurable field, look in both instance-level
        // and field-level settings.
        if (empty($default_image['uuid']) && ($definition instanceof FieldConfigInterface)) {
        $default_image = $definition->getFieldStorageDefinition()->getSetting('default_image');
        }
        return !empty($default_image['uuid']);
        }
        }
        ......@@ -66,14 +66,22 @@ protected function setUp(): void {
        'field_string_with_default' => 'It is ok to be different',
        'field_string_with_callback' => 'Not from a callback',
        'field_string_late_default' => 'I am way ahead of you.',
        'field_image_with_default' => [
        'target_id' => 2,
        'alt' => 'My different alt text',
        ],
        'field_image_no_default' => [
        'field_image_storage_default' => [
        'target_id' => 3,
        'alt' => 'My third alt text',
        ],
        'field_image_instance_default' => [
        'target_id' => 4,
        'alt' => 'My fourth alt text',
        ],
        'field_image_both_defaults' => [
        'target_id' => 5,
        'alt' => 'My fifth alt text',
        ],
        'field_image_no_default' => [
        'target_id' => 6,
        'alt' => 'My sixth alt text',
        ],
        ]);
        // Create node 2 relying on defaults.
        ......@@ -127,16 +135,31 @@ protected function assertNodeWithValues() {
        $assert_session->pageTextContains('field_string_late_default');
        $assert_session->pageTextNotContains('Too late!');
        $assert_session->pageTextContains('I am way ahead of you');
        // Image field with default should render non-default value.
        $assert_session->pageTextContains('field_image_with_default');
        $assert_session->responseNotContains('My default alt text');
        // Image field with storage default should render non-default value.
        $assert_session->pageTextContains('field_image_storage_default');
        $assert_session->responseNotContains('My storage default alt text');
        $assert_session->responseNotContains('test-file-1');
        $assert_session->responseContains('My different alt text');
        $assert_session->responseContains('test-file-2');
        // Image field with no default should render a value.
        $assert_session->pageTextContains('field_image_no_default');
        $assert_session->responseContains('My third alt text');
        $assert_session->responseContains('test-file-3');
        // Image field with instance default should render non-default value.
        $assert_session->pageTextContains('field_image_instance_default');
        $assert_session->responseNotContains('My instance default alt text');
        $assert_session->responseNotContains('test-file-1');
        $assert_session->responseContains('My fourth alt text');
        $assert_session->responseContains('test-file-4');
        // Image field with both storage and instance defaults should render
        // non-default value.
        $assert_session->pageTextContains('field_image_both_defaults');
        $assert_session->responseNotContains('My storage default alt text');
        $assert_session->responseNotContains('My instance default alt text');
        $assert_session->responseNotContains('test-file-1');
        $assert_session->responseNotContains('test-file-2');
        $assert_session->responseContains('My fifth alt text');
        $assert_session->responseContains('test-file-5');
        // Image field with no default should render a value.
        $assert_session->pageTextContains('field_image_no_default');
        $assert_session->responseContains('My sixth alt text');
        $assert_session->responseContains('test-file-6');
        }
        /**
        ......@@ -166,9 +189,15 @@ protected function assertNodeWithDefaultValues() {
        $assert_session->pageTextNotContains('field_string_late_default');
        $assert_session->pageTextNotContains('Too late!');
        // Image field with default should render default value.
        $assert_session->pageTextContains('field_image_with_default');
        $assert_session->responseContains('My default alt text');
        $assert_session->pageTextContains('field_image_storage_default');
        $assert_session->responseContains('My storage default alt text');
        $assert_session->responseContains('test-file-1');
        $assert_session->pageTextContains('field_image_instance_default');
        $assert_session->responseContains('My instance default alt text');
        $assert_session->responseContains('test-file-1');
        $assert_session->pageTextContains('field_image_both_defaults');
        $assert_session->responseContains('My instance default alt text');
        $assert_session->responseContains('test-file-2');
        // Image field with no default should not render.
        $assert_session->pageTextNotContains('field_image_no_default');
        // Confirm that there is no DOM element for the field_image_with_no_default
        ......@@ -259,7 +288,7 @@ protected function addImageFields() {
        // Create files to use as the default images.
        $files = $this->drupalGetTestFiles('image');
        $images = [];
        for ($i = 1; $i <= 3; $i++) {
        for ($i = 1; $i <= 6; $i++) {
        $filename = "test-file-$i";
        $desired_filepath = 'public://' . $filename;
        \Drupal::service('file_system')->copy($files[0]->uri, $desired_filepath, FileSystemInterface::EXISTS_ERROR);
        ......@@ -272,17 +301,57 @@ protected function addImageFields() {
        $images[] = $file;
        }
        $field_name = 'field_image_with_default';
        $field_name = 'field_image_storage_default';
        $storage_settings['default_image'] = [
        'uuid' => $images[0]->uuid(),
        'alt' => 'My default alt text',
        'alt' => 'My storage default alt text',
        'title' => '',
        'width' => 0,
        'height' => 0,
        ];
        $field_settings['default_image'] = [
        'uuid' => NULL,
        'alt' => '',
        'title' => '',
        'width' => NULL,
        'height' => NULL,
        ];
        $widget_settings = [
        'preview_image_style' => 'medium',
        ];
        $this->createImageField($field_name, 'test_node_type', $storage_settings, $field_settings, $widget_settings);
        $field_name = 'field_image_instance_default';
        $storage_settings['default_image'] = [
        'uuid' => NULL,
        'alt' => '',
        'title' => '',
        'width' => NULL,
        'height' => NULL,
        ];
        $field_settings['default_image'] = [
        'uuid' => $images[0]->uuid(),
        'alt' => 'My default alt text',
        'alt' => 'My instance default alt text',
        'title' => '',
        'width' => 0,
        'height' => 0,
        ];
        $widget_settings = [
        'preview_image_style' => 'medium',
        ];
        $this->createImageField($field_name, 'test_node_type', $storage_settings, $field_settings, $widget_settings);
        $field_name = 'field_image_both_defaults';
        $storage_settings['default_image'] = [
        'uuid' => $images[0]->uuid(),
        'alt' => 'My storage default alt text',
        'title' => '',
        'width' => 0,
        'height' => 0,
        ];
        $field_settings['default_image'] = [
        'uuid' => $images[1]->uuid(),
        'alt' => 'My instance default alt text',
        'title' => '',
        'width' => 0,
        'height' => 0,
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment