addHiddenField('sectionId', $sections[0]->getId()); } else { $this->addField(new FieldOptions('sectionId', [ 'type' => 'radio', 'label' => __('section.section'), 'description' => __('author.submit.journalSectionDescription'), 'options' => $this->getSectionOptions($sections), 'value' => '', 'isRequired' => true, ]), [FIELD_POSITION_AFTER, 'title']); foreach ($sections as $section) { if (!trim(PKPString::html2text($section->getLocalizedPolicy()))) { continue; } $this->addField(new FieldHTML('sectionDescription' . $section->getId(), [ 'label' => $section->getLocalizedTitle(), 'description' => $section->getLocalizedPolicy(), 'showWhen' => ['sectionId', $section->getId()], ]), [FIELD_POSITION_AFTER, 'sectionId']); } } } /** * Convert sections to options prop for a FieldOption * * @param Section[] $sections */ protected function getSectionOptions(array $sections): array { $options = []; foreach ($sections as $section) { $options[] = [ 'value' => $section->getId(), 'label' => $section->getLocalizedTitle(), ]; } return $options; } }