Attribute example

if (\in_array($group->getId()$filterGroupIds)) {
                        $tmpGroup = ['groupName' => $group->getName()];
                        $firstOption = $group->getOptions()[0];
                        if ($firstOption instanceof Option) {
                            $tmpGroup['optionName'] = $firstOption->getName();
                        }
                        $groups[] = $tmpGroup;
                    }
                }

                if (!empty($groups)) {
                    $product->addAttribute('swagVariantConfiguration', new Attribute(['value' => $groups]));
                }
            }
        }

        return $result;
    }
}
/** @var Address $billing */
        $billing = $billingForm->getData();

        $config = $this->container->get(Shopware_Components_Config::class);

        $accountMode = (int) $customer->getAccountMode();
        $doubleOptinWithAccount = ($accountMode === 0) && $config->get('optinregister');
        $doubleOptInAccountless = ($accountMode === 1) && $config->get('optinaccountless');

        $doubleOptinRegister = $doubleOptinWithAccount || $doubleOptInAccountless;
        $shop = $context->getShop();
        $shop->addAttribute('sendOptinMail', new Attribute([
            'sendOptinMail' => $doubleOptinRegister,
        ]));

        $customer->setReferer((string) $session->offsetGet('sReferer'));
        $customer->setValidation((string) ($data['register']['personal']['sValidation'] ?? ''));
        $customer->setAffiliate((int) $session->offsetGet('sPartner'));
        $customer->setPaymentId((int) $session->offsetGet('sPaymentID'));
        $customer->setDoubleOptinRegister($doubleOptinRegister);
        $customer->setDoubleOptinConfirmDate(null);

        /** @var Enlight_Event_EventManager $eventManager */
        
// if not has a constructor will inject values into public properties             if (false === $metadata['has_constructor']) {
                // collect all public properties                 foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                    $metadata['properties'][$property->name] = $property->name;

                    if (false === ($propertyComment = $property->getDocComment())) {
                        continue;
                    }

                    $attribute = new Attribute();

                    $attribute->required = str_contains($propertyComment, '@Required');
                    $attribute->name     = $property->name;
                    $attribute->type     = (str_contains($propertyComment, '@var') && preg_match('/@var\s+([^\s]+)/',$propertyComment$matches))
                        ? $matches[1]
                        : 'mixed';

                    $this->collectAttributeTypeMetadata($metadata$attribute);

                    // checks if the property has @Enum                     if (str_contains($propertyComment, '@Enum')) {
                        

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
        $products = [];

        foreach ($data as $row) {
            $product = new BaseProduct(
                (int) $row['__product_id'],
                (int) $row['__variant_id'],
                $row['__variant_ordernumber']
            );

            $product->addAttribute('search', new Attribute($row));
            $products[$product->getNumber()] = $product;
        }

        return $products;
    }

    /** * Calculated the total count of the whole search result. * * @param QueryBuilder $query * * @return int */

  }

  /** * Tests casting an Attribute object to a string. * * @see \Drupal\Core\Template\Attribute::__toString() * * @dataProvider providerTestAttributeData */
  public function testDrupalAttributes($attributes$expected$message) {
    $this->assertSame($expected(string) new Attribute($attributes)$message);
  }

  /** * Tests attribute iteration. */
  public function testAttributeIteration() {
    $attribute = new Attribute(['key1' => 'value1']);
    foreach ($attribute as $value) {
      $this->assertSame((string) $value, 'value1', 'Iterate over attribute.');
    }
  }

  
'#foo' => 'foo',
      '#bar' => 'bar',
      '#theme_wrappers' => ['container'],
      '#attributes' => ['class' => ['baz']],
    ];
    $setup_code_type_link = function D) {
      $this->themeManager->expects($this->exactly(2))
        ->method('render')
        ->with($this->logicalOr('common_test_foo', 'container'))
        ->willReturnCallback(function D$theme$vars) {
          if ($theme == 'container') {
            return '<div' . (string) (new Attribute($vars['#attributes'])) . '>' . $vars['#children'] . "</div>\n";
          }
          return $vars['#foo'] . $vars['#bar'];
        });
    };
    $data[] = [$build, '<div class="baz">foobar</div>' . "\n", $setup_code_type_link];

    // Tests that #theme_wrappers can disambiguate element attributes shared     // with rendering methods that build #children by using the alternate     // #theme_wrappers attribute override syntax.     $build = [
      '#type' => 'link',
      

    $block = $this->drupalPlaceBlock('views_block:test_view_block-block_1');
    $cached_block = $this->drupalPlaceBlock('views_block:test_view_block-block_1');
    $this->drupalGet('test-page');

    $id = 'block:block=' . $block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
    $id_token = Crypt::hmacBase64($id, Settings::getHashSalt() . $this->container->get('private_key')->get());
    $cached_id = 'block:block=' . $cached_block->id() . ':langcode=en|entity.view.edit_form:view=test_view_block:location=block&name=test_view_block&display_id=block_1&langcode=en';
    $cached_id_token = Crypt::hmacBase64($cached_id, Settings::getHashSalt() . $this->container->get('private_key')->get());
    // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:assertContextualLinkPlaceHolder()     // Check existence of the contextual link placeholders.     $this->assertSession()->responseContains('<div' . new Attribute(['data-contextual-id' => $id, 'data-contextual-token' => $id_token, 'data-drupal-ajax-container' => '']) . '></div>');
    $this->assertSession()->responseContains('<div' . new Attribute(['data-contextual-id' => $cached_id, 'data-contextual-token' => $cached_id_token, 'data-drupal-ajax-container' => '']) . '></div>');

    // Get server-rendered contextual links.     // @see \Drupal\contextual\Tests\ContextualDynamicContextTest:renderContextualLinks()     $post = ['ids[0]' => $id, 'ids[1]' => $cached_id, 'tokens[0]' => $id_token, 'tokens[1]' => $cached_id_token];
    $url = 'contextual/render?_format=json,destination=test-page';
    $this->getSession()->getDriver()->getClient()->request('POST', $url$post);
    $this->assertSession()->statusCodeEquals(200);
    $json = Json::decode($this->getSession()->getPage()->getContent());
    $this->assertSame('<ul class="contextual-links"><li><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '">Configure block</a></li><li><a href="' . base_path() . 'admin/structure/block/manage/' . $block->id() . '/delete">Remove block</a></li><li><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$id]);
    $this->assertSame('<ul class="contextual-links"><li><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '">Configure block</a></li><li><a href="' . base_path() . 'admin/structure/block/manage/' . $cached_block->id() . '/delete">Remove block</a></li><li><a href="' . base_path() . 'admin/structure/views/view/test_view_block/edit/block_1">Edit view</a></li></ul>', $json[$cached_id]);
  }

  public static function dataProviderValidatePropsValid(): array {
    return [
      [
        [
          'text' => 'Can Pica',
          'href' => 'https://www.drupal.org',
          'target' => '_blank',
          'attributes' => new Attribute(['key' => 'value']),
        ],
        'my-cta',
        static::loadComponentDefinitionFromFs('my-cta'),
      ],
      [[], 'my-banner', static::loadComponentDefinitionFromFs('my-banner')],
      [
        ['nonProp' => new \stdClass()],
        'my-banner',
        static::loadComponentDefinitionFromFs('my-banner'),
      ],
    ];
  }
$params = $this->prepareCustomerData($params$customer);
        $params = $this->prepareAssociatedData($params$customer);
        $customer->fromArray($params);

        $billing = $this->createAddress($params['billing']) ?? new AddressModel();
        $shipping = $this->createAddress($params['shipping'] ?? null);

        $registerService = $this->getContainer()->get(RegisterServiceInterface::class);
        $context = $this->getContainer()->get(ContextServiceInterface::class)->getShopContext()->getShop();

        $context->addAttribute('sendOptinMail', new Attribute([
            'sendOptinMail' => ($params['sendOptinMail'] ?? false) === true,
        ]));

        $registerService->register($context$customer$billing$shipping);

        return $customer;
    }

    /** * @param string $number * @param array<string, mixed> $params * * @throws ParameterMissingException * @throws CustomValidationException * @throws NotFoundException * * @return CustomerModel */

  public static function mergeCollections($a$b) {
    if (!($a instanceof Attribute || is_array($a)) || !($b instanceof Attribute || is_array($b))) {
      throw new \InvalidArgumentException('Invalid collection argument');
    }
    // If both collections are arrays, just merge them.     if (is_array($a) && is_array($b)) {
      return NestedArray::mergeDeep($a$b);
    }
    // If at least one collections is an Attribute object, merge through     // Attribute::merge.     $merge_a = $a instanceof Attribute ? $a : new Attribute($a);
    $merge_b = $b instanceof Attribute ? $b : new Attribute($b);
    $merge_a->merge($merge_b);
    return $a instanceof Attribute ? $merge_a : $merge_a->toArray();
  }

}

      '#sorted' => TRUE,
      '#menu_name' => 'mock',
      '#theme' => 'menu__mock',
      '#items' => [
        // To be filled when generating test cases, using $get_built_element().       ],
    ];

    $get_built_element = function DMenuLinkTreeElement $element) {
      $return = [
        'attributes' => new Attribute(),
        'title' => $element->link->getTitle(),
        'url' => new Url($element->link->getRouteName()$element->link->getRouteParameters()['set_active_class' => TRUE]),
        'below' => [],
        'original_link' => $element->link,
        'is_expanded' => FALSE,
        'is_collapsed' => FALSE,
        'in_active_trail' => FALSE,
      ];

      if ($element->hasChildren && !empty($element->subtree)) {
        $return['is_expanded'] = TRUE;
      }
$element['is_collapsed'] = TRUE;
      }
      // Set a helper variable to indicate whether the link is in the active       // trail.       $element['in_active_trail'] = FALSE;
      if ($data->inActiveTrail) {
        $element['in_active_trail'] = TRUE;
      }

      // Note: links are rendered in the menu.html.twig template; and they       // automatically bubble their associated cacheability metadata.       $element['attributes'] = new Attribute();
      $element['title'] = $link->getTitle();
      $element['url'] = $link->getUrlObject();
      $element['url']->setOption('set_active_class', TRUE);
      $element['below'] = $data->subtree ? $this->buildItems($data->subtree, $tree_access_cacheability$tree_link_cacheability) : [];
      if (isset($data->options)) {
        $element['url']->setOptions(NestedArray::mergeDeep($element['url']->getOptions()$data->options));
      }
      $element['original_link'] = $link;
      // Index using the link's unique ID.       $items[$link->getPluginId()] = $element;
    }

    
&& !$criteriaFacet instanceof HeightFacet
            ) {
                continue;
            }
            $facetResult = $this->createRangeFacet($criteriaFacet$stats$criteria);
            if ($facetResult === null) {
                continue;
            }

            $results[] = $facetResult;
        }
        $criteria->addAttribute('product_dimensions_handled', new Attribute());

        return $results;
    }

    public function supportsFacet(FacetInterface $facet)
    {
        return $facet instanceof WeightFacet
            || $facet instanceof WidthFacet
            || $facet instanceof LengthFacet
            || $facet instanceof HeightFacet
        ;
    }
/** * Creates an Attribute object. * * @param array $attributes * (optional) An associative array of key-value pairs to be converted to * HTML attributes. * * @return \Drupal\Core\Template\Attribute * An attributes object that has the given attributes. */
  public function createAttribute(array $attributes = []) {
    return new Attribute($attributes);
  }

  /** * Removes child elements from a copy of the original array. * * Creates a copy of the renderable array and removes child elements by key * specified through filter's arguments. The copy can be printed without these * elements. The original renderable array is still available and can be used * to print child elements in their entirety in the twig template. * * @param array|object $element * The parent renderable array to exclude the child items. * @param string[]|string ... * The string keys of $element to prevent printing. Arguments can include * string keys directly, or arrays of string keys to hide. * * @return array * The filtered renderable array. */
/** * Ensures the attributes are merged properly. */
  protected function checkAttributeMerging(): void {
    $content = ['label' => 'I am a labels'];
    // 1. Check that if it exists Attribute object in the 'attributes' prop, you     // get them merged.     $build = [
      '#type' => 'inline_template',
      '#context' => [
        'content' => $content,
        'attributes' => new Attribute(['data-merged-attributes' => 'yes']),
      ],
      '#template' => "{{ include('sdc_test:my-button', { text: content.label, iconType: 'external', attributes: attributes }, with_context = false) }}",
    ];
    $crawler = $this->renderComponentRenderArray($build);
    $this->assertNotEmpty($crawler->filter('#sdc-wrapper [data-merged-attributes="yes"][data-component-id="sdc_test:my-button"]')$crawler->outerHtml());
    // 2. Check that if the 'attributes' exists, but there is some other data     // type, then we don't touch it.     $build = [
      '#type' => 'inline_template',
      '#context' => [
        'content' => $content,
        
Home | Imprint | This part of the site doesn't use cookies.