@@ -11,12 +11,47 @@ def value
11
11
data &.[]( 'content_item_id' )
12
12
end
13
13
14
+ def associated_content_item
15
+ ContentItem . find_by_id ( value )
16
+ end
17
+
18
+ def associated_primary_field
19
+ associated_content_item . content_type . fields . find_by_name ( field . metadata [ 'field_name' ] )
20
+ end
21
+
22
+ def associated_primary_field_type_class
23
+ associated_primary_field . field_type_instance . class
24
+ end
25
+
26
+ def associated_primary_field_item
27
+ associated_content_item . field_items . find_by_field_id associated_primary_field
28
+ end
29
+
30
+ def associated_content_item_title
31
+ # Gross hack, this should rely on 'primary title field' config feature in future, and should use a scope
32
+ title_field_item = associated_content_item . field_items . find do |field_item |
33
+ field_item . field . name == 'Title'
34
+ end
35
+
36
+ title_field_item . data [ 'text' ]
37
+ end
38
+
14
39
def render_label
15
- "Add #{ field . name } "
40
+ "Select #{ field . name } "
16
41
end
17
42
18
43
def render_content_item_id
19
- @options [ :form ] . hidden_field 'data[content_item_id]' , value : value
44
+ @options [ :form ] . hidden_field 'data[content_item_id]' , value : value , class : 'association_content_item_id'
45
+ end
46
+
47
+ def render_association_cell
48
+ cell ( Plugins ::Core ::AssetCell , associated_primary_field_item ,
49
+ associated_content_item : associated_content_item ,
50
+ associated_primary_field : associated_primary_field ,
51
+ associated_primary_field_type_class : associated_primary_field_type_class ,
52
+ associated_primary_field_item : associated_primary_field_item ,
53
+ associated_content_item_title : associated_content_item_title )
54
+ . ( :association )
20
55
end
21
56
end
22
57
end
0 commit comments