You are here

protected function WebformEntityReferenceTrait::setOptions in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformEntityReferenceTrait.php \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::setOptions()

Get element options.

Parameters

array $element: An element.

array $settings: An array of settings used to limit and randomize options.

3 calls to WebformEntityReferenceTrait::setOptions()
WebformEntityReferenceTrait::formatHtmlItems in src/Plugin/WebformElement/WebformEntityReferenceTrait.php
WebformEntityReferenceTrait::formatTextItems in src/Plugin/WebformElement/WebformEntityReferenceTrait.php
WebformEntityReferenceTrait::getTestValues in src/Plugin/WebformElement/WebformEntityReferenceTrait.php
3 methods override WebformEntityReferenceTrait::setOptions()
WebformOptionsCustomEntity::setOptions in modules/webform_options_custom/src/Plugin/WebformElement/WebformOptionsCustomEntity.php
Get element options.
WebformTermCheckboxes::setOptions in src/Plugin/WebformElement/WebformTermCheckboxes.php
Get element options.
WebformTermSelect::setOptions in src/Plugin/WebformElement/WebformTermSelect.php
Get element options.

File

src/Plugin/WebformElement/WebformEntityReferenceTrait.php, line 384

Class

WebformEntityReferenceTrait
Provides an 'entity_reference' trait.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function setOptions(array &$element, array $settings = []) {

  // Add the webform submission to entity reference selection settings.
  if (!isset($settings['webform_submission']) && !empty($element['#webform_submission'])) {
    $settings['webform_submission'] = WebformSubmission::load($element['#webform_submission']);
  }

  // Replace tokens element just in case entity selection settings use tokens.
  if (isset($settings['webform_submission'])) {
    $this
      ->replaceTokens($element, $settings['webform_submission']);
  }
  WebformEntityTrait::setOptions($element, $settings);

  // Set options all after entity options are defined.
  if (!empty($element['#options_all'])) {
    $element['#options'][$element['#options_all_value']] = $element['#options_all_text'];
  }
}