diff --git a/scholartokens.module b/scholartokens.module index 261868c..930e1ef 100644 --- a/scholartokens.module +++ b/scholartokens.module @@ -47,6 +47,7 @@ function scholartokens_token_info() { * Implements hook_tokens(). */ function scholartokens_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) { + $config = \Drupal::config('scholartokens.settings'); $replacements = []; if ($type == 'scholartokens' && !empty($data['node'])) { if (!is_array($tokens) || empty($tokens)) { @@ -60,7 +61,7 @@ function scholartokens_tokens($type, $tokens, array $data, array $options, Bubbl switch ($name) { case 'scholar_author': $allowed = ['relators:aut', 'relators:cre']; - $replacement = scholartokens_get_term_with_rel_type($data['node'], 'field_linked_agent', $allowed, TRUE); + $replacement = scholartokens_get_term_with_rel_type($data['node'], $config->get('contributor_field'), $allowed, TRUE); $replacements[$original] = $replacement; break; diff --git a/src/Form/ScholarTokensSettingsForm.php b/src/Form/ScholarTokensSettingsForm.php index 02278c1..2293307 100644 --- a/src/Form/ScholarTokensSettingsForm.php +++ b/src/Form/ScholarTokensSettingsForm.php @@ -82,6 +82,11 @@ final class ScholarTokensSettingsForm extends ConfigFormBase { $range_fields[$field_name] = $field_definition->getLabel(); } } + foreach ($fields as $field_name => $field_definition) { + if ($field_definition->getType() === 'typed_relation') { + $typed_relation_fields[$field_name] = $field_definition->getLabel(); + } + } $form['field'] = [ '#type' => 'select', '#title' => $this->t('Choose date field to be tokenized'), @@ -95,6 +100,13 @@ final class ScholarTokensSettingsForm extends ConfigFormBase { '#options' => $range_fields, '#default_value' => $this->config('scholartokens.settings')->get('range_field'), ]; + + $form['contributor_field'] = [ + '#type' => 'select', + '#title' => $this->t('Choose contributor field to be tokenized'), + '#options' => $typed_relation_fields, + '#default_value' => $this->config('scholartokens.settings')->get('range_field'), + ]; return parent::buildForm($form, $form_state); } @@ -122,6 +134,7 @@ final class ScholarTokensSettingsForm extends ConfigFormBase { $this->config('scholartokens.settings') ->set('field', $form_state->getValue('field')) ->set('range_field', $form_state->getValue('range_field')) + ->set('contributor_field', $form_state->getValue('contributor_field')) ->save(); parent::submitForm($form, $form_state); }