Related issue opened on the Focal Point module:
https://www.drupal.org/project/focal_point/issues/3008727

I'm running into an issue when both the Focal Point and File (Field) Paths modules are enabled on an image field. In particular, it would appear that when I initially upload a file, set the focal point, and save the node, Focal Point isn't saving correct values.

However, if I open the Node, set the focal point, and re-save, things seem to work as expected. Disabling File (Field) Paths on the image field while keeping Focal Point also resolves the issue, which makes me curious if File (Field) Paths might be the culprit.

Specific info about my setup.

  • Drupal Version: 8.6.3
  • Focal Point Version: 8.x-1.0-beta6
  • File (Field) Paths Version: 8.x-1.0-beta1

I've also been able to replicate this on fresh installs of Drupal, so I don't think it's specific to my environment. If anyone else could replicate this, I would be very happy to know that I'm not going crazy off this though :)

A related issue I found long ago, but it looks like this was resolved and not entirely related maybe: https://www.drupal.org/project/filefield_paths/issues/2757285

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

Nuuou created an issue. See original summary.

nikitas’s picture

I had the same issue. I have solved this by checking the filefields_paths_entity_update hook and modifying it in my custom module like this:


use Drupal\media\MediaInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\filefield_paths\Utility\FieldItem;

/**
 * Implements hook_entity_update().
 */
function pixelthis_entity_update(EntityInterface $entity) {

  if (!$entity instanceof MediaInterface || $entity->bundle() !== 'image') {
    return;
  }

  // The filefield_paths module conflicts with the focal_point module.
  // If the filefield_paths module is enabled, we need to disable it
  // for the media.image.field_media_image field.
  // other wise the focal point will not work.
  // https://www.drupal.org/project/filefield_paths/issues/3015137
  $module_handler = \Drupal::moduleHandler();
  foreach ($entity->getFields() as $field) {
    if (FieldItem::hasConfigurationEnabled($field)) {
      $settings = FieldItem::getConfiguration($field);
      // Invoke hook_filefield_paths_process_file().
      $module_handler->invokeAll(
        'filefield_paths_process_file',
        [$entity, $field, $settings]
      );
    }
  }

}

voleger’s picture

Component: Code » Compatibility
justcaldwell’s picture

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

deciphered’s picture

Status: Active » Needs review

This one is on us, so it is fixed here rather than in Focal Point.

When a file is moved into its token based path, the field item still points at the pre-move file. Focal Point reads the field item immediately after us and saves its crop against a location that no longer exists, which is why the position is lost on the first save and correct on the second. Any module that reads a file path after us hits the same thing.

MR !75 points the field item at the moved file, with kernel tests covering it. There is no dependency on Focal Point or Crop.

Worth noting that https://www.drupal.org/i/3042259 is still Needs Review, so the patch people have been applying has not shipped. The two fixes are complementary and both are worth having.

Credit to Nuuou for the report and reproduction, tvhung for finding the cause in 2019, nikitas for the workaround, and justcaldwell for confirming it and opening the Focal Point MR.