diff --git a/config/install/focal_point.preview.yml b/config/install/focal_point.preview.yml index e69de29..68f2342 100644 --- a/config/install/focal_point.preview.yml +++ b/config/install/focal_point.preview.yml @@ -0,0 +1 @@ +display_link: true diff --git a/config/install/focal_point.settings.yml b/config/install/focal_point.settings.yml index 947a6ce..d286e1e 100644 --- a/config/install/focal_point.settings.yml +++ b/config/install/focal_point.settings.yml @@ -1,3 +1,2 @@ crop_type: 'focal_point' default_value: '50,50' - diff --git a/focal_point.install b/focal_point.install index 5aa7713..def95f6 100644 --- a/focal_point.install +++ b/focal_point.install @@ -116,3 +116,11 @@ function focal_point_update_8002(&$sandbox) { // Intentionally leaving legacy table. You never know... } + +/** + * Install preview config. + */ +function focal_point_update_8003() { + \Drupal::service('config.installer') + ->installDefaultConfig('module', 'focal_point'); +} diff --git a/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php b/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php index 8956bac..412cc6b 100644 --- a/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php +++ b/src/Plugin/Field/FieldWidget/FocalPointImageWidget.php @@ -53,25 +53,32 @@ class FocalPointImageWidget extends ImageWidget { '#markup' => '', ); - $preview_focal_point_value = str_replace(',', 'x', $default_focal_point_value); - $preview_link = [ - '#type' => 'link', - '#title' => t('Preview'), - '#url' => new Url('focal_point.preview', ['fid' => $fid,'focal_point_value' => $preview_focal_point_value]), - '#attributes' => [ - 'class' => array('focal-point-preview-link'), - 'data-selector' => $element_selector, - 'data-field-name' => $element['#field_name'], - 'target' => '_blank' - ], - ]; - $preview = array( 'indicator' => $indicator, 'thumbnail' => $element['preview'], - 'preview_link' => $preview_link, ); + $display_preview_link = \Drupal::config('focal_point.preview')->get('display_link'); + if ($display_preview_link) { + $preview_focal_point_value = str_replace(',', 'x', $default_focal_point_value); + $preview_link = [ + '#type' => 'link', + '#title' => t('Preview'), + '#url' => new Url('focal_point.preview', [ + 'fid' => $fid, + 'focal_point_value' => $preview_focal_point_value + ]), + '#attributes' => [ + 'class' => array('focal-point-preview-link'), + 'data-selector' => $element_selector, + 'data-field-name' => $element['#field_name'], + 'target' => '_blank' + ], + ]; + + $preview['preview_link'] = $preview_link; + } + // Use the existing preview weight value so that the focal point indicator // and thumbnail appear in the correct order. $preview['#weight'] = isset($element['preview']['#weight']) ? $element['preview']['#weight'] : 0;