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 \Drupal\crop\Entity\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 \Drupal\crop\Entity\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 \Drupal\crop\Entity\CropType $crop_type
50 * The entity CropType.
52 * Show notification after actions (default TRUE).
54 public function saveCrop(
55 array $crop_properties,
62 * Delete the crop when user delete it.
64 * @param string $file_uri
65 * Uri of image uploaded by user.
66 * @param \Drupal\crop\Entity\CropType $crop_type
67 * The CropType object.
69 * Id of image uploaded by user.
71 public function deleteCrop($file_uri, CropType $crop_type, $file_id);
74 * Get center of crop selection.
77 * Coordinates of x-axis & y-axis.
78 * @param array $crop_selection
79 * Coordinates of crop selection (width & height).
81 * @return arraystringinteger
82 * Coordinates (x-axis & y-axis) of crop selection zone.
84 public function getAxisCoordinates(array $axis, array $crop_selection);
87 * Get the size and position of the crop.
89 * @param array $field_values
90 * The original values of image.
91 * @param array $properties
92 * The original height of image.
95 * The data dimensions (width & height) into this ImageStyle or,
96 * empty array is the image isn't a valid file.
98 public function getCropOriginalDimension(array $field_values, array $properties);
101 * Get one effect instead of ImageStyle.
103 * @param \Drupal\image\Entity\ImageStyle $image_style
104 * The ImageStyle to get data.
105 * @param string $data_type
106 * The type of data needed in current ImageStyle.
109 * The effect data in current ImageStyle.
111 public function getEffectData(ImageStyle $image_style, $data_type);
114 * Get the imageStyle using this crop_type.
116 * @param string $crop_type_name
117 * The id of the current crop_type entity.
120 * All imageStyle used by this crop_type.
122 public function getImageStylesByCrop($crop_type_name);
125 * Apply different operation on ImageStyles.
127 * @param array $image_styles
128 * All ImageStyles used by this cropType.
129 * @param string $file_uri
130 * Uri of image uploaded by user.
131 * @param bool $create_derivative
132 * Boolean to create an derivative of the image uploaded.
134 public function imageStylesOperations(array $image_styles, $file_uri, $create_derivative = FALSE);
137 * Update existent crop entity properties.
139 * @param \Drupal\crop\Entity\Crop $crop
140 * The crop object loaded.
141 * @param array $crop_properties
142 * The machine name of ImageStyle.
144 public function updateCropProperties(Crop $crop, array $crop_properties);
147 * Load all crop using the ImageStyles.
149 * @param array $image_styles
150 * All ImageStyle for this current CROP.
151 * @param \Drupal\crop\Entity\CropType $crop_type
152 * The entity CropType.
153 * @param string $file_uri
154 * Uri of uploded file.
157 * All crop used this ImageStyle.
159 public function loadImageStyleByCrop(array $image_styles, CropType $crop_type, $file_uri);
162 * Compare crop zone properties when user saved one crop.
164 * @param array $crop_properties
165 * The crop properties after saved the form.
166 * @param array $old_crop
167 * The crop properties save in this crop entity,
168 * Only if this crop already exist.
171 * Return true if properties is not identical.
173 public function cropHasChanged(array $crop_properties, array $old_crop);
176 * Verify if the crop is used by a ImageStyle.
178 * @param string[] $crop_list
179 * The list of existent Crop Type.
181 * @return arrayinteger
182 * The list of Crop Type filtred.
184 public function getAvailableCropType(array $crop_list);
187 * Get All sizes properties of the crops for an file.
189 * @param \Drupal\crop\Entity\Crop $crop
190 * All crops attached to this file based on URI.
193 * Get all crop zone properties (x, y, height, width),
195 public static function getCropProperties(Crop $crop);
198 * Fetch all fields FileField and use "image_crop" element on an entity.
200 * @param \Drupal\Core\Entity\EntityInterface $entity
203 public function buildCropToEntity(EntityInterface $entity);
206 * Fetch all form elements using image_crop element.
208 * @param \Drupal\Core\Form\FormStateInterface $form_state
209 * The current state of the form.
211 public function buildCropToForm(FormStateInterface $form_state);