Skip to content

Commit 18724ff

Browse files
authored
feat: image widget insert from url should be optional (#5572)
1 parent 97353b6 commit 18724ff

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

packages/netlify-cms-widget-file/src/withFileControl.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export default function withFileControl({ forImage } = {}) {
291291
};
292292

293293
renderSelection = subject => {
294-
const { t } = this.props;
294+
const { t, field } = this.props;
295295
return (
296296
<div>
297297
{forImage ? this.renderImages() : null}
@@ -300,9 +300,11 @@ export default function withFileControl({ forImage } = {}) {
300300
<FileWidgetButton onClick={this.handleChange}>
301301
{t(`editor.editorWidgets.${subject}.chooseDifferent`)}
302302
</FileWidgetButton>
303-
<FileWidgetButton onClick={this.handleUrl(subject)}>
304-
{t(`editor.editorWidgets.${subject}.replaceUrl`)}
305-
</FileWidgetButton>
303+
{field.get('choose_url', true) ? (
304+
<FileWidgetButton onClick={this.handleUrl(subject)}>
305+
{t(`editor.editorWidgets.${subject}.replaceUrl`)}
306+
</FileWidgetButton>
307+
) : null}
306308
<FileWidgetButtonRemove onClick={this.handleRemove}>
307309
{t(`editor.editorWidgets.${subject}.remove`)}
308310
</FileWidgetButtonRemove>
@@ -312,15 +314,17 @@ export default function withFileControl({ forImage } = {}) {
312314
};
313315

314316
renderNoSelection = subject => {
315-
const { t } = this.props;
317+
const { t, field } = this.props;
316318
return (
317319
<>
318320
<FileWidgetButton onClick={this.handleChange}>
319321
{t(`editor.editorWidgets.${subject}.choose`)}
320322
</FileWidgetButton>
321-
<FileWidgetButton onClick={this.handleUrl(subject)}>
322-
{t(`editor.editorWidgets.${subject}.chooseUrl`)}
323-
</FileWidgetButton>
323+
{field.get('choose_url', true) ? (
324+
<FileWidgetButton onClick={this.handleUrl(subject)}>
325+
{t(`editor.editorWidgets.${subject}.chooseUrl`)}
326+
</FileWidgetButton>
327+
) : null}
324328
</>
325329
);
326330
};

website/content/docs/widgets/file.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The file widget allows editors to upload a file or select an existing one from t
1717
* `config`: a configuration object that will be passed directly to the media library being
1818
used - available options are determined by the library
1919
* `media_folder` (Beta): file path where uploaded files will be saved specific to this control. Paths can be relative to a collection folder (e.g. `files` will add the file to a sub-folder in the collection folder) or absolute with reference to the base of the repo which needs to begin with `/` (e.g `/static/files` will save uploaded files to the `static` folder in a sub folder named `files`)
20+
* `choose_url`: *(default: `true`)* when set to `false`, the "Insert from URL" button will be hidden
2021
* **Example:**
2122

2223
```yaml

website/content/docs/widgets/image.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ The image widget allows editors to upload an image or select an existing one fro
1414
current widget
1515
* `allow_multiple`: *(default: `true`)* when set to `false`, multiple selection will be disabled even if the media library extension supports it
1616
* `config`: a configuration object passed directly to the media library; check the documentation of your media library extension for available `config` options
17-
* `media_folder` (Beta): file path where uploaded images will be saved specific to this control. Paths can be relative to a collection folder (e.g. `images` will add the image to a sub-folder in the collection folder) or absolute with reference to the base of the repo which needs to begin with `/` (e.g `/static/images` will save uploaded images to the `static` folder in a sub folder named `images`)
17+
* `media_folder` (Beta): file path where uploaded images will be saved specific to this control. Paths can be relative to a collection folder (e.g. `images` will add the image to a sub-folder in the collection folder) or absolute with reference to the base of the repo which needs to begin with `/` (e.g `/static/images` will save uploaded images to the `static` folder in a sub folder named `images`)
18+
* `choose_url`: *(default: `true`)* when set to `false`, the "Insert from URL" button will be hidden
1819
* **Example:**
1920

2021
```yaml
2122
- label: "Featured Image"
2223
name: "thumbnail"
2324
widget: "image"
25+
choose_url: true
2426
default: "/uploads/chocolate-dogecoin.jpg"
2527
media_library:
2628
config:
2729
multiple: true
28-
```
30+
```

0 commit comments

Comments
 (0)