You are here

public function YamlFormSubmissionStorage::getCustomColumns in YAML Form 8

Get customized submission columns used to display custom table.

Parameters

\Drupal\yamlform\YamlFormInterface|null $yamlform: A form.

\Drupal\Core\Entity\EntityInterface|null $source_entity: A form submission source entity.

\Drupal\Core\Session\AccountInterface|null $account: A user account.

Return value

array|mixed An associative array of columns keyed by name.

Overrides YamlFormSubmissionStorageInterface::getCustomColumns

File

src/YamlFormSubmissionStorage.php, line 271

Class

YamlFormSubmissionStorage
Defines the form submission storage.

Namespace

Drupal\yamlform

Code

public function getCustomColumns(YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, $include_elements = TRUE) {

  // Get custom columns from the form's state.
  if ($source_entity) {
    $source_key = $source_entity
      ->getEntityTypeId() . '.' . $source_entity
      ->id();
    $custom_column_names = $yamlform
      ->getState("results.custom.columns.{$source_key}", []);

    // If the source entity does not have custom columns, then see if we
    // can use the main form as the default custom columns.
    if (empty($custom_column_names) && $yamlform
      ->getState("results.custom.default", FALSE)) {
      $custom_column_names = $yamlform
        ->getState('results.custom.columns', []);
    }
  }
  else {
    $custom_column_names = $yamlform
      ->getState('results.custom.columns', []);
  }
  if (empty($custom_column_names)) {
    return $this
      ->getDefaultColumns($yamlform, $source_entity, $account, $include_elements);
  }

  // Get custom column with labels.
  $columns = $this
    ->getColumns($yamlform, $source_entity, $account, $include_elements);
  $custom_columns = [];
  foreach ($custom_column_names as $column_name) {
    if (isset($columns[$column_name])) {
      $custom_columns[$column_name] = $columns[$column_name];
    }
  }
  return $custom_columns;
}