Including security review as a submodule - with patched for Yaffs.
[yaffs-website] / web / modules / contrib / image_widget_crop / README.md
1 # ImageWidgetCrop module
2
3 Provides an interface for using the features of the [Crop API]. This element provides an UX for using a crop on all fields images or file elements. This module has particularity to purpose capability to crop the same image by “Crop type” configured. It’s very useful for editorial sites or media management sites.
4
5 ## Table of contents
6 - [Requirements](#requirements)
7 - [Roadmap](#roadmap)
8 - [Known problems](#known-problems)
9 - [Try out the module](#try-out-the-module)
10 - [Installation](#installation)
11 - [Configuration](#configuration)
12 - [Options](#options)
13 - [Recommended modules](#recommended-modules)
14
15 ## Requirements
16 * Drupal Module [Crop API].
17 * Library [Cropper].
18
19 ## Roadmap
20 You can follow the evolution of this module [here](https://www.drupal.org/node/2832789).
21
22 ## Known problems
23 * Release 1.x
24 1. Not compatible with 'Boostrap theme', please switch on 2.x branch to have full support with all themes.
25 2. Support multiple crop variants per URI and crop type, more information [here](https://www.drupal.org/node/2617818).
26
27 * Release 2.x
28 1. Support multiple crop variants per URI and crop type, more information [here](https://www.drupal.org/node/2617818).
29
30 ## Try out the module
31 You can Test ImageWidgetCrop in action directly with the sub-module "ImageWidgetCrop example" to test different use cases of this module.
32 You have two choices to use example module :
33
34 ### Local files
35 1. Download and extract project.
36 2. Enable it (`drush en image_widget_crop_examples -y`) or (`admin/modules`) and enable modules.
37 3. Your site frontpage have changed to ImageWidgetCrop Examples welcome page and list all possible examples to try the modules.
38
39 ### simplytest.me (Online)
40 If you prefer to use SimplyTest.me service, you can test the module online in two versions.
41
42 1. Use one of links [1.x (Stable)] Or [2.x (Stable)].
43 2. Click on the button "Lauch sandbox" and follow common way to install Drupal 8.
44 3. Enable ImageWidgetCrop example module on Extend page (`admin/modules`) and enable module.
45 4. Enable it (`drush en image_widget_crop_examples -y`) or (`admin/modules`) and enable id.
46 5. Your site frontpage have changed to ImageWidgetCrop Examples welcome page and list all possible examples to try the modules.
47
48 [1.x (Stable)]: https://simplytest.me/project/image_widget_crop/8.x-1.5?add[]=media_entity&add[]=media_entity_image&add[]=file_entity&add[]=entity&add[]=token&add[]=inline_entity_form
49 [2.x (Stable)]: https://simplytest.me/project/image_widget_crop/8.x-2.x?add[]=media_entity&add[]=media_entity_image&add[]=file_entity&add[]=entity&add[]=token&add[]=inline_entity_form&add[]=imce&add[]=entity_browser&add[]=ctools
50
51 ## Installation
52 1. Download and extract the module to your (`sites/all/modules/contrib`) folder.
53 2. Enable the module on the Drupal Modules page (`admin/modules`) or using    $ drush en
54
55 The module is currently using Cropper as a library to display,  the cropping widget.
56 To properly configure it, do the following:
57
58 * Local library:
59 1. Download the latest version of [Cropper].
60 2. Copy the dist folder into:
61 - /libraries/cropper/dist
62 3. Enable the libraries module.
63
64 * External library:
65 1. Set the external URL for the minified version of the library and CSS file,      in Image Crop Widget settings (`/admin/config/media/crop-widget`), found at      https://cdnjs.com/libraries/cropper.
66
67 NOTE: The external library is set by default when you enable the module.
68
69 ## Configuration
70
71 ImageWidgetCrop can be used in different contexts.
72
73 ### FieldWidget:
74
75 * Create a Crop Type (`admin/structure/crop`)
76 * Create ImageStyles  
77 * add Manual crop effect, using your Crop Type,       (to apply your crop selection).
78 * Create an Image field.
79 * In its form display, at (`admin/structure/types/manage/page/form-display`):
80 * set the widget for your field to ImageWidgetCrop 
81 * at select your crop types in the Crop settings list. You can configure        the widget to create different crops on each crop types. For example, if        you have an editorial site, you need to display an image on different        places. With this option, you can set an optimal crop zone for each of the       image styles applied to the image.
82 * Set the display formatter Image and choose your image style,   or responsive image styles.
83 * Go add an image with your widget and crop your picture,   by crop types used for this image.
84
85 ### FileEntity:
86
87 * The (`image_crop`) element are already implemented to use,  an general configuration of module.
88 * In its ImageWidgetCrop general configuration,   at (`admin/config/media/crop-widget`):
89 * open (`GENERAL CONFIGURATION`) fieldset.
90 * at select your crop types in the Crop settings list. You can configure        the element to create different crops on each crop types. For example, if        you have an editorial site, you need to display an image on different        places. With this option, you can set an optimal crop zone for each of the       image styles applied to the image
91 * Verify your content using (`image`) field type configured,  with (`Editable file`) form widget.
92 * Add an File into content (`node/add/{your-content-type}`) upload your file,  click to (`Edit`) button and crop your picture,   by crop types used for this image.
93
94 ### Form API:
95
96 * Implement (`image_crop`) form element.
97 * Set all variables elements Or use general configuration of module.
98
99 #### Example of Form API implementation:
100
101 ##### Common element configuration of ImageWidgetCrop:
102 ```php
103 $crop_config = \Drupal::config('image_widget_crop.settings');
104 $form['image_crop'] = [
105   '#type' => 'image_crop',
106   '#file' => $file_object,
107   '#crop_type_list' => $crop_config->get('settings.crop_list'),
108   '#crop_preview_image_style' => $crop_config->get('settings.crop_preview_image_style'),
109   '#show_default_crop' => $crop_config->get('settings.show_default_crop'),
110   '#show_crop_area' => $crop_config->get('settings.show_crop_area'),
111   '#warn_mupltiple_usages' => $crop_config->get('settings.warn_mupltiple_usages'),
112 ];
113 ```
114 ##### Custom element configuration
115 ```php
116 $form['image_crop'] = [
117   '#type' => 'image_crop',
118   '#file' => $file_object,
119   '#crop_type_list' => ['crop_16_9', 'crop_free'],
120   '#crop_preview_image_style' => 'crop_thumbnail',
121   '#show_default_crop' => FALSE,
122   '#show_crop_area' => FALSE,
123   '#warn_mupltiple_usages' => FALSE,
124 ];
125 ```
126
127 ## Options
128 You may use ImageWidgetCrop configuration in few contexts and define different options to have desired features by context.
129 If you want to change the global default options you can change it at (`/admin/config/media/crop-widget`) and use configuration `\Drupal::config('image_widget_crop.settings')`.
130
131 ### crop_type_list
132
133 - Type: `Array`
134 - Default: `empty`
135
136 List of all CropTypes configured onto ImageStyle to use and define crop.
137
138 ### crop_preview_image_style
139
140 - Type: `String`
141 - Default: `crop_thumbnail`
142
143 Control the sizes of image to crop, you do conserve the aspect ratio of image (Only use Scale in `Width` OR `Height` not both).
144
145 ### show_default_crop
146
147 - Type: `Boolean`
148 - Default: `true`
149
150 Automatically initialize Crop Area on open `crop` element or file upload if `show_crop_area` option is enable.
151
152 ### show_crop_area
153
154 - Type: `Boolean`
155 - Default: `true`
156
157 Automatically open `image_crop` detail elements.
158
159 ### warn_mupltiple_usages
160
161 - Type: `Boolean`
162 - Default: `true`
163
164 Show a message to prevent users if current crop is used in other places and risk to affect in multiple places in same time.
165
166 ## Recommended modules
167 All of these modules are supported and tested with Image Widget Crop.
168
169 * [Crop API]: Provides basic API for images cropping.
170 * [IMCE]: Now supported by all versions of Image Widget Crop. We just have an option to enable of image_crop elements to use it.
171 * [File (Field) Paths]: We support this module and work with Image Widget Crop.
172 * [Bootstrap (theme)]: During lot of efforts to made compatibility with Boostrap all themes are compatible with Image Widget Crop Thank to @markcarver for his precious help.
173 * [Entity Browser]: Fully supported by this module.
174 * [File Entity (fieldable files)]: Fully compatible with this module.
175 * [Automated Crop]: Soon Image Widget Crop use this service to provide a powerful feature request (Automatic crop).
176
177 [Cropper]: https://github.com/fengyuanchen/cropper
178 [Crop API]: https://github.com/drupal-media/crop
179 [IMCE]: https://www.drupal.org/project/imce
180 [File (Field) Paths]: https://www.drupal.org/project/filefield_paths
181 [Bootstrap (theme)]: https://www.drupal.org/project/bootstrap
182 [Entity Browser]: https://www.drupal.org/project/entity_browser
183 [File Entity (fieldable files)]: https://www.drupal.org/project/file_entity
184 [Automated Crop]: https://www.drupal.org/project/automated_crop