You are here

public function WebformOptionsCustom::getOptions in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_options_custom/src/Entity/WebformOptionsCustom.php \Drupal\webform_options_custom\Entity\WebformOptionsCustom::getOptions()

Get options (YAML) as an associative array.

Return value

array|bool Images as an associative array. Returns FALSE if options YAML is invalid.

Overrides WebformOptionsCustomInterface::getOptions

1 call to WebformOptionsCustom::getOptions()
WebformOptionsCustom::getElement in modules/webform_options_custom/src/Entity/WebformOptionsCustom.php
Get the custom options element.

File

modules/webform_options_custom/src/Entity/WebformOptionsCustom.php, line 232

Class

WebformOptionsCustom
Defines the webform options custom entity.

Namespace

Drupal\webform_options_custom\Entity

Code

public function getOptions() {
  if (!isset($this->optionsDecoded)) {
    try {
      $options = $this->options ? Yaml::decode($this->options) : [];

      // Since YAML supports simple values.
      $options = is_array($options) ? $options : [];
    } catch (\Exception $exception) {
      $link = $this
        ->toLink($this
        ->t('Edit'), 'edit-form')
        ->toString();
      \Drupal::logger('webform_options_custom')
        ->notice('%title custom options are not valid. @message', [
        '%title' => $this
          ->label(),
        '@message' => $exception
          ->getMessage(),
        'link' => $link,
      ]);
      $options = [];
    }
    $this->optionsDecoded = $options;
  }
  return $this->optionsDecoded;
}