You are here

protected function WebformSubmissionForm::getUploadedManagedFileIds in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::getUploadedManagedFileIds()

Get uploaded managed file ids.

Return value

array An array of uploaded file ids.

1 call to WebformSubmissionForm::getUploadedManagedFileIds()
WebformSubmissionForm::validateUploadedManagedFiles in src/WebformSubmissionForm.php
Validate uploaded managed file limits.

File

src/WebformSubmissionForm.php, line 2106

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

protected function getUploadedManagedFileIds() {
  $fids = [];
  $element_keys = $this
    ->getWebform()
    ->getElementsManagedFiles();
  foreach ($element_keys as $element_key) {
    $data = $this->entity
      ->getElementData($element_key);
    if (!$data) {
      continue;
    }
    $element = $this
      ->getWebform()
      ->getElement($element_key);
    $element_plugin = $this->elementManager
      ->getElementInstance($element);
    $multiple = $element_plugin
      ->hasMultipleValues($element);

    // Get fids from composite sub-elements.
    if ($element_plugin instanceof WebformCompositeBase) {
      $managed_file_keys = $element_plugin
        ->getManagedFiles($element);

      // Convert single composite value to array of multiple composite values.
      $data = !$multiple ? [
        $data,
      ] : $data;
      foreach ($data as $item) {
        foreach ($managed_file_keys as $manage_file_key) {
          if ($item[$manage_file_key]) {
            $fids[] = $item[$manage_file_key];
          }
        }
      }
    }
    else {
      $fids = array_merge($fids, (array) $data);
    }
  }
  return $fids;
}