getFilteredDescription example

// Collect widget elements.     $elements = [];

    // If the widget is handling multiple values (e.g Options), or if we are     // displaying an individual element, just get a single form element and make     // it the $delta value.     if ($this->handlesMultipleValues() || isset($get_delta)) {
      $delta = $get_delta ?? 0;
      $element = [
        '#title' => $this->fieldDefinition->getLabel(),
        '#description' => $this->getFilteredDescription(),
      ];
      $element = $this->formSingleElement($items$delta$element$form$form_state);

      if ($element) {
        if (isset($get_delta)) {
          // If we are processing a specific delta value for a field where the           // field module handles multiples, set the delta in the result.           $elements[$delta] = $element;
        }
        else {
          // For fields that handle their own processing, we cannot make
$max = count($items);
        $is_multiple = TRUE;
        break;

      default:
        $max = $cardinality - 1;
        $is_multiple = ($cardinality > 1);
        break;
    }

    $title = $this->fieldDefinition->getLabel();
    $description = $this->getFilteredDescription();

    $elements = [];

    $delta = 0;
    // Add an element for every existing item.     foreach ($items as $item) {
      $element = [
        '#title' => $title,
        '#description' => $description,
      ];
      $element = $this->formSingleElement($items$delta$element$form$form_state);

      
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
    $file_upload_help = [
      '#theme' => 'file_upload_help',
      '#description' => '',
      '#upload_validators' => $elements[0]['#upload_validators'],
      '#cardinality' => $cardinality,
    ];
    if ($cardinality == 1) {
      // If there's only one field, return it as delta 0.       if (empty($elements[0]['#default_value']['fids'])) {
        $file_upload_help['#description'] = $this->getFilteredDescription();
        $elements[0]['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
      }
    }
    else {
      $elements['#file_upload_description'] = $file_upload_help;
    }

    return $elements;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.