Skip to content
Snippets Groups Projects

Issue #2107455 by mparker17, ravi.shankar, yogeshmpawar, pooja saraah,...

Open Issue #2107455 by mparker17, ravi.shankar, yogeshmpawar, pooja saraah,...
2 unresolved threads
2 unresolved threads

Issue #2107455 by mparker17, ravi.shankar, yogeshmpawar, pooja saraah, joseph.olstad, claudiu.cristea, KapilV, ShaunDychko, andileco, drclaw, xjm, alexpott: Allow the $items parameter to be nullable thanks to code sniffer. Image field default value not shown when upload destination set to private file storage

Closes #2107455

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
35 public function __construct(
36 #[Autowire(service: 'cache.default')]
37 protected readonly CacheBackendInterface $cache,
38 protected readonly EntityTypeManagerInterface $entityTypeManager,
39 protected readonly EntityRepositoryInterface $entityRepository,
40 protected readonly EntityFieldManagerInterface $entityFieldManager,
41 protected readonly AccountInterface $currentUser,
42 protected readonly ImageFactory $imageFactory,
43 protected readonly ConfigFactoryInterface $configFactory,
44 protected readonly ModuleHandlerInterface $moduleHandler,
45 ) {}
46
47 /**
48 * Implements hook_file_download().
49 */
50 public function __invoke($uri): array|int|null {
  • 155 // First, check if the default image is set on the field storage.
    156 $uri_from_storage = NULL;
    157 $file_uuid = $field_storages[$field_name]->getSetting('default_image')['uuid'];
    158 if ($file_uuid && $file = $this->entityRepository->loadEntityByUuid('file', $file_uuid)) {
    159 /** @var \Drupal\file\FileInterface $file */
    160 $uri_from_storage = $file->getFileUri();
    161 $cache_tags = Cache::mergeTags($cache_tags, $file->getCacheTags());
    162 }
    163
    164 foreach ($field_info['bundles'] as $bundle) {
    165 $field_definition = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle)[$field_name];
    166 $default_uri = $uri_from_storage;
    167 $file_uuid = $field_definition->getSetting('default_image')['uuid'];
    168 // If the default image is overridden in the field definition, use
    169 // that instead of the one set on the field storage.
    170 if ($file_uuid && $file = $this->entityRepository->loadEntityByUuid('file', $file_uuid)) {
    • && is higher than = in order of operations. It also doesn't look like there is test coverage for the default image being set on the bundle field config instead of field storage.

      Suggested change
      171 if ($file_uuid && $file = $this->entityRepository->loadEntityByUuid('file', $file_uuid)) {
      171 if ($file_uuid && ($file = $this->entityRepository->loadEntityByUuid('file', $file_uuid))) {
    • I don't see an issue with operator precedence here. It only affects readability, and there are no standards that require this.

      Edited by kksandr
    • And this conditional structure is widely used in the core. For example, #1, #2, #3...

    • OK, I do see this note on https://www.php.net/manual/en/language.operators.precedence.php, so TIL in PHP:

      Although = has a lower precedence than most other operators, PHP will still allow expressions similar to the following: if (!$a = foo()), in which case the return value of foo() is put into $a.

      As mentioned in the issue, a similar conditional in https://www.drupal.org/project/drupal/issues/3403999 was problematic, ($batch = batch_get() && isset($batch['current_set'])), but apparently PHP knows that you need a variable to do the assigning.

      Regardless, I don't see test coverage for the default image being set on the field config with a private image. AFAICT, Drupal\Tests\image\Functional\ImageFieldDisplayTest::testImageFieldDefaultImage() only has a test for default images set on the field storage config.

    • Please register or sign in to reply
  • kksandr added 1 commit

    added 1 commit

    • 2453ee81 - Apply 1 suggestion(s) to 1 file(s)

    Compare with previous version

  • kksandr added 1 commit

    added 1 commit

    Compare with previous version

  • kksandr added 1 commit

    added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • Matthias Lünemann added 414 commits

    added 414 commits

    Compare with previous version

  • Matthias Lünemann added 36 commits

    added 36 commits

    Compare with previous version

  • Matthias Lünemann added 43 commits

    added 43 commits

    Compare with previous version

  • Please register or sign in to reply
    Loading