Commit 6a58a7ce authored by Wesley Sandra's avatar Wesley Sandra Committed by Wesley Sandra
Browse files

Issue #3314858 by weseze: Add support for automated_crop within image_widget_crop

parent 4f475a9f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ drimage.settings:
    imageapi_optimize_webp:
      type: text
      label: 'Support for webp through the imageapi_optimize_webp module'
    automated_crop:
      type: text
      label: 'Support for automated_crop module'
    fallback_style:
      type: text
      label: 'Fallback Image Style'
+10 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ function drimage_install() {
    ->set('downscale', 3840)
    ->set('multiplier', 1)
    ->set('imageapi_optimize_webp', FALSE)
    ->set('automated_crop', NULL)
    ->set('lazy_offset', 100)
    ->save();
}
@@ -41,3 +42,12 @@ function drimage_update_8007(&$sandbox) {
    ->set('imageapi_optimize_webp', FALSE)
    ->save();
}

/**
 * Set false as default value for "imageapi_optimize_webp".
 */
function drimage_update_8008(&$sandbox) {
  \Drupal::configFactory()->getEditable('drimage.settings')
    ->set('automated_crop', NULL)
    ->save();
}
+7 −0
Original line number Diff line number Diff line
@@ -215,6 +215,13 @@ class DrImageController extends ImageStyleDownloadController {
                'crop_type' => $iwc_id,
              ],
            ];

            // Add support for automated_crop module.
            $drimage_config = $this->config('drimage.settings');
            if (!empty($drimage_config->get('automated_crop'))) {
              $iwc_configuration['data']['automatic_crop_provider'] = $drimage_config->get('automated_crop');
            }

            $effect = \Drupal::service('plugin.manager.image.effect')->createInstance($iwc_configuration['id'], $iwc_configuration);
            $style->addImageEffect($effect->getConfiguration());
          }
+20 −0
Original line number Diff line number Diff line
@@ -155,6 +155,25 @@ class DrimageSettingsForm extends ConfigFormBase {
      '#disabled' => !$imageapi_optimize_webp_check,
    ];

    $automated_crop_check = FALSE;
    $automated_crop_providers = [];
    $module_handler = \Drupal::service('module_handler');
    if ($module_handler->moduleExists('image_widget_crop') && $module_handler->moduleExists('automated_crop')) {
      $automated_crop_check = TRUE;
      $event = new \Drupal\crop\Events\AutomaticCropProviders();
      \Drupal::service('event_dispatcher')->dispatch(\Drupal\crop\Events\Events::AUTOMATIC_CROP_PROVIDERS, $event);
      $automated_crop_providers = $event->getProviders();
    }
    $form['automated_crop'] = [
      '#type' => 'select',
      '#title' => $this->t('Enable automated_crop support'),
      '#options' => $automated_crop_providers,
      '#empty_option' => $this->t('- Select a Provider -'),
      '#default_value' => $this->config('drimage.settings')->get('automated_crop'),
      '#description' => $this->t('This options is only available if <a href="https://www.drupal.org/project/image_widget_crop">image_widget_crop</a> and <a href="https://www.drupal.org/project/automated_crop">automated_crop</a> are installed. You will need to delete all drimage styles using image_widget_crop after enabling this.'),
      '#disabled' => !$automated_crop_check,
    ];

    $form['lazy_offset'] = [
      '#type' => 'number',
      '#title' => $this->t('Lazyloader offeset'),
@@ -220,6 +239,7 @@ class DrimageSettingsForm extends ConfigFormBase {
      ->set('downscale', $form_state->getValue('downscale'))
      ->set('multiplier', $form_state->getValue('multiplier'))
      ->set('imageapi_optimize_webp', $form_state->getValue('imageapi_optimize_webp'))
      ->set('automated_crop', $form_state->getValue('automated_crop'))
      ->set('lazy_offset', $form_state->getValue('lazy_offset'))
      ->set('fallback_style', $form_state->getValue('fallback_style'))
      ->set('proxy_cache_maximum_age', $form_state->getValue('proxy_cache_maximum_age'))