Problem/Motivation

This modules comes with a very nice UI. Focal point selector tool is currently coupled with image field. It would be very nice to be able to use it on other places too. One example would be file edit page that file_entity provides. There is even more. I believe this tool could be useful even outside of cropping problem. In every situation where some specific point on an image needs to be selected, for whatever reason, we could use the tool that this module provides.

Proposed resolution

I propose that we create a form element that will be responsible for focal point selection tool. Then we use this element on the image widget.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

slashrsm created an issue. See original summary.

chr.fritsch’s picture

Status: Active » Needs review
StatusFileSize
new13.33 KB

Here is a first draft of the focal_point form element. I'am pretty sure that this is not ready, but i want to get some feedback to see if i'am on the right track.

spadxiii’s picture

It might be an idea to wait until this is committed into dev: https://www.drupal.org/node/2701861

bleen’s picture

agreed

davy-r’s picture

Status: Needs review » Needs work

Just a heads up, Create focal point specific image field widget is committed.

Plugin widget 'image_focal_point' is now available, changing the status accordingly.

tanc’s picture

It looks like a good time to move onto this task now that #2701861: Create focal point specific image field widget is complete. Having a standalone form would reduce the code in #2701725: Integrate focal point with file entity and entity browser

bleen’s picture

Been playing with this for a couple days... Hope to have a patch today

bleen’s picture

StatusFileSize
new23.23 KB

Ok ... this is where I am at. The attached patch is not nearly finished. Things that are still problems:

  1. It doesn't work...
  2. The focal point value is saved, but not displayed on the form properly. This is because "50,50" is hard coded in the focalpoint image widget process function.
  3. There may (or may not) be a weird js issue where some bizarre errors show up ... needs more looking into
  4. By replacing the preview widget with the focal point element, the focal point value is referred to as "preview" in a lot of places. I think this should be fixed so that we remove the preview value and add the focal point value instead.
  5. The focal point value should ultimately work very similar to the "alt" value. It should travel with the image in the same way, but right now it doesn't.
  6. As is, this patch breaks the field-widget-based settings for "show preview link" and "default offsets"
  7. Focal point is showing up on the node/add form before an image is uploaded
  8. Double clicking on the focal point indicator shows the focal point field as it should (YAY!), but it breaks the form a bit (BOOO!)
  9. TESTS!

Other than that, this is good to go ;)

Any help on this would be very much appreciated!!

bleen’s picture

StatusFileSize
new23.73 KB
new5.46 KB
  1. It doesn't work...
  2. The focal point value is saved, but not displayed on the form properly. This is because "50,50" is hard coded in the focalpoint image widget process function.
  3. There may (or may not) be a weird js issue where some bizarre errors show up ... needs more looking into
  4. By replacing the preview widget with the focal point element, the focal point value is referred to as "preview" in a lot of places. I think this should be fixed so that we remove the preview value and add the focal point value instead.
  5. The focal point value should ultimately work very similar to the "alt" value. It should travel with the image in the same way, but right now it doesn't.
  6. As is, this patch breaks the field-widget-based settings for "show preview link" and "default offsets"
  7. Focal point is showing up on the node/add form before an image is uploaded
  8. Double clicking on the focal point indicator shows the focal point field as it should (YAY!), but it breaks the form a bit (BOOO!)
  9. TESTS!
bleen’s picture

StatusFileSize
new25.76 KB
new12.25 KB

This is definitely closer to how things should be, but still lots left to do:

  1. It doesn't work...
  2. The focal point value is saved, but not displayed on the form properly. This is because "50,50" is hard coded in the focalpoint image widget process function.
  3. There may (or may not) be a weird js issue where some bizarre errors show up ... needs more looking into
  4. By replacing the preview widget with the focal point element, the focal point value is referred to as "preview" in a lot of places. I think this should be fixed so that we remove the preview value and add the focal point value instead.
  5. The focal point value should ultimately work very similar to the "alt" value. It should travel with the image in the same way, but right now it doesn't.
  6. As is, this patch breaks the field-widget-based settings for "show preview link" and "default offsets"
  7. Focal point is showing up on the node/add form before an image is uploaded
  8. Double clicking on the focal point indicator shows the focal point field as it should (YAY!), but it breaks the form a bit (BOOO!)
  9. TESTS!
bleen’s picture

StatusFileSize
new25.08 KB
new9.39 KB
  1. It doesn't work...
  2. The focal point value is saved, but not displayed on the form properly. This is because "50,50" is hard coded in the focalpoint image widget process function.
  3. There may (or may not) be a weird js issue where some bizarre errors show up ... needs more looking into
  4. By replacing the preview widget with the focal point element, the focal point value is referred to as "preview" in a lot of places. I think this should be fixed so that we remove the preview value and add the focal point value instead.
  5. The focal point value should ultimately work very similar to the "alt" value. It should travel with the image in the same way, but right now it doesn't.
  6. As is, this patch breaks the field-widget-based settings for "show preview link" and "default offsets"
  7. Focal point is showing up on the node/add form before an image is uploaded
  8. Double clicking on the focal point indicator shows the focal point field as it should (YAY!), but it breaks the form a bit (BOOO!)
  9. TESTS!
  10. The element is still too coupled with image widget because it expects the preview thumbnail to be passed in ... we should make that optional or just generate the preview thumbnail ourselves.
bleen’s picture

StatusFileSize
new25.24 KB
new2.81 KB
  1. It doesn't work...
  2. The focal point value is saved, but not displayed on the form properly. This is because "50,50" is hard coded in the focalpoint image widget process function.
  3. There may (or may not) be a weird js issue where some bizarre errors show up ... needs more looking into
  4. By replacing the preview widget with the focal point element, the focal point value is referred to as "preview" in a lot of places. I think this should be fixed so that we remove the preview value and add the focal point value instead.
  5. The focal point value should ultimately work very similar to the "alt" value. It should travel with the image in the same way, but right now it doesn't.
  6. As is, this patch breaks the field-widget-based settings for "show preview link" and "default offsets"
  7. Focal point is showing up on the node/add form before an image is uploaded
  8. Double clicking on the focal point indicator shows the focal point field as it should (YAY!), but it breaks the form a bit (BOOO!)
  9. TESTS!
  10. The element is still too coupled with image widget because it expects the preview thumbnail to be passed in ... we should make that optional or just generate the preview thumbnail ourselves.
tanc’s picture

Nice work @bleen! Keep chipping away :)

bleen’s picture

StatusFileSize
new28.58 KB
new6.75 KB
  1. It doesn't work...
  2. The focal point value is saved, but not displayed on the form properly. This is because "50,50" is hard coded in the focalpoint image widget process function.
  3. There may (or may not) be a weird js issue where some bizarre errors show up ... needs more looking into
  4. By replacing the preview widget with the focal point element, the focal point value is referred to as "preview" in a lot of places. I think this should be fixed so that we remove the preview value and add the focal point value instead.
  5. The focal point value should ultimately work very similar to the "alt" value. It should travel with the image in the same way, but right now it doesn't.
  6. As is, this patch breaks the field-widget-based settings for "show preview link" and "default offsets"
  7. Focal point is showing up on the node/add form before an image is uploaded
  8. Double clicking on the focal point indicator shows the focal point field as it should (YAY!), but it breaks the form a bit (BOOO!)
  9. TESTS!
  10. The element is still too coupled with image widget because it expects the preview thumbnail to be passed in ... we should make that optional or just generate the preview thumbnail ourselves.
bleen’s picture

Status: Needs work » Needs review
StatusFileSize
new35.05 KB

Ok ... this is the first patch that I think *might* be ready. I did not add new TESTS since focal point really just needs a bunch of functional tests in general and that shouldn't hold this up any more than any other issue.

That said, this needs a lot of tire kicking. Please test it thoroughly....

kumkum29’s picture

Hello,

I reopen this post to know if the latest patch is included in the last version. Can we use Focal Point with the entity browser module?
Focal point module is very useful but actually not functionnal with entity browser.

Thanks.

chr.fritsch’s picture

StatusFileSize
new36 KB

Holy shit, this was a hell to rebase it. Hopefully, I did not destroy too much...

Coops_’s picture

StatusFileSize
new35.32 KB

Patch #17 wasn't applying to the latest dev branch so I've updated it. Would be good to get this merged soon as well.

mikelutz’s picture

StatusFileSize
new33.29 KB

Attempting a Re-roll of this, as I think I might find it useful.

Status: Needs review » Needs work

The last submitted patch, 19: 2657592-19.focal_point.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

swilmes’s picture

Can someone explain how one would use this patch to add a focal point image field to a form in code?

$form['image'] = [
  '#type' => 'focal_point',
  '#title' => $this->t('Focal Point Image'),
  '#description' => t("Image Field"),
]

This produces a title and description but no image field.

duaelfr’s picture

Version: 8.x-1.x-dev » 2.x-dev
Issue tags: +Needs reroll

I'll try to reroll that in a MR

duaelfr’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

hudri’s picture

When the field widget is converted into a standalone form element, this also completely changes the code needed to make this module potentially compatible with the SVG image module. Would love to see this merged soon, as this change is a blocker for issue 3122722

rajeshreeputra’s picture

can someone please review and mark as RTBC, I have tested this but need second eye/hand.

martijn de wit’s picture

Status: Needs review » Needs work

Tried to apply https://git.drupalcode.org/project/focal_point/-/merge_requests/7.diff with composer at a 2.X version. But it seems composer can't handle the diff as patch...

Applied the diff manual with a git checkout (2.x version). It did apply. I see the deletion of tests/src/Unit/FieldWidgets/FocalPointFieldWidgetTest.php but no replacing tests are added.

I think if the behaviour is changed, a new test is needed. check?

ankitv18 made their first commit to this issue’s fork.

ankitv18’s picture

Rebased with 2.x, re-rolled MR !7 and introduce DI in the service class.

ankitv18’s picture

Assigned: Unassigned » ankitv18

Need to work on fixing the test cases.

ankitv18’s picture

Assigned: ankitv18 » Unassigned
Status: Needs work » Needs review

MR! 7 is ready for a review

rajeshreeputra’s picture

Looks good to me, can we have another review on this.

martijn de wit’s picture

Status: Needs review » Needs work

Trying MR #7.

Using media library via file field at a content type seems to go well... But when i'm going to [site]/media/add/image

I get an error:

The website encountered an unexpected error. Please try again later.
AssertionError: Cannot load the "file" entity with NULL ID. in assert() (line 295 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
assert(, 'Cannot load the "file" entity with NULL ID.') (Line: 295)
Drupal\Core\Entity\EntityStorageBase->load(NULL) (Line: 158)
Drupal\focal_point\FocalPointManager->getFocalPoint(NULL) (Line: 157)
Drupal\focal_point\Plugin\Field\FieldWidget\FocalPointImageWidget::value(Array, , Object)
call_user_func_array(Array, Array) (Line: 1285)
Drupal\Core\Form\FormBuilder->handleInputElement('media_image_add_form', Array, Object) (Line: 1003)
Drupal\Core\Form\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 1073)
Drupal\Core\Form\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 1073)
Drupal\Core\Form\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 1073)
Drupal\Core\Form\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 577)
Drupal\Core\Form\FormBuilder->processForm('media_image_add_form', Array, Object) (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 707)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Beside that I still don't see a replacement for the deletion of tests/src/Unit/FieldWidgets/FocalPointFieldWidgetTest.php. Because there is still a widget right?

ankitv18’s picture

Assigned: Unassigned » ankitv18

Thanks for this quick review,
Will look into this!!

martijn de wit’s picture

@ankitv18 did you already had some time to tackle #33 ?

martijn de wit’s picture

Hiding patches because there is a recent Merge Request for this ticket.

martijn de wit’s picture

Still the problem for [site]/media/add/image is not resolved #33

martijn de wit’s picture

Assigned: ankitv18 » Unassigned

unassigning this, because there is no response (yet). and others already worked on it.

Tried to debug the latest version and get it working on [site]/media/add/image, but there is still a lot to do.