From 92e2d84f792cc7b32b6362a90a09f19c3d1f72d8 Mon Sep 17 00:00:00 2001 From: astanley Date: Mon, 2 Dec 2024 09:43:32 -0400 Subject: [PATCH] added form --- src/Form/AltmetricSettingForm.php | 105 ++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/Form/AltmetricSettingForm.php diff --git a/src/Form/AltmetricSettingForm.php b/src/Form/AltmetricSettingForm.php new file mode 100644 index 0000000..744f305 --- /dev/null +++ b/src/Form/AltmetricSettingForm.php @@ -0,0 +1,105 @@ +entityFieldManager = $entity_field_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity_field.manager') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId(): string { + return 'islandora_altmetric_altmetric_settings'; + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames(): array { + return ['islandora_altmetric.settings']; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state): array { + $fields = $this->entityFieldManager->getFieldDefinitions('node', 'islandora_object'); + $candidate_fields = []; + foreach ($fields as $field_name => $field_definition) { + if ($field_definition->getType() === 'string') { + if (str_starts_with($field_name, 'field')) { + $candidate_fields[$field_name] = $field_definition->getLabel(); + } + } + } + $form['doi_field'] = [ + '#type' => 'select', + '#title' => $this->t('DOI Field'), + '#options' => $candidate_fields, + '#description' => $this->t("Field from content model with DOI"), + '#default_value' => $this->config('islandora_altmetric.settings')->get('doi_field'), + ]; + $styles = [ + '4' => $this->t('Default'), + 'donut' => $this->t('Donut'), + 'medium-donut' => $this->t('Medium Donut'), + 'large-donut' => $this->t('Large Donut'), + + ]; + $form['style'] = [ + '#type' => 'select', + '#title' => $this->t('Badge Style'), + '#options' => $styles, + '#description' => $this->t("Display Style"), + '#default_value' => $this->config('islandora_altmetric.settings')->get('style'), + ]; + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state): void { + $this->config('islandora_altmetric.settings') + ->set('doi_field', $form_state->getValue('doi_field')) + ->set('style', $form_state->getValue('style')) + ->save(); + parent::submitForm($form, $form_state); + } + +}