8
8
use Drupal \islandora \Plugin \Action \AbstractGenerateDerivativeMediaFile ;
9
9
10
10
/**
11
- * Emits a Node for generating fits derivatives event.
11
+ * Generates OCR derivatives event.
12
12
*
13
13
* @Action(
14
14
* id = "generate_extracted_text_file",
@@ -29,6 +29,7 @@ public function defaultConfiguration() {
29
29
$ config ['destination_media_type ' ] = 'file ' ;
30
30
$ config ['scheme ' ] = $ this ->config ->get ('default_scheme ' );
31
31
$ config ['destination_text_field_name ' ] = '' ;
32
+ $ config ['text_format ' ] = 'plain_text ' ;
32
33
return $ config ;
33
34
}
34
35
@@ -38,7 +39,7 @@ public function defaultConfiguration() {
38
39
public function buildConfigurationForm (array $ form , FormStateInterface $ form_state ) {
39
40
$ map = $ this ->entityFieldManager ->getFieldMapByFieldType ('text_long ' );
40
41
$ file_fields = $ map ['media ' ];
41
- $ field_options = array_combine (array_keys ($ file_fields ), array_keys ($ file_fields ));
42
+ $ field_options = [ ' none ' => $ this -> t ( ' None ' )] + array_combine (array_keys ($ file_fields ), array_keys ($ file_fields ));
42
43
$ form = parent ::buildConfigurationForm ($ form , $ form_state );
43
44
$ form ['mimetype ' ]['#description ' ] = $ this ->t ('Mimetype to convert to (e.g. application/xml, etc...) ' );
44
45
$ form ['mimetype ' ]['#value ' ] = 'text/plain ' ;
@@ -48,13 +49,23 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
48
49
$ last = array_slice ($ form , count ($ form ) - $ position + 1 );
49
50
50
51
$ middle ['destination_text_field_name ' ] = [
51
- '#required ' => TRUE ,
52
+ '#required ' => FALSE ,
52
53
'#type ' => 'select ' ,
53
54
'#options ' => $ field_options ,
54
55
'#title ' => $ this ->t ('Destination Text field Name ' ),
55
56
'#default_value ' => $ this ->configuration ['destination_text_field_name ' ],
56
57
'#description ' => $ this ->t ('Text field on Media Type to hold extracted text. ' ),
57
58
];
59
+ $ middle ['text_format ' ] = [
60
+ '#type ' => 'select ' ,
61
+ '#title ' => $ this ->t ('Format ' ),
62
+ '#options ' => [
63
+ 'plain_text ' => $ this ->t ('Plain text ' ),
64
+ 'hocr ' => $ this ->t ('hOCR text with positional data ' ),
65
+ ],
66
+ '#default_value ' => $ this ->configuration ['text_format ' ],
67
+ '#description ' => $ this ->t ("The type of text to be returned. " ),
68
+ ];
58
69
$ form = array_merge ($ first , $ middle , $ last );
59
70
60
71
unset($ form ['args ' ]);
@@ -81,17 +92,29 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
81
92
public function submitConfigurationForm (array &$ form , FormStateInterface $ form_state ) {
82
93
parent ::submitConfigurationForm ($ form , $ form_state );
83
94
$ this ->configuration ['destination_text_field_name ' ] = $ form_state ->getValue ('destination_text_field_name ' );
95
+ $ this ->configuration ['text_format ' ] = $ form_state ->getValue ('text_format ' );
96
+ switch ($ form_state ->getValue ('text_format ' )) {
97
+ case 'hocr ' :
98
+ $ this ->configuration ['args ' ] = '-c tessedit_create_hocr=1 -c hocr_font_info=0 ' ;
99
+ break ;
100
+
101
+ case 'plain_text ' :
102
+ $ his ->configuration ['args ' ] = '' ;
103
+ break ;
104
+ }
84
105
}
85
106
86
107
/**
87
108
* Override this to return arbitrary data as an array to be json encoded.
88
109
*/
89
110
protected function generateData (EntityInterface $ entity ) {
111
+
90
112
$ data = parent ::generateData ($ entity );
91
113
$ route_params = [
92
114
'media ' => $ entity ->id (),
93
115
'destination_field ' => $ this ->configuration ['destination_field_name ' ],
94
116
'destination_text_field ' => $ this ->configuration ['destination_text_field_name ' ],
117
+ 'text_format ' => $ this ->configuration ['text_format ' ],
95
118
];
96
119
$ data ['destination_uri ' ] = Url::fromRoute ('islandora_text_extraction.attach_file_to_media ' , $ route_params )
97
120
->setAbsolute ()
0 commit comments