Add widget display image that provide default image by uploading Image file.

Project link

https://www.drupal.org/project/media_default_image

Comments

ckhalilo created an issue. See original summary.

vishal.kadam’s picture

Thank you for applying!

Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

The important notes are the following.

  • If you have not done it yet, you should run phpcs --standard=Drupal,DrupalPractice on the project, which alone fixes most of what reviewers would report.
  • For the time this application is open, only your commits are allowed.
  • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status won't be changed by this application and no other user will be able to opt projects into security advisory policy.
  • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

To the reviewers

Please read How to review security advisory coverage applications, Application workflow, What to cover in an application review, and Tools to use for reviews.

The important notes are the following.

  • It is preferable to wait for a Code Review Administrator before commenting on newly created applications. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
  • Reviewers should show the output of a CLI tool only once per application.
  • It may be best to have the applicant fix things before further review.

For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues.

vishal.kadam’s picture

Title: Media Default Image » [1.0.x] Media Default Image
Assigned: ckhalilo » Unassigned
Category: Support request » Task
Issue summary: View changes
vishal.kadam’s picture

Remember to change status, when the project is ready to be reviewed. In this queue, projects are only reviewed when the status is Needs review.

ckhalilo’s picture

The code is ready to review

ckhalilo’s picture

Status: Active » Needs review
vishal.kadam’s picture

Status: Needs review » Needs work

1. Fix phpcs issues.

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml media_default_image/

FILE: media_default_image/Readme.md
-----------------------------------------------------------------------
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES
-----------------------------------------------------------------------
 34 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
 36 | WARNING | [ ] Line exceeds 80 characters; contains 94 characters
 40 | ERROR   | [x] Expected 1 newline at end of file; 0 found
-----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------

2. FILE: media_default_image.module

/**
 * @file
 * Contains media default image module.
 */

The usual description for a .module file is “Hook implementations for the [module name] module”, where [module name] is the module name given in the .info.yml file.

3. FILE: src/Form/DefaultImageSettingsForm.php

Properties should be declared first in a class, followed by methods.

ckhalilo’s picture

Status: Needs work » Needs review

Comments #7 is fixed

vishal.kadam’s picture

Rest seems fine to me.

Let’s wait for other reviewers and Code Review Administrator to take a look and if everything goes fine, you will get the role.

avpaderno’s picture

Assigned: Unassigned » avpaderno

I will review the project tomorrow.

avpaderno’s picture

Assigned: avpaderno » Unassigned
Status: Needs review » Needs work
  • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
  • A specific point may just be an example and may apply in other places
  • A review is about code that does not follow the coding standards, contains possible security issue, or does not correctly use the Drupal API
  • The single review points are not ordered, not even by importance

src/Form/DefaultImageSettingsForm.php

If the settings are only used by a plugin, there is no need to create a form class. A plugin's form is returned by its settingsForm() method.

      catch (FileException $exception) {
        $this->logger('media_default_image')->error($exception->getMessage());
      }

The $message parameter passed to the LoggerInterface methods must be a literal string that uses placeholders. It's not a translatable string returned from t() or $this->t(), a string concatenation, nor a value returned from a function/method.

$form_state->setErrorByName('test', 'No image found for image one');

The second argument passed to ::setErrorByName() needs to be a translatable string.

src/Plugin/Field/FieldFormatter/DefaultImageFormatter.php

The parent class is not part of the public API and cannot be used as parent class for classes implemented by a contributed module. Only base classes can be used as parent class.

ckhalilo’s picture

Hi,
The reason why I use Form, I need to use default image multiple times, not only for the FieldFormatter.

I will fix the others issue.

Regards
Khalil

ckhalilo’s picture

Status: Needs work » Needs review

Hi,

I've updated my code, can you please review?

Best regards
Khalil

rushikesh raval’s picture

Priority: Normal » Critical

I am changing priority as per Issue priorities.

bbu23’s picture

Priority: Critical » Normal
Status: Needs review » Needs work

Hi @ckhalilo!
Below you have my feedback:

1. One of the issues reported in comment #11 is still pending in src/Form/DefaultImageSettingsForm.php file, validateForm() method.

2. In the DefaultImageSettingsForm.php the default_image field is not required, so that means that I can leave the field empty. The submitForm() method does not store the data when the field is empty, which can be confusing. Either make the field required or allow to store empty data.

3. The DefaultImageFormatter.php file duplicates significant code from web/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php. I was about to ask why not extending it, but it is unclear why you are trying to apply "image" options to a "media" formatter. You should consider extending the Rendered entity or Thumbnail formatters and simply handle the default image addition, and let the parent do its job, unless there's something that I am missing. By doing the current implementation you are cancelling the Media image usage.

4. You have some French comments in the createDefaultImageElement method.

5. There is no error handling for when a user attempts to use the formatter without any default image set.

6. The formatter seems to be intended for Media entity but the isApplicable method is not implemented to limit the options. Because of this I can set this formatter to any type of entity reference.

7. When you are building the default image element, you should consider adding the configuration as cacheable dependency.

8. Better replace "How to use" with "Configuration" in README and provide better info on how to configure and use the module. And it would be preferred to have the name of the README file in full uppercase.

9. The hook_help provides no relevant information.

10. It's still not clear what's the benefit of this module and the global configuration as mentioned in comments #11 and #12. The current explanation is

I need to use default image multiple times, not only for the FieldFormatter

but there is only one usage implemented in the module, and that's the field formatter.

avpaderno’s picture

Priority: Normal » Minor

I am changing priority as per Issue priorities.

ckhalilo’s picture

Status: Needs work » Needs review

Hi,

Point 1,2,4,5,6,8,9 fixed
Thank you for the point 3 i have updated to use extended MediaThumbnailFormatter, this work better now.
Point 7 is also fixed, now image has Cache dependency, thank you for remind me.

Point 10.
I understand that the module's scope is currently limited to Field Formatters.
The main objective is to centralize the configuration within a single interface, rather than managing it individually for each entity's field formatter.
If it were configured on a per-entity basis, this module wouldn't be necessary since users can already set default images in the standard image field settings.
I am already using it across six entity types (including Nodes and Taxonomy terms), which simplifies managing default images across various displays, such as Views

I have Updated my code.

Best Regards
Khalil

vishal.kadam’s picture

Priority: Minor » Normal

I am changing priority as per Issue priorities.

ckhalilo’s picture

Any updates please?

vishal.kadam’s picture

Priority: Normal » Major

I am changing priority as per Issue priorities.

vishal.kadam’s picture

Priority: Major » Critical

I am changing priority as per Issue priorities.

scontzen’s picture

Status: Needs review » Needs work

Automated Review

GitLab CI is not enabled for this project. I'd recommend enabling it, it catches a lot early. See GitLab CI setup.

Manual Review

Individual user account
Yes, follows the guidelines for individual user accounts.
No duplication
Yes. Provides a centralized, site-wide default image for media entity reference fields (different from core's per-field default image setting).
Master Branch
Yes, uses 1.0.x.
Licensing
Yes, follows the licensing requirements.
3rd party assets/code
Yes, no third-party libraries.
README.txt/README.md
Yes, has the required sections. Minor: filename is README.MD, the module documentation guidelines specify README.md (lowercase extension).
Code long/complex enough for review
Yes. ConfigFormBase with file handling, FieldFormatter plugin with DI, cache metadata.
Secure code
Yes, meets the security requirements. File uploads use proper validators, route has access control, Form API handles CSRF. No raw SQL, no unsafe markup.
Coding style & Drupal API usage
Cacheable dependencies for both config and file entity are correctly implemented, isApplicable() properly limits the formatter to media references.
  1. (*) No config/schema/media_default_image.schema.yml. The module stores configuration in media_default_image.settings but has no schema, which is required for validation, config export/import, and strict config mode. See Configuration schema/metadata.
  2. (*) The $message parameter passed to LoggerInterface methods must be a literal string that uses placeholders. In DefaultImageFormatter.php, settingsForm() passes $e->getMessage() and createDefaultImageElement() passes $exception->getMessage() directly.
  3. (*) In DefaultImageSettingsForm::submitForm(), file_usage is added for the new file but never removed for the previous one. Old files remain permanent and accumulate. The previous file ID should be loaded from config before saving, and $this->fileUsage->delete() called on the old file.
  4. (+) A new module that aims to be compatible with latest Drupal releases is expected to implement hooks as class methods as described in Support for OO hook implementations. The hook_help in media_default_image.module should be converted. This requires ^10.3 || ^11, but 10.2 is no longer supported.
  5. I noticed there is no composer.json. While drupal.org auto-generates one during packaging, having your own allows you to define keywords and license. If you add one, note that there is no need to add the required Drupal version, since that is already added by the Drupal.org Composer façade.

The starred items (*) warrant setting this back to Needs work.

This review uses the Project Application Review Template.

scontzen’s picture

Priority: Critical » Normal
ckhalilo’s picture

Status: Needs work » Needs review

I have commited changes

scontzen’s picture

Thanks for the update. All points from #22 are addressed:

  • Schema added at config/schema/media_default_image.schema.yml.
  • Logger calls in DefaultImageFormatter::settingsForm(), DefaultImageFormatter::createDefaultImageElement() and DefaultImageSettingsForm::submitForm() use literal strings with placeholders.
  • DefaultImageSettingsForm::submitForm() reads the previous file ID from config and calls fileUsage->delete() on the old file before saving the new one.
  • hook_help moved to MediaDefaultImageHooks with the #[Hook] attribute. The .module file is reduced to a docblock.
  • README extension changed to lowercase, composer.json added.

Looks good to me. RTBC from my side.

jnguyen23’s picture

Issue summary: View changes

I reviewed the current 1.0.x branch and cross-checked the existing comments through #25 so I only list points that I did not see already reported there.

The following items still warrant Needs work:

1. The module currently claims `core_version_requirement: ^10.3 || ^11`, but `src/Plugin/Field/FieldFormatter/DefaultImageFormatter.php` still uses the Drupal 10 `MediaThumbnailFormatter` constructor/create signature. In Drupal 11, `MediaThumbnailFormatter::__construct()` also requires `ImageDerivativeUtilities`, so this formatter is not actually compatible with Drupal 11 as declared. Please either adapt the formatter for both supported core branches or drop `^11` until that compatibility is in place.

2. `config/schema/media_default_image.schema.yml` defines `default_image` as a `sequence`, but `DefaultImageSettingsForm::submitForm()` saves a single fid (or `NULL`) with `$config->set('default_image', $fid)`. The schema should describe the shape that is actually stored, or the saved config should be changed to match the schema. As it stands, this is still a config schema mismatch.

I did not find a separate new security flaw beyond the API/schema issues above.

vishal.kadam’s picture

Issue summary: View changes
Status: Needs review » Needs work
vishal.kadam’s picture

Priority: Normal » Minor

I am changing priority as per Issue priorities.

avpaderno’s picture

This thread has been idle, in the needs work state with no activity for some months.

May you confirm you are still pursuing this application? If this is the case, and you made commits basing on what previously reported, or you can answer the questions previously asked, please change the status to Needs review.

avpaderno’s picture

Status: Needs work » Closed (won't fix)

This thread has been idle, in the Needs work state with no activity for about four months or more; the application has been created about 11 months ago or more. Therefore, I marked it as Closed (won't fix).

If this is incorrect, and you are still pursuing this application, please feel free to re-open it and set the issue status to Needs work or Needs review, depending on the current status of your code.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.