diff --git a/focal_point.info.yml b/focal_point.info.yml index f2d7bdf..49e4d4c 100644 --- a/focal_point.info.yml +++ b/focal_point.info.yml @@ -6,4 +6,4 @@ package: Images version: VERSION dependencies: - image - - crop + - crop (>=8.x-1.0-alpha2) diff --git a/focal_point.install b/focal_point.install index 6551772..9a78111 100644 --- a/focal_point.install +++ b/focal_point.install @@ -6,10 +6,27 @@ */ /** + * Checks if required version of Crop API is installed. + * + * @return bool + * TRUE if dependency is met and FALSE if not. + */ +function _focal_point_check_crop_version() { + if (\Drupal::moduleHandler()->moduleExists('crop')) { + $info = system_get_info('module', 'crop'); + if (version_compare($info['version'], '8.x-1.0-alpha2') >= 0) { + return TRUE; + } + } + + return FALSE; +} + +/** * Implements hook_requirements(). */ function focal_point_requirements($phase) { - if ($phase == 'update' && !\Drupal::moduleHandler()->moduleExists('crop')) { + if ($phase == 'update' && !_focal_point_check_crop_version()) { return [ 'crop' => [ 'title' => t('Focal point'), @@ -28,7 +45,7 @@ function focal_point_requirements($phase) { * Install default config. */ function focal_point_update_8001() { - if (!\Drupal::moduleHandler()->moduleExists('crop')) { + if (!_focal_point_check_crop_version()) { throw new \Drupal\Core\Utility\UpdateException('Crop API (drupal.org/project/crop) module is now a dependency and needs to be installed before running updates.'); } @@ -80,7 +97,7 @@ function focal_point_update_8002(&$sandbox) { $sandbox['last_fid'] = $file->id(); } - $sandbox['#finished'] = $sandbox['num_processed'] / (float) $sandbox['total_items']; + $sandbox['#finished'] = $sandbox['total_items'] ? $sandbox['num_processed'] / $sandbox['total_items'] : 1; // Intentionally leaving legacy table. You never know... } diff --git a/src/Plugin/Field/Validation/Constrant/FocalPointConstraint.php b/src/Plugin/Field/Validation/Constrant/FocalPointConstraint.php new file mode 100644 index 0000000..e69de29