Skip to content

Commit 8dacf46

Browse files
authored
Merge pull request #25 from lehors/relax-fields
Limit the number of required fields on model form to name and org
2 parents 4583ef8 + 28c60f3 commit 8dacf46

File tree

2 files changed

+28
-50
lines changed

2 files changed

+28
-50
lines changed

web/modules/mof/src/Entity/Model.php

+26-26
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,25 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
287287
->setDisplayConfigurable('form', TRUE)
288288
->setDisplayConfigurable('view', FALSE);
289289

290+
$fields['organization'] = BaseFieldDefinition::create('string')
291+
->setRevisionable(TRUE)
292+
->setTranslatable(TRUE)
293+
->setLabel(t('Organization'))
294+
->setDescription(t('The organization that developed the model.'))
295+
->setRequired(TRUE)
296+
->setSetting('max_length', 255)
297+
->setDisplayOptions('form', [
298+
'type' => 'string_textfield',
299+
'weight' => -95,
300+
])
301+
->setDisplayConfigurable('form', TRUE)
302+
->setDisplayOptions('view', [
303+
'label' => 'inline',
304+
'type' => 'string',
305+
'weight' => -95,
306+
])
307+
->setDisplayConfigurable('view', TRUE);
308+
290309
$fields['description'] = BaseFieldDefinition::create('string_long')
291310
->setRevisionable(TRUE)
292311
->setTranslatable(TRUE)
@@ -303,7 +322,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
303322
'weight' => -90,
304323
])
305324
->setDisplayConfigurable('view', TRUE)
306-
->setRequired(TRUE);
325+
->setRequired(FALSE);
307326

308327
$fields['version'] = BaseFieldDefinition::create('string')
309328
->setRevisionable(TRUE)
@@ -321,33 +340,14 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
321340
'weight' => -80,
322341
])
323342
->setDisplayConfigurable('view', TRUE)
324-
->setRequired(TRUE);
325-
326-
$fields['organization'] = BaseFieldDefinition::create('string')
327-
->setRevisionable(TRUE)
328-
->setTranslatable(TRUE)
329-
->setLabel(t('Organization'))
330-
->setDescription(t('The organization that developed the model.'))
331-
->setRequired(TRUE)
332-
->setSetting('max_length', 255)
333-
->setDisplayOptions('form', [
334-
'type' => 'string_textfield',
335-
'weight' => -75,
336-
])
337-
->setDisplayConfigurable('form', TRUE)
338-
->setDisplayOptions('view', [
339-
'label' => 'inline',
340-
'type' => 'string',
341-
'weight' => -75,
342-
])
343-
->setDisplayConfigurable('view', TRUE);
343+
->setRequired(FALSE);
344344

345345
$fields['type'] = BaseFieldDefinition::create('list_string')
346346
->setRevisionable(TRUE)
347347
->setTranslatable(TRUE)
348348
->setLabel(t('Type'))
349349
->setDescription(t('Type of model, generally its modality.'))
350-
->setRequired(TRUE)
350+
->setRequired(FALSE)
351351
->setSetting('allowed_values', [
352352
'language' => t('Language model'),
353353
'vision' => t('Vision model'),
@@ -376,7 +376,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
376376
->setTranslatable(TRUE)
377377
->setLabel(t('Architecture'))
378378
->setDescription(t('The model\'s architecture.'))
379-
->setRequired(TRUE)
379+
->setRequired(FALSE)
380380
->setSetting('allowed_values', [
381381
'transformer' => t('Transformer'),
382382
'transformer decoder' => t('Transformer (Decoder-only)'),
@@ -409,7 +409,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
409409
->setTranslatable(TRUE)
410410
->setLabel(t('Treatment'))
411411
->setDescription(t('The training treatment, includes pre-training, fine-tuning, RLHF or other training techniques.'))
412-
->setRequired(TRUE)
412+
->setRequired(FALSE)
413413
->setSetting('allowed_values', [
414414
'pre-trained' => t('Pre-trained'),
415415
'instruct fine-tuned' => t('Instruct fine-tuned'),
@@ -432,7 +432,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
432432
->setTranslatable(TRUE)
433433
->setLabel(t('Base model'))
434434
->setDescription(t('The pretrained version of the model which this model is based on, reference itself if this is the pre-trained model.'))
435-
->setRequired(TRUE)
435+
->setRequired(FALSE)
436436
->setSetting('max_length', 255)
437437
->setDisplayOptions('form', [
438438
'type' => 'string_textfield',
@@ -534,7 +534,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type): a
534534
->setRevisionable(TRUE)
535535
->setTranslatable(TRUE)
536536
->setDescription(t('Model status'))
537-
->setRequired(TRUE)
537+
->setRequired(FALSE)
538538
->setDefaultValue(static::STATUS_UNAPPROVED)
539539
->setSetting('allowed_values', [
540540
static::STATUS_UNAPPROVED => t('Unapproved'),

web/modules/mof/src/Form/ModelSubmitForm.php

+2-24
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function form(array $form, FormStateInterface $form_state): array {
4242

4343
$model_details = [
4444
'label',
45+
'organization',
4546
'description',
4647
'version',
47-
'organization',
4848
'type',
4949
'architecture',
5050
'treatment',
@@ -90,7 +90,7 @@ public function form(array $form, FormStateInterface $form_state): array {
9090

9191
// Open when ajax rebuilds the form.
9292
if ($form_state->isRebuilding()) {
93-
$form['details']['#open'] = TRUE;
93+
$form['details']['#open'] = FALSE;
9494
}
9595

9696
// Add fields to capture license and component paths.
@@ -111,11 +111,6 @@ public function form(array $form, FormStateInterface $form_state): array {
111111
'class' => ['license-path'],
112112
'autocomplete' => 'off',
113113
],
114-
'#states' => [
115-
'optional' => [
116-
':input[name="components['.$id.'][license]"]' => ['empty' => TRUE],
117-
],
118-
],
119114
],
120115
'component_path' => [
121116
'#type' => 'textfield',
@@ -130,11 +125,6 @@ public function form(array $form, FormStateInterface $form_state): array {
130125
'class' => ['component-path'],
131126
'autocomplete' => 'off',
132127
],
133-
'#states' => [
134-
'optional' => [
135-
':input[name="components['.$id.'][license]"]' => ['empty' => TRUE],
136-
],
137-
],
138128
],
139129
'#type' => 'container',
140130
'#attributes' => [
@@ -166,18 +156,6 @@ public function validateForm(array &$form, FormStateInterface $form_state): void
166156

167157
$extra = array_column($this->licenseHandler->getExtraOptions(), 'licenseId');
168158

169-
// Ensure a license and component path is entered.
170-
foreach ($form_state->getValue('components') as $cid => $component) {
171-
if ($component['license'] !== '' && !in_array($component['license'], $extra)) {
172-
if (!trim($component['license_path'])) {
173-
$form_state->setErrorByName("components][{$cid}][license_path", $this->t('License path is required.'));
174-
}
175-
if (!trim($component['component_path'])) {
176-
$form_state->setErrorByName("components][{$cid}][component_path", $this->t('Component path is required.'));
177-
}
178-
}
179-
}
180-
181159
// Re-populate git repo tree datalist.
182160
if (($repo_name = $form_state->getValue('github')) && !empty($repo_name)) {
183161

0 commit comments

Comments
 (0)