File tree Expand file tree Collapse file tree 5 files changed +19
-12
lines changed
src/Plugin/Field/FieldWidget Expand file tree Collapse file tree 5 files changed +19
-12
lines changed File renamed without changes.
Original file line number Diff line number Diff line change @@ -17,13 +17,13 @@ frontify_media_library:
17
17
- core/drupal
18
18
- core/drupalSettings
19
19
- frontify/frontify_finder
20
- frontify_media_form :
20
+ frontify_entity_form :
21
21
version : 1.x
22
22
js :
23
- js/frontify_media_form .js : { }
23
+ js/frontify_entity_form .js : { }
24
24
css :
25
25
component :
26
- css/frontify_media_form .css : { }
26
+ css/frontify_entity_form .css : { }
27
27
dependencies :
28
28
- core/drupal
29
29
- frontify/frontify_finder
Original file line number Diff line number Diff line change 6
6
( function ( ) {
7
7
Drupal . frontifyMediaForm = {
8
8
handleFinder ( el ) {
9
- console . log ( 'Frontify media form' ) ;
10
9
el . addEventListener ( 'click' , async element => {
11
10
element . currentTarget . disabled = true ;
12
11
// Handle unlimited fields.
31
30
domain : drupalSettings . Frontify . api_url ,
32
31
options : {
33
32
permanentDownloadUrls : true ,
34
- // @todo configure extensions based on the media bundle.
35
- // this should be done as a third party setting of the Media provider
36
- // and selected based on its type .
33
+ // @todo configure extensions based on the field, so no need
34
+ // to bind this to a specific media entity, and the field widget
35
+ // can be used independently .
37
36
filters : [
38
37
{
39
38
key : 'ext' ,
76
75
$fieldItem . querySelector ( 'textarea.frontify-asset-metadata' ) . value =
77
76
JSON . stringify ( assets [ 0 ] ) ;
78
77
79
- // Media name
80
- document . querySelector ( '#edit-name-wrapper input' ) . value = assets [ 0 ] . title ;
78
+ // Media specifics: set the Media name from the Frontify one.
79
+ if ( drupalSettings . Frontify . parent_entity_type_id === 'media' ) {
80
+ document . querySelector ( '#edit-name-wrapper input' ) . value = assets [ 0 ] . title ;
81
+ }
81
82
82
83
$field
83
84
. querySelector ( '.frontify-wrapper-finder-overlay' )
Original file line number Diff line number Diff line change 13
13
case 'media_library' :
14
14
Drupal . frontifyMediaLibrary . handleFinder ( el ) ;
15
15
break ;
16
- case 'media_form ' :
16
+ case 'entity_form ' :
17
17
Drupal . frontifyMediaForm . handleFinder ( el ) ;
18
18
break ;
19
19
default :
Original file line number Diff line number Diff line change 2
2
3
3
namespace Drupal \frontify \Plugin \Field \FieldWidget ;
4
4
5
+ use Drupal \Core \Entity \Plugin \DataType \EntityAdapter ;
5
6
use Drupal \Core \Field \Attribute \FieldWidget ;
6
7
use Drupal \Core \Field \FieldItemListInterface ;
7
8
use Drupal \Core \Form \FormStateInterface ;
@@ -92,6 +93,10 @@ public function formElement(
92
93
],
93
94
];
94
95
96
+
97
+ $ parent = $ items ->getParent ();
98
+ $ entityTypeId = $ parent instanceof EntityAdapter ? $ parent ->getEntity ()->getEntityTypeId () : '' ;
99
+
95
100
$ element ['open ' ] = [
96
101
'#type ' => 'button ' ,
97
102
'#value ' => $ this ->t ('Open Frontify ' ),
@@ -102,14 +107,15 @@ public function formElement(
102
107
'#attached ' => [
103
108
'library ' => [
104
109
'frontify/frontify_once ' ,
105
- 'frontify/frontify_media_form ' ,
110
+ 'frontify/frontify_entity_form ' ,
106
111
],
107
112
'drupalSettings ' => [
108
113
'Frontify ' => [
109
- 'context ' => 'media_form ' ,
114
+ 'context ' => 'entity_form ' ,
110
115
'api_url ' => $ config ->get ('frontify_api_url ' ),
111
116
'debug_mode ' => $ config ->get ('debug_mode ' ),
112
117
'preview_image_width ' => self ::PREVIEW_IMAGE_WIDTH ,
118
+ 'parent_entity_type_id ' => $ entityTypeId ,
113
119
],
114
120
],
115
121
],
You can’t perform that action at this time.
0 commit comments