I'm using the Mulitvalue Field module (https://www.drupal.org/project/multivaluefield) and I created a form like this and it successfully sets the various emails into the configuration file, but when i try to get the default value it, gets an array back. how do i get the default value for this multivalue field to display it in the form?

$form['comment']['comment_admin_notify_mailto'] = array(
  '#type' => 'multivalue',
  '#title' => $this->t('Comments Topics And Post Approvers'),
  '#cardinality' => MultiValue::CARDINALITY_UNLIMITED,
  'comment_admin_notify_mailto' => [
    '#type' => 'textfield',
    '#title' => $this->t('Person to send notifications for Comments, Topics and Posts'),
    '#default_value' =>  vista_moderation_admin_notify_variable_get_site_email(),

this is the function code:

function vista_moderation_admin_notify_variable_get_site_email() {
  $moderation_config = \Drupal::config('vista_moderation_admin_notify.settings');
  $site_mail = $moderation_config->get('comment_admin_notify_mailto');
  if (empty($site_mail)) {
    $site_config = \Drupal::config('system.site');
    $site_mail = $site_config->get('mail');
  return $site_mail;

1 Answer 1


i found the answer in the comments of the module which is the documentation :

   * Sets the default value for the child elements.
   * @param array $elements
   *   The elements array.
   * @param array $value
   *   An array of values, keyed by the children element name.
  public static function setDefaultValue(array &$elements, array $value): void {
    // @todo Handle nested elements.
    foreach (Element::children($elements, FALSE) as $child) {
      if (isset($value[$child])) {
        $elements[$child]['#default_value'] = $value[$child];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.