getSelectedOptions example

class OptionsSelectWidget extends OptionsWidgetBase {

  /** * {@inheritdoc} */
  public function formElement(FieldItemListInterface $items$delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items$delta$element$form$form_state);

    $element += [
      '#type' => 'select',
      '#options' => $this->getOptions($items->getEntity()),
      '#default_value' => $this->getSelectedOptions($items),
      // Do not display a 'multiple' select box if there is only one option.       '#multiple' => $this->multiple && count($this->options) > 1,
    ];

    return $element;
  }

  /** * {@inheritdoc} */
  protected function sanitizeLabel(&$label) {
    
$type = $this->getConfiguratorType($product->getId());

            /** * Check if a variant should be loaded. And load the configuration for the variant for pre selection. * * Requires the following scenario: * 1. $number has to be set (without a number we can't load a configuration) * 2. $number is equals to $productNumber (if the order number is invalid or inactive fallback to main variant) * 3. $configuration is empty (Customer hasn't not set an own configuration) */
            if ($providedNumber && $providedNumber == $productNumber && empty($selection) || $type === 0) {
                $selection = $product->getSelectedOptions();
            }
        }

        $categoryId = (int) $sCategoryID;
        if (empty($categoryId) || $categoryId == Shopware()->Shop()->getId()) {
            $categoryId = Shopware()->Modules()->Categories()->sGetCategoryIdByArticleId($id);
        }

        return $this->getLegacyProduct(
            $product,
            $categoryId,
            
$metaInformation->setMetaKeywords((string) $page->getProduct()->getTranslation('keywords'));

        if ((string) $page->getProduct()->getTranslation('metaTitle') !== '') {
            $metaInformation->setMetaTitle((string) $page->getProduct()->getTranslation('metaTitle'));

            return;
        }

        $metaTitleParts = [$page->getProduct()->getTranslation('name')];

        foreach ($page->getSelectedOptions() as $option) {
            $metaTitleParts[] = $option->getTranslation('name');
        }

        $metaTitleParts[] = $page->getProduct()->getProductNumber();

        $metaInformation->setMetaTitle(implode(' | ', $metaTitleParts));
    }

    /** * @@deprecated tag:v6.6.0 - will be removed because cms page id will always be set */
    

class OptionsButtonsWidget extends OptionsWidgetBase {

  /** * {@inheritdoc} */
  public function formElement(FieldItemListInterface $items$delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items$delta$element$form$form_state);

    $options = $this->getOptions($items->getEntity());
    $selected = $this->getSelectedOptions($items);

    // If required and there is one single option, preselect it.     if ($this->required && count($options) == 1) {
      reset($options);
      $selected = [key($options)];
    }

    if ($this->multiple) {
      $element += [
        '#type' => 'checkboxes',
        '#default_value' => $selected,
        
Home | Imprint | This part of the site doesn't use cookies.