More tidying.
[yaffs-website] / web / modules / contrib / image_widget_crop / src / ImageWidgetCropInterface.php
1 <?php
2
3 namespace Drupal\image_widget_crop;
4
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;
10
11 /**
12  * Defines the interface for ImageWidgetCropManager calculation class service.
13  */
14 interface ImageWidgetCropInterface {
15
16   /**
17    * Create new crop entity with user properties.
18    *
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.
26    */
27   public function applyCrop(array $properties, $field_value, CropType $crop_type);
28
29   /**
30    * Update old crop with new properties choose in UI.
31    *
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.
39    */
40   public function updateCrop(array $properties, $field_value, CropType $crop_type);
41
42   /**
43    * Save the crop when this crop not exist.
44    *
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.
53    * @param bool $notify
54    *   Show notification after actions (default TRUE).
55    */
56   public function saveCrop(
57     array $crop_properties,
58     $field_value,
59     array $image_styles,
60     CropType $crop_type,
61     $notify = TRUE
62   );
63
64   /**
65    * Delete the crop when user delete it.
66    *
67    * @param string $file_uri
68    *   Uri of image uploaded by user.
69    * @param \Drupal\crop\Entity\CropType $crop_type
70    *   The CropType object.
71    * @param int $file_id
72    *   Id of image uploaded by user.
73    */
74   public function deleteCrop($file_uri, CropType $crop_type, $file_id);
75
76   /**
77    * Get center of crop selection.
78    *
79    * @param int[] $axis
80    *   Coordinates of x-axis & y-axis.
81    * @param array $crop_selection
82    *   Coordinates of crop selection (width & height).
83    *
84    * @return array<string,double>
85    *   Coordinates (x-axis & y-axis) of crop selection zone.
86    */
87   public function getAxisCoordinates(array $axis, array $crop_selection);
88
89   /**
90    * Get the size and position of the crop.
91    *
92    * @param array $field_values
93    *   The original values of image.
94    * @param array $properties
95    *   The original height of image.
96    *
97    * @return null|array
98    *   The data dimensions (width & height) into this ImageStyle.
99    */
100   public function getCropOriginalDimension(array $field_values, array $properties);
101
102   /**
103    * Get one effect instead of ImageStyle.
104    *
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.
109    *
110    * @return mixed|null
111    *   The effect data in current ImageStyle.
112    */
113   public function getEffectData(ImageStyle $image_style, $data_type);
114
115   /**
116    * Get the imageStyle using this crop_type.
117    *
118    * @param string $crop_type_name
119    *   The id of the current crop_type entity.
120    *
121    * @return array
122    *   All imageStyle used by this crop_type.
123    */
124   public function getImageStylesByCrop($crop_type_name);
125
126   /**
127    * Apply different operation on ImageStyles.
128    *
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.
135    */
136   public function imageStylesOperations(array $image_styles, $file_uri, $create_derivative = FALSE);
137
138   /**
139    * Update existent crop entity properties.
140    *
141    * @param \Drupal\crop\Entity\Crop $crop
142    *   The crop object loaded.
143    * @param array $crop_properties
144    *   The machine name of ImageStyle.
145    */
146   public function updateCropProperties(Crop $crop, array $crop_properties);
147
148   /**
149    * Load all crop using the ImageStyles.
150    *
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.
157    *
158    * @return array
159    *   All crop used this ImageStyle.
160    */
161   public function loadImageStyleByCrop(array $image_styles, CropType $crop_type, $file_uri);
162
163   /**
164    * Compare crop zone properties when user saved one crop.
165    *
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.
171    *
172    * @return bool
173    *   Return true if properties is not identical.
174    */
175   public function cropHasChanged(array $crop_properties, array $old_crop);
176
177   /**
178    * Verify if ImageStyle is correctly configured.
179    *
180    * @param array $styles
181    *   The list of available ImageStyle.
182    *
183    * @return array<integer>
184    *   The list of styles filtred.
185    */
186   public function getAvailableCropImageStyle(array $styles);
187
188   /**
189    * Verify if the crop is used by a ImageStyle.
190    *
191    * @param array $crop_list
192    *   The list of existent Crop Type.
193    *
194    * @return array<integer>
195    *   The list of Crop Type filtred.
196    */
197   public function getAvailableCropType(array $crop_list);
198
199   /**
200    * Get All sizes properties of the crops for an file.
201    *
202    * @param \Drupal\crop\Entity\Crop $crop
203    *   All crops attached to this file based on URI.
204    *
205    * @return array<array>
206    *   Get all crop zone properties (x, y, height, width),
207    */
208   public static function getCropProperties(Crop $crop);
209
210   /**
211    * Fetch all fields FileField and use "image_crop" element on an entity.
212    *
213    * @param \Drupal\Core\Entity\EntityInterface $entity
214    *   The entity object.
215    */
216   public function buildCropToEntity(EntityInterface $entity);
217
218   /**
219    * Fetch all form elements using image_crop element.
220    *
221    * @param \Drupal\Core\Form\FormStateInterface $form_state
222    *   The current state of the form.
223    */
224   public function buildCropToForm(FormStateInterface $form_state);
225
226 }