You are here

public function LinkTargetFieldWidget::getSelectedOptions in Link target 8

Retrieve settings and convert to an array that includes on those selected.

return array The options to include.

2 calls to LinkTargetFieldWidget::getSelectedOptions()
LinkTargetFieldWidget::formElement in src/Plugin/Field/FieldWidget/LinkTargetFieldWidget.php
Returns the form for a single field widget.
LinkTargetFieldWidget::settingsSummary in src/Plugin/Field/FieldWidget/LinkTargetFieldWidget.php
Returns a short summary for the current widget settings.

File

src/Plugin/Field/FieldWidget/LinkTargetFieldWidget.php, line 125

Class

LinkTargetFieldWidget
Plugin implementation of the 'link_target_field_widget' widget.

Namespace

Drupal\link_target\Plugin\Field\FieldWidget

Code

public function getSelectedOptions($default_all = FALSE) {
  $defaults = $this
    ->getTargets();

  // If a subset of targets have been specified, use them.
  $targets_conf = $this
    ->getSetting('available_targets');
  if ($targets_conf) {
    $targets_available = [];
    foreach ($targets_conf as $key) {
      if (isset($defaults[$key])) {
        $targets_available[$key] = $defaults[$key];
      }
    }
  }
  if (empty($targets_available) && $default_all) {
    $targets_available = $defaults;
  }
  return $targets_available;
}