ImageWidgetCrop

Project description :

Provides an interface for using the features of the Crop API. This widget provide an UX for use a crop on all fields images. This module have particularity to purpose capability to crop the same image by 'Crop type' configured. It's very usefull for editorial sites or media management sites.

By example if you have same image in 3 differents emplacement provide by same field image. You can specify on the rendered view_mode the image style to display this field image but if you have 3 formats ratio different your image have chance to destroy with classic image scale and crop.

You have a chance to loose a part of your subject in the picture, with ImageCropWidget you can specify by image style (can group by Crop Type) a specific crop.

Installation and Configuration

Installation

Download and install the image_widget_crop module as normal. Just like other modules. Install modules on "sites/all/contrib/module/" crop."

Try demo module

You can Test ImageWidgetCrop in action directly with the sub-module "ImageWidgetCrop examples" to test differents usecase of this module.

ImageWidgetCrop Code Quality

SensioLabsInsight
Scrutinizer
Travis-ci

Requirements

Module Crop API.
For ImageWidgetCrop Examples : Read readme.md.

Configuration

@See Drupal Media d8 guide.
https://drupal-media.gitbooks.io/drupal8-guide/content/modules/image_wid...

Sandbox project page link:
https://www.drupal.org/sandbox/woprrr/2571403

Pareview results:
http://pareview.sh/pareview/httpgitdrupalorgsandboxwoprrr2571403-0

To clone the project:

git clone --branch 8.x-1.x http://git.drupal.org/sandbox/woprrr/2571403.git image_widget_crop
cd image_widget_crop

Manual reviews of other projects :
https://www.drupal.org/node/2595851#comment-10502500
https://www.drupal.org/node/2368123#comment-10735792
https://www.drupal.org/node/2604294#comment-10594692

CommentFileSizeAuthor
#37 coder-results.txt3.31 KBklausi
#11 logo_CROP.psd414.34 KBwoprrr
ImageWidgetCrop.png759.07 KBwoprrr
#12 iwc_logo.png21.68 KBwoprrr

Comments

woprrr created an issue. See original summary.

woprrr’s picture

Issue summary: View changes
PA robot’s picture

Issue summary: View changes
Status: Needs review » Needs work

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

Fixed the git clone URL in the issue summary for non-maintainer users.

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.

woprrr’s picture

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

Issue summary: View changes
woprrr’s picture

Issue summary: View changes
PA robot’s picture

Issue summary: View changes

Fixed the git clone URL in the issue summary for non-maintainer users.

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

woprrr’s picture

Issue summary: View changes
woprrr’s picture

Issue summary: View changes
woprrr’s picture

Issue summary: View changes
woprrr’s picture

Issue summary: View changes
StatusFileSize
new414.34 KB
woprrr’s picture

StatusFileSize
new21.68 KB
woprrr’s picture

Issue summary: View changes
woprrr’s picture

This module is now fully ready and test in two site (1 in production environnement). I need some Tester for pass in fullProject. You can now enable a sub module 'ImageWidgetCrop Examples' for test this module easily.

Thanks for your support.

woprrr’s picture

Issue tags: +PAreview: review bonus
vpeltot’s picture

Hi woprrr

I focused my first code review in your hook_entity_presave implementation.

1. Image widget service

Why are you call the image_widget_crop.manager service in each iteration of the foreach ?

/** @var \Drupal\image_widget_crop\ImageWidgetCrop $crop */
$crop = \Drupal::service('image_widget_crop.manager');

It would be better to move this piece of code outside the foreach.

2. Route parameter

Why you check the 'edit' value in route parameter ?

// Get the route params attributes.
$route_params = \Drupal::requestStack()
->getCurrentRequest()->attributes->get('_route_params');

if (isset($route_params['_entity_form']) && preg_match('/.edit/', $route_params['_entity_form'])) {
  $edit = TRUE;
}

If I understand, you would know if the current saving request comes from an edit form, is that right ?
You can use $entity->isNew() to check that.

node/add : $entity->isNew() == TRUE
node/#/edit : $entity->isNew() == FALSE

3. Multiple value

Your module works fine with contents containing an image field with a number of value equals to 1.
I tried to add a field with multiple value, Only the first crop is saved.
In this hook_entity_presave, this code is the cause

$entity_fields->getValue()['0']

You must iterate on all field value.

You must handle these cases :

New entity -> No images
New entity -> Add 1 image
New entity -> Add 2 (or more) images
Edit entity -> No images -> Add 1 image
Edit entity -> No images -> Add 2 (or more) image
Edit entity -> 1 image -> Add more images
Edit entity -> 2 (or more) images -> Add more images
Edit entity -> 1 image -> Remove 1 image
Edit entity -> 2 (or more) images -> Remove 1 image
Edit entity -> 2 (or more) images -> Remove 2 (or more) images
Delete entity -> delete all images
vpeltot’s picture

Status: Needs review » Needs work
woprrr’s picture

Hi @vpeltot, First THANK LOT !! for your precious returns :)

I respond point by point :

1. Image widget service : The image_widget_crop.manager service is call in each itteration is true But, he does not spend much time in this loop, it passes over x field_image using image_widget_crop different. But especially not by elements present in the field. In most cases therefore one time or 2 times (because if your need to crop two different images increase cardinality and it work).

2. Route parameter : It's TRUE !! Thanks : ) I ve changed it now is good you can confirm this :) ?

3. Multiple value : Right ! After my big refactor i ve forget to test this case again ! Now in my new commit i ve fix this feature and améliorate the javascript. I adapt the message to specify the filename of image modified in addition to the information of cropType.

For realize this is required to add a loop after parse all Crop values. (Why ? getFields() is an array map and table contains as many as there are fields). If we need to delete this loop we need to create another widget to cardinality unlimited, I thinks is bad, if we need add this foreach to manage all feature is better way.

woprrr’s picture

Status: Needs work » Needs review
vpeltot’s picture

Status: Needs review » Needs work

Nice !
I watched the rest of your code. Everything seems good !

Just one thing, I found a bug by following this steps :

  1. Allow multiple value in your field
  2. Create a new content
  3. Add one image
  4. Select the crop zone
  5. Add another image

Paf, previously selected crop zones are disapeared !

Maybe javascript ?

woprrr’s picture

Hi vpeltot, no it s normal the ajax form refresh all element and use a stopPropagation for stop all javascript element the normal way is add your images and after crop your zone. If you need add an image in edit mode you can but add your images and after crop.

woprrr’s picture

Hello, The latest version with the widget is 100% compatible and debug (JS level also unlimited cardinality mode).

Thank you to you for this review @vpeltot :)

Also merge slide by using default that appears never to have a case where there is an empty area.

Thanks all for your time :)

woprrr’s picture

Status: Needs work » Needs review
woprrr’s picture

Issue tags: +D8Media, +#d8ux
woprrr’s picture

Issue summary: View changes
woprrr’s picture

@Vpeltot now is Ok for your case (https://www.drupal.org/node/2573087#comment-10508480).

I also improve the detection of elements saved even if the item has not yet submitted, allowing to have saved on the line corresponding to the crop even in case the user adds other slides. This allows not to lose the selections but also to clearly identify the areas already treated.

Thanks :).

woprrr’s picture

Issue summary: View changes
woprrr’s picture

Update processed in project :), The activity in Issue queu is good ready to became full project ...

chandrasekhar539’s picture

Hi woprrr,

please fix the errors in parreview

Manual Review:
Individual user account: Follows
No duplication: See #4
Master Branch: Follows
Licensing: Follows
3rd party assets/code: N/A
README.txt/README.md: Follows
Coding style & Drupal API usage:
Automated review: errors

woprrr’s picture

Thanks After my refactor I ve use JSLint, now i am based ok ESlint. Thanks :) is correct now see pareview. The last codespell on yml is not an coding error and generated by drupal.

woprrr’s picture

Currently we're thinking already has a version of "standardization" and a second existing reprennand more "exotic". I think the sandbox should move as quickly as possible to enable the project to the Media team to work more simply via DO

woprrr’s picture

We have change a lot of concepts in this module during Media week long. Media team have work on version more standard in first time and purpose an "complex" UI like old version after.

@see https://www.drupal.org/node/2625026

klausi’s picture

Issue tags: -PAreview: review bonus

Removing review bonus tag, you have not listed any reviews in the issue summary? Make sure to read through the source code of the other projects, as requested on the review bonus page.

woprrr’s picture

Issue summary: View changes
woprrr’s picture

@klausi I ve add my other reviews, I participate a lot in media feature on D8 ( i maintain Crop_api / IWC ) and i help in IEF.
I have not had much time for other projects but I made the best to promote this one is very expected in fullproject everything is ok now?

woprrr’s picture

Issue tags: +PAreview: review bonus
klausi’s picture

Assigned: Unassigned » dave reid
Priority: Major » Normal
Status: Needs review » Reviewed & tested by the community
Issue tags: -PAreview: review bonus
StatusFileSize
new3.31 KB

Review of the 8.x-1.x branch (commit 2b27b12):

This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.

manual review:

  1. project page: what is the use case of the module, what problem does it solve? Does it operate on image fields I assume? Or on Form API file elements? What image toolkit does it use, how does it crop the images? What does the UI look like, can you provide a screenshot on the project page?
  2. image_widget_crop.info.yml: why does the module depend on the node module? Please add a comment.
  3. image_widget_crop.services.yml: the entity manager service is deprecated. use one of the replacements instead, see https://www.drupal.org/node/2549139
  4. "method_exists($entity, 'getFields')": do not check if the method exists, check if the entity implements the correct interface with instanceof, FieldableEntityInterface.
  5. ImageWidgetCropManager: a service should usually not invoke drupal_set_message(), since it might be used in other contexts where no messages should be shown. Use return values instead to indicate success/failure. Or use your notify parameter pattern everywhere.
  6. ImageWidgetCropManager: do not use \Drupal in service classes. Inject the service instead. Also elsewhere in ImageCropWidget.php for example.
  7. getCropOriginalDimension: RuntimeException: what image file is not valid? Can you pass on an ID or something?
  8. "@return array" should be "@return double[]"
  9. ImageCropWidget::process: why do you need the route params here? why do you need to check if you are on a form here? Please add a comment.
  10. " Add compatibility to PHP 5.3.": Drupal 8 core depends on PHP 5.5, so you should remove all PHP 5.3 compatibility code and comments.
  11. ImageCropWidget: don't use the function t() in objects if possible. Use $this->t() instead in this case, which is already on the parent class.
  12. ImageWidgetCropTest: don't use \Drupal here, use $this->container->get() to access services.
  13. ImageWidgetCropTest: $this->randomMachineName(): do not use random test data in tests which makes them unpredictable. See https://www.drupal.org/node/2571183

But that are not critical application blockers, otherwise looks good to me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

Assigning to Dave Reid as he might have time to take a final look at this.

woprrr’s picture

For pareview return ATM we don't have choose, we need to use eval() we process an large refactor and clean up of js / php calculation architecture (@see https://www.drupal.org/node/2641970 ).

project page: what is the use case of the module, what problem does it solve? Does it operate on image fields I assume? Or on Form API file elements? What image toolkit does it use, how does it crop the images? What does the UI look like, can you provide a screenshot on the project page?

The answers to these questions lies in the doccumentation page dedicate a drupal-media ( https://drupal-media.gitbooks.io/drupal8-guide/content/modules/image_wid... ). I'll add a link to this doccumentation and would make a doc about DO

image_widget_crop.info.yml: why does the module depend on the node module? Please add a comment.

Fixed.

image_widget_crop.services.yml: the entity manager service is deprecated. use one of the replacements instead, see https://www.drupal.org/node/2549139

Fixed.

"method_exists($entity, 'getFields')": do not check if the method exists, check if the entity implements the correct interface with instanceof, FieldableEntityInterface.

Fixed @klausi Thanks a lot.

ImageWidgetCropManager: do not use \Drupal in service classes. Inject the service instead. Also elsewhere in ImageCropWidget.php for example.

In ImageWidgetCropManager we have any /Drupal call, in ImageCropWidget class is obligatory in static méthod. process method is defined static in core we can change it to inject our code. In github we have an issue to transform all element define in process into new form element ( @see https://github.com/drupal-media/image_widget_crop/pull/1#issuecomment-17... ).

"@return array" should be "@return double[]"

It's same, i process scrutinizer analyze and he require an @return array instead double[].

ImageCropWidget::process: why do you need the route params here? why do you need to check if you are on a form here? Please add a comment.

We need to be sure to be in an editing context of an entity when we access a process().

" Add compatibility to PHP 5.3.": Drupal 8 core depends on PHP 5.5, so you should remove all PHP 5.3 compatibility code and comments.

Fixed.

ImageCropWidget: don't use the function t() in objects if possible. Use $this->t() instead in this case, which is already on the parent class.

Fixed. ( We have a real gain? Can you explain to me or give me a doc about the difference? )

For the two remaining points I create a way to fix that.

Thanks a lot @klausi !

slashrsm’s picture

Assigned: dave reid » Unassigned

In ImageWidgetCropManager we have any /Drupal call, in ImageCropWidget class is obligatory in static méthod. process method is defined static in core we can change it to inject our code. In github we have an issue to transform all element define in process into new form element ( @see https://github.com/drupal-media/image_widget_crop/pull/1#issuecomment-17... ).

One \Drupal::service() call is in static function, but the other is not. Also, deprecated entity.manager is still used in one of them. Would be great to check entire module for usages of entity manager.

It's same, i process scrutinizer analyze and he require an @return array instead double[].

Drupal standard is double[].

We need to be sure to be in an editing context of an entity when we access a process().

I agree with @klausi that this isn't the nicest solutions. Why can't we simply try to load? If nothing comes back it is obvious that there is no crop for the image. But I also agree that it is not critical. Specially considering the fact that we're planning to refactor this part significantly. As @woprrr already mentioned we're planning to convert cropping tool to a decoupled form element. We will fix this kind of problems along the way.

Unrelated to stuff above.... This module has already been adopted by Media initiative. It has a copy in drupal-media group on Github and it following our standard development process. We invested significant amount of time into it in past few months. It was one of the focuses at Zurich media sprint, that happened in December.

It was great to work with @woprrr. He is very open for other ideas, very collaborative, responsive and open for suggestions. All this will make him a great module maintainer.

This is good to go as far as I am concerned. I am pretty sure everyone in the initiative that worked on this module (many people!) agree with me.

klausi’s picture

Status: Reviewed & tested by the community » Fixed

OK, I think another RTBC from @slashrsm is enough to approve this.

Thanks for your contribution, woprrr!

I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.