3 namespace Drupal\image_widget_crop;
5 use Drupal\Core\Entity\EntityInterface;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\crop\Entity\Crop;
8 use Drupal\crop\Entity\CropType;
9 use Drupal\image\Entity\ImageStyle;
12 * Defines the interface for ImageWidgetCropManager calculation class service.
14 interface ImageWidgetCropInterface {
17 * Create new crop entity with user properties.
19 * @param array $properties
20 * All properties returned by the crop plugin (js),
21 * and the size of thumbnail image.
22 * @param array|mixed $field_value
23 * An array of values for the contained properties of image_crop widget.
24 * @param CropType $crop_type
25 * The entity CropType.
27 public function applyCrop(array $properties, $field_value, CropType $crop_type);
30 * Update old crop with new properties choose in UI.
32 * @param array $properties
33 * All properties returned by the crop plugin (js),
34 * and the size of thumbnail image.
35 * @param array|mixed $field_value
36 * An array of values contain properties of image_crop widget.
37 * @param CropType $crop_type
38 * The entity CropType.
40 public function updateCrop(array $properties, $field_value, CropType $crop_type);
43 * Save the crop when this crop not exist.
45 * @param double[] $crop_properties
46 * The properties of the crop applied to the original image (dimensions).
47 * @param array|mixed $field_value
48 * An array of values for the contained properties of image_crop widget.
49 * @param array $image_styles
50 * The list of imagesStyle available for this crop.
51 * @param CropType $crop_type
52 * The entity CropType.
54 * Show notification after actions (default TRUE).
56 public function saveCrop(
57 array $crop_properties,
65 * Delete the crop when user delete it.
67 * @param string $file_uri
68 * Uri of image uploaded by user.
69 * @param \Drupal\crop\Entity\CropType $crop_type
70 * The CropType object.
72 * Id of image uploaded by user.
74 public function deleteCrop($file_uri, CropType $crop_type, $file_id);
77 * Get center of crop selection.
80 * Coordinates of x-axis & y-axis.
81 * @param array $crop_selection
82 * Coordinates of crop selection (width & height).
84 * @return array<string,double>
85 * Coordinates (x-axis & y-axis) of crop selection zone.
87 public function getAxisCoordinates(array $axis, array $crop_selection);
90 * Get the size and position of the crop.
92 * @param array $field_values
93 * The original values of image.
94 * @param array $properties
95 * The original height of image.
98 * The data dimensions (width & height) into this ImageStyle.
100 public function getCropOriginalDimension(array $field_values, array $properties);
103 * Get one effect instead of ImageStyle.
105 * @param \Drupal\image\Entity\ImageStyle $image_style
106 * The ImageStyle to get data.
107 * @param string $data_type
108 * The type of data needed in current ImageStyle.
111 * The effect data in current ImageStyle.
113 public function getEffectData(ImageStyle $image_style, $data_type);
116 * Get the imageStyle using this crop_type.
118 * @param string $crop_type_name
119 * The id of the current crop_type entity.
122 * All imageStyle used by this crop_type.
124 public function getImageStylesByCrop($crop_type_name);
127 * Apply different operation on ImageStyles.
129 * @param array $image_styles
130 * All ImageStyles used by this cropType.
131 * @param string $file_uri
132 * Uri of image uploaded by user.
133 * @param bool $create_derivative
134 * Boolean to create an derivative of the image uploaded.
136 public function imageStylesOperations(array $image_styles, $file_uri, $create_derivative = FALSE);
139 * Update existent crop entity properties.
141 * @param \Drupal\crop\Entity\Crop $crop
142 * The crop object loaded.
143 * @param array $crop_properties
144 * The machine name of ImageStyle.
146 public function updateCropProperties(Crop $crop, array $crop_properties);
149 * Load all crop using the ImageStyles.
151 * @param array $image_styles
152 * All ImageStyle for this current CROP.
153 * @param CropType $crop_type
154 * The entity CropType.
155 * @param string $file_uri
156 * Uri of uploded file.
159 * All crop used this ImageStyle.
161 public function loadImageStyleByCrop(array $image_styles, CropType $crop_type, $file_uri);
164 * Compare crop zone properties when user saved one crop.
166 * @param array $crop_properties
167 * The crop properties after saved the form.
168 * @param array $old_crop
169 * The crop properties save in this crop entity,
170 * Only if this crop already exist.
173 * Return true if properties is not identical.
175 public function cropHasChanged(array $crop_properties, array $old_crop);
178 * Verify if ImageStyle is correctly configured.
180 * @param array $styles
181 * The list of available ImageStyle.
183 * @return array<integer>
184 * The list of styles filtred.
186 public function getAvailableCropImageStyle(array $styles);
189 * Verify if the crop is used by a ImageStyle.
191 * @param array $crop_list
192 * The list of existent Crop Type.
194 * @return array<integer>
195 * The list of Crop Type filtred.
197 public function getAvailableCropType(array $crop_list);
200 * Get All sizes properties of the crops for an file.
202 * @param \Drupal\crop\Entity\Crop $crop
203 * All crops attached to this file based on URI.
205 * @return array<array>
206 * Get all crop zone properties (x, y, height, width),
208 public static function getCropProperties(Crop $crop);
211 * Fetch all fields FileField and use "image_crop" element on an entity.
213 * @param \Drupal\Core\Entity\EntityInterface $entity
216 public function buildCropToEntity(EntityInterface $entity);
219 * Fetch all form elements using image_crop element.
221 * @param \Drupal\Core\Form\FormStateInterface $form_state
222 * The current state of the form.
224 public function buildCropToForm(FormStateInterface $form_state);