Introduction

Image Class 8 module allows site administrator to add css class to <img/> tag. This works independent of other contributed modules. The site administrator can add a css class through Manage Display of entity type.

Image Class 8 configuration

Project Page

https://www.drupal.org/sandbox/patilvishalvs/2603340

Pareview Results

http://pareview.sh/pareview/httpgitdrupalorgsandboxpatilvishalvs2603340git

Clone Repository

git clone --branch 8.x-1.x http://git.drupal.org/sandbox/patilvishalvs/2603340.git image_class_8
cd image_class_8 

Manual reviews of other projects

https://www.drupal.org/node/2595851#comment-10525996

Comments

patilvishalvs created an issue. See original summary.

patilvishalvs’s picture

Issue summary: View changes
patilvishalvs’s picture

Issue summary: View changes
StatusFileSize
new78.79 KB
PA robot’s picture

Status: Needs review » Needs work

There are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxpatilvishalvs2603340git

We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)

Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).

I'm a robot and this is an automated message from Project Applications Scraper.

patilvishalvs’s picture

Status: Needs work » Needs review

Updated the module as per recommendations given at http://pareview.sh/pareview/httpgitdrupalorgsandboxpatilvishalvs2603340git

patilvishalvs’s picture

Issue summary: View changes
patilvishalvs’s picture

Issue summary: View changes
vpeltot’s picture

Status: Needs review » Needs work

Hi

Good idea.
But your implementation is so Drupal 7.
I think it would be better if you create a new field formatter plugin for image fields, and completely delete your .module file.
Your new plugin must extend the ImageFormatter Plugin to keep all properties.

It's the same as what you have implement before, but in Drupal 8.

Place your plugin file in src/Plugin/Field/FieldFormatter.
Your plugin should look like this:


/**
 * @file
 * Contains Drupal\image_class_8\Plugin\Field\FieldFormatter\ImageClassFormatter.
 */

namespace Drupal\image_class_8\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter;

/**
 * Plugin implementation of the 'image_class' formatter.
 *
 * @FieldFormatter(
 *   id = "image_class",
 *   label = @Translation("Image custom class"),
 *   field_types = {
 *     "image"
 *   }
 * )
 */
class ImageClassFormatter extends ImageFormatter {

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
    return array(
      'class' => 'test_class',
    ) + parent::defaultSettings();
  }

  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
    $element = parent::settingsForm($form, $form_state);

    $element['class'] = array(
      '#type' => 'textfield',
      '#title' => t('Image Class'),
      '#default_value' => $this->getSetting('class'),
    );

    return $element;
  }

  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
    $elements = parent::viewElements($items, $langcode);

    foreach($elements as &$element) {
      $element['#item_attributes']['class'][] = $this->getSetting('class');
    }

    return $elements;
  }

}

patilvishalvs’s picture

@vpeltot thanks for reviewing the module. Also thanks for Plugin suggestion, I will work on it.

patilvishalvs’s picture

Issue summary: View changes
StatusFileSize
new59.02 KB
patilvishalvs’s picture

Updated the module as ImageClassFormatter plugin.

patilvishalvs’s picture

Issue summary: View changes
Status: Needs work » Needs review
vpeltot’s picture

Nice.
It's really better.
Everything is ok for me now.

Also, if you have time, my module needs to be reviewed :-)

vpeltot’s picture

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not cause module duplication and/or fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Followsthe licensing requirements.
3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements.
woprrr’s picture

Great job @patilvishalvs :) Work fine for me.

Manual Review

Individual user account
Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not cause module duplication and/or fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Followsthe licensing requirements.
3rd party assets/code
Yes: Follows the guidelines for 3rd party assets/code.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements.

Also, if you have time, my module needs to be reviewed too :-)

patilvishalvs’s picture

Issue summary: View changes
joachim’s picture

Have you seen https://www.drupal.org/project/field_formatter_class?
Could you explain how your project provides different functionality?

patilvishalvs’s picture

@joachim The field formatter class module allows to add a class to a field wrapper and Image Class 8 allow to add class to <img> tag.

shreepa.bss@gmail.com’s picture

hi,I installed https://www.drupal.org/project/field_formatter_class.I have a content type name:About us.In this content type I added an image field.I also created a view using this content type.in About us content type at image field I added a class named:image_circle but class is not added to my image filed.please give me any suggestion.I installed this version:8.x-1.x-dev tar.gz (7.95 KB) | zip (9.46 KB)

nishkris’s picture

This is not working for me , i'm getting one error in reports

User error: Invalid placeholder (!class) in string: Image Class: !class in Drupal\Component\Render\FormattableMarkup::placeholderFormat() (line 240 of core/lib/Drupal/Component/Render/FormattableMarkup.php).
Drupal\Component\Render\FormattableMarkup::placeholderFormat('Image Class: !class', Array)
patilvishalvs’s picture

@nishkris the issue is resolved. I have replaced ! with @ to resolve the issue.

sandeepguntaka’s picture

Good job @patilvishalvs :) its a good idea to create a module like this.
Automated Review
Has some warnings listed in pareview.sh
Manual Review

Individual user account

Yes: Follows the guidelines for individual user accounts.
No duplication
Yes: Does not cause module duplication and/or fragmentation.
Master Branch
Yes: Follows the guidelines for master branch.
README.txt/README.md
Yes: Follows the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes: Meets the security requirements.

patilvishalvs’s picture

@sandeepreddyg thank you for the review. I have updated changes to remove warnings listed in pareview.sh.

jonreid’s picture

Status: Needs review » Reviewed & tested by the community

Automated Review

No issues found on rerun.

Manual Review

Individual user account
[Yes: Follows] the guidelines for individual user accounts.
No duplication
[Yes: Does not cause] module duplication and/or fragmentation.
Master Branch
[Yes: Follows] the guidelines for master branch.
Licensing
[Yes: Follows] the licensing requirements.
3rd party assets/code
[Yes: Follows] the guidelines for 3rd party assets/code. No third party assets or code found.
README.txt/README.md
[Yes: Follows / No: Does not follow] the guidelines for in-project documentation and/or the README Template.
Code long/complex enough for review
[No: Does not follow] the guidelines for project length and complexity.
Secure code
[Yes: Meets the security requirements. / No: List of security issues identified.]
Coding style & Drupal API usage
[List of identified issues in no particular order. Use (*) and (+) to indicate an issue importance. Replace the text below by the issues themselves:
  1. No recommendations

The starred items (*) are fairly big issues and warrant going back to Needs Work. Items marked with a plus sign (+) are important and should be addressed before a stable project release. The rest of the comments in the code walkthrough are recommendations.

The module doesn't technically meet the minimum length guidelines in terms of number of function calls or source code length. I wouldn't consider this a blocker but it may be that the project won't qualify for the "create full projects" permission. Still, the code looks complete to me. It tests fine. If you're up for it, a nice option to extend the module size and provide an improved experience would be to add form validation. Possibly something around disallowing problematic class names like those starting with a hyphen.

If added, please don't remove the security tag, we keep that for statistics and to show examples of security problems.

This review uses the Project Application Review Template.

Jing Qian’s picture

dman’s picture

Status: Reviewed & tested by the community » Postponed

Given the reviews, I was about to double-check the code length and sign this off - but the module name/namespace stuck out at me terribly.
Why image_class_8? Well, because there is already Image Class which does exactly this same job in Drupal7. That is clear duplication, and it's clear you must have seen that earlier module when setting the module name.

Nobody else saw that in their "Duplication" review?

The initial code submission is very much the same shape as the image class module. Not an outright copy, but doing the same job, function-for-function.

There is even already a Drupal 8 module doing just this one, tiny job. Extra Image Field Classes With Code so similar to the same file in this module it is SCARY.

:-{

Every reviewer that claimed No duplication has been failing even a preliminary module search.

Sorry, (Although I respect it's a small, tidy module with some handy utility) - This is such a clear case of trivial module duplication, This has to go on hold.

dman’s picture

StatusFileSize
new233.86 KB

klausi’s picture

Status: Postponed » Closed (won't fix)

Oh, this is sad.

@patilvishalvs: please do not copy other modules and present them as your own work. Your behavior violates 2 essential points of our code of conduct: be respectful and be collaborative https://www.drupal.org/dcoc

EDIT: removed warning.

manarth’s picture

I'd like to give @patilvishalvs the benefit of the doubt, and note that the first commit to the sandbox was in October 2015, which is when this Project Application was opened.

The earliest commit for Extra Image Field Classes was in February 2016, 4 months after this application began: https://www.drupal.org/node/2672714/commits

The similarity in code suggests very strongly that the code was copied, but without understanding more about the background and without seeing any other relevant commit history, it's difficult to recognise who copied who, or the genuine origin of the code.

I do agree though that where there is an older module for the same purpose - e.g. a D7 equivalent - people should initially try to collaborate with the maintainers of that module, rather than branch off and create their own D8 version. There's as much - if not more - kudos in being a co-maintainer of a module as there is in creating a new one.

dman’s picture

Despite the astonishing similarity, I was still OK with imagining it was parallel evolution. (my world is nicer if I imagine people are nice).
If you look up this thread, you'll see that all the actual code was given in full by vpeltot !!.
I didn't see that earlier, I just went checking for duplication when I saw how basic the job was.

I think this starts to show the conformity that Drupal8 plugins are bringing to the ecosystem. Given the trivial nature of this module, there are not really any more or less lines of code that would achieve this exact result! vpeltot earned all the points here.

The 'trivial' part also means that it would certainly fail with respect to being unique or complex enough, as it's a classroom exercise now - testing if you can read the d.o. documentation and regurgitate.

patilvishalvs’s picture

@dman, thanks for reviewing the module. I would like to mention that the module is inspired from Image class module, but as there was no drupal 8 release available for it, I created a new module. Also first commit of Extra Image Field Classes was on February 21, 2016 17:03 and of Image class 8 was on October 28, 2015 18:17 and the code modifications mentioned by @vpeltot were committed on October 30, 2015 11:41. This means I have implemented the code before Extra Image Field Classes. I don't mind giving credits to @vpeltot for providing the nice code.

klausi’s picture

Oops, I apologize for my harsh comment in light of that.

Feel free to open a new project application when you have a new project to promote. And for all Drupal 8 ports of existing modules please contribute them to the existing projects instead by opening issues there. Thanks!