You are here

public function YamlFormSubmissionStorage::getCustomSetting in YAML Form 8

Get customize setting.

Parameters

string $name: Custom settings name.

mixed $default: Custom settings default value.

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

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

Return value

mixed Custom setting.

Overrides YamlFormSubmissionStorageInterface::getCustomSetting

File

src/YamlFormSubmissionStorage.php, line 437

Class

YamlFormSubmissionStorage
Defines the form submission storage.

Namespace

Drupal\yamlform

Code

public function getCustomSetting($name, $default, YamlFormInterface $yamlform = NULL, EntityInterface $source_entity = NULL) {

  // Return the default value is form and source entity is not defined.
  if (!$yamlform && !$source_entity) {
    return $default;
  }
  $key = "results.custom.{$name}";
  if (!$source_entity) {
    return $yamlform
      ->getState($key, $default);
  }
  $source_key = $source_entity
    ->getEntityTypeId() . '.' . $source_entity
    ->id();
  if ($yamlform
    ->hasState("{$key}.{$source_key}")) {
    return $yamlform
      ->getState("{$key}.{$source_key}", $default);
  }
  if ($yamlform
    ->getState("results.custom.default", FALSE)) {
    return $yamlform
      ->getState($key, $default);
  }
  else {
    return $default;
  }
}