0

I created a Custom Composite, but I have some display difficulties.

<?php

namespace Drupal\dvc_composite\Element;

use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\Element\WebformCompositeBase;

/**
 * Provides a 'dvc_composite'.
 *
 * Webform composites contain a group of sub-elements.
 *
 *
 * IMPORTANT:
 * Webform composite can not contain multiple value elements (i.e. checkboxes)
 * or composites (i.e. webform_address)
 *
 * @FormElement("dvc_composite")
 *
 * @see \Drupal\webform\Element\WebformCompositeBase
 * @see \Drupal\dvc_composite\Element\WebformExampleComposite
 * @see \Drupal\webform\Plugin\WebformElementBase
 */
class WebformExampleComposite extends WebformCompositeBase {

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    return parent::getInfo() + ['#theme' => 'dvc_composite'];
  }

  /**
   * {@inheritdoc}
   */
  public static function getCompositeElements(array $element) {
    $elements = [];
    $elements['piece'] = [
      '#type' => 'managed_file',
      '#title' => 'Fichier',
      '#max_filesize' => '5',
      '#file_extensions' => 'pdf',
      '#file_help' => 'help',
      '#wrapper_type'=> 'container',
    ];

    $elements['radio_etat_piece'] = [
      '#type' => 'radios',
      '#title' => t('Etat Pièce'),
      '#options' => 'etat_piece',
      '#wrapper_type'=> 'container',
    ];

    $elements['motif_rejet_piece'] = [
      '#type' => 'select',
      '#title' => t('Motif'),
      '#options' => 'motifs_pieces_non_conformes',
    ];

    return $elements;
  }
...
}

I would like to display formatTextItemValue items from my Custom Composite like this :

link_to_my_file.pdf

Etat Piece : Display Value

Motif: Display Value

I coded this, but I can't get the link to my file :

  protected function formatTextItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
    $value = $this->getValue($element, $webform_submission, $options);
    $lines = [];
    if (!empty($value['piece'])) {
        $lines['piece'] = $value['piece'];
    }
    if (!empty($value['radio_etat_piece'])) {
        $lines['radio_etat_piece'] = $value['radio_etat_piece'];
    }
    if (!empty($value['motif_rejet_piece'])) {
        $lines['motif_rejet_piece'] = $value['motif_rejet_piece'];
    }
    return $lines;
  }

can someone help me, please ?

2
  • Where are you trying to get the link?
    – RajeevK
    Aug 30, 2022 at 12:53
  • Hello, in the result tab of all webform submissions. Aug 30, 2022 at 12:59

0

Your Answer

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

Browse other questions tagged or ask your own question.