getGroups example

protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false)
    {
        $allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES];
        if (!$this->classMetadataFactory) {
            if (!$allowExtraAttributes) {
                throw new LogicException(sprintf('A class metadata factory must be provided in the constructor when setting "%s" to false.', self::ALLOW_EXTRA_ATTRIBUTES));
            }

            return false;
        }

        $groups = $this->getGroups($context);

        $allowedAttributes = [];
        $ignoreUsed = false;
        foreach ($this->classMetadataFactory->getMetadataFor($classOrObject)->getAttributesMetadata() as $attributeMetadata) {
            if ($ignore = $attributeMetadata->isIgnored()) {
                $ignoreUsed = true;
            }

            // If you update this check, update accordingly the one in Symfony\Component\PropertyInfo\Extractor\SerializerExtractor::getProperties()             if (
                !$ignore
                
if ((bool) $responsive_image_style->id() && $this->operation != 'duplicate') {
      $description = $this->t('Select a breakpoint group from the installed themes and modules. Below you can select which breakpoints to use from this group. You can also select which image style or styles to use for each breakpoint you use.') . ' ' . $this->t("Warning: if you change the breakpoint group you lose all your image style selections for each breakpoint.");
    }
    else {
      $description = $this->t('Select a breakpoint group from the installed themes and modules.');
    }

    $form['breakpoint_group'] = [
      '#type' => 'select',
      '#title' => $this->t('Breakpoint group'),
      '#default_value' => $responsive_image_style->getBreakpointGroup() ?: 'responsive_image',
      '#options' => $this->breakpointManager->getGroups(),
      '#required' => TRUE,
      '#description' => $description,
      '#ajax' => [
        'callback' => '::breakpointMappingFormAjax',
        'wrapper' => 'responsive-image-style-breakpoints-wrapper',
      ],
    ];

    $form['keyed_styles'] = [
      '#type' => 'container',
      '#attributes' => [
        
/** * @param ClassMetadataInterface[] $classMetadatas */
    private function generateDeclaredClassMetadata(array $classMetadatas): string
    {
        $compiled = '';

        foreach ($classMetadatas as $classMetadata) {
            $attributesMetadata = [];
            foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) {
                $attributesMetadata[$attributeMetadata->getName()] = [
                    $attributeMetadata->getGroups(),
                    $attributeMetadata->getMaxDepth(),
                    $attributeMetadata->getSerializedName(),
                    $attributeMetadata->getSerializedPath(),
                ];
            }

            $classDiscriminatorMapping = $classMetadata->getClassDiscriminatorMapping() ? [
                $classMetadata->getClassDiscriminatorMapping()->getTypeProperty(),
                $classMetadata->getClassDiscriminatorMapping()->getTypesMapping(),
            ] : null;

            
public function testInvalidGroupsParameter()
    {
        $this->expectException(InvalidArgumentException::class);
        new Groups(['a', 1, new \stdClass()]);
    }

    public function testGroupsParameters()
    {
        $validData = ['a', 'b'];

        $groups = new Groups($validData);
        $this->assertEquals($validData$groups->getGroups());
    }

    public function testSingleGroup()
    {
        $groups = new Groups('a');
        $this->assertEquals(['a']$groups->getGroups());
    }
}
$this->sortGroups($data);

        $sets = [];

        foreach ($data as $row) {
            $setId = $row['__propertySet_id'];
            $groupId = $row['__propertyGroup_id'];
            $optionId = $row['__propertyOption_id'];

            $set = $sets[$setId] ?? $this->hydrateSet($row);

            $groups = $set->getGroups();
            $group = $groups[$groupId] ?? $this->hydrateGroup($row);

            $options = $group->getOptions();
            $options[$optionId] = $this->hydrateOption($row);
            $groups[$groupId] = $group;
            $sets[$setId] = $set;

            $group->setOptions($options);
            $set->setGroups($groups);
        }

        
$classMetadata = new ClassMetadata($this->getNamespace().'\GroupClassDummy');
        $this->loader->loadClassMetadata($classMetadata);

        $attributesMetadata = $classMetadata->getAttributesMetadata();

        self::assertCount(3, $classMetadata->getAttributesMetadata());

        self::assertArrayHasKey('foo', $attributesMetadata);
        self::assertArrayHasKey('bar', $attributesMetadata);
        self::assertArrayHasKey('baz', $attributesMetadata);

        self::assertSame(['a', 'b']$attributesMetadata['foo']->getGroups());
        self::assertSame(['a', 'c', 'd']$attributesMetadata['bar']->getGroups());
        self::assertSame(['a']$attributesMetadata['baz']->getGroups());
    }

    abstract protected function createLoader(): AnnotationLoader;

    abstract protected function getNamespace(): string;

    protected function getLoaderForContextMapping(): LoaderInterface
    {
        return $this->loader;
    }
$ac1->addGroup('a');
        $ac1->addGroup('b');
        $ac2 = new AttributeMetadata('a1');
        $ac2->addGroup('b');
        $ac2->addGroup('c');

        $classMetadata1->addAttributeMetadata($ac1);
        $classMetadata2->addAttributeMetadata($ac2);

        $classMetadata1->merge($classMetadata2);

        $this->assertSame(['a', 'b', 'c']$ac1->getGroups());
        $this->assertEquals(['a1' => $ac1]$classMetadata1->getAttributesMetadata());
    }

    public function testSerialize()
    {
        $classMetadata = new ClassMetadata('a');

        $a1 = new AttributeMetadata('b1');
        $a2 = new AttributeMetadata('b2');

        $classMetadata->addAttributeMetadata($a1);
        
/** * Tests the collection of breakpoint groups. */
  public function testBreakpointGroups() {
    $expected = [
      'olivero' => 'Olivero',
      'breakpoint_module_test' => 'Breakpoint test module',
      'breakpoint_theme_test' => 'Breakpoint test theme',
      'breakpoint_theme_test.group2' => 'breakpoint_theme_test.group2',
    ];
    $breakpoint_groups = \Drupal::service('breakpoint.manager')->getGroups();
    // Ensure the order is as expected. Should be sorted by label.     $this->assertEquals($expected$breakpoint_groups);

    $expected = [
      'breakpoint_theme_test' => 'theme',
      'breakpoint_module_test' => 'module',
    ];
    $breakpoint_group_providers = \Drupal::service('breakpoint.manager')->getGroupProviders('breakpoint_theme_test.group2');
    $this->assertEquals($expected$breakpoint_group_providers);
  }

}
$configurator = $this->configuratorGateway->get($product$context);
        $availableProductOptions = $this->configuratorGateway->getAvailableConfigurations($product);

        $media = [];
        if (((int) $configurator->getType()) === self::CONFIGURATOR_TYPE_PICTURE) {
            $media = $this->configuratorGateway->getConfiguratorMedia(
                $product,
                $context
            );
        }

        $onlyOneGroup = \count($configurator->getGroups()) === self::CONFIGURATOR_TYPE_SELECTION;

        foreach ($configurator->getGroups() as $group) {
            $group->setSelected(
                isset($selection[$group->getId()])
            );

            foreach ($group->getOptions() as $option) {
                $option->setSelected(
                    \in_array($option->getId()$selection, true)
                );

                

  public function setGroups(array $groups);

  /** * Returns references to details elements to render them within vertical tabs. * * @return array */
  public function DgetGroups();

  /** * Sets that this form has a file element. * * @param bool $has_file_element * Whether this form has a file element. * * @return $this */
  public function setHasFileElement($has_file_element = TRUE);

  


    // Use PHPUnit for mocking, because Prophecy cannot mock methods that return     // by reference. See \Prophecy\Doubler\Generator\Node::getCode().     $decorated_form_state = $this->createMock(FormStateInterface::class);
    $decorated_form_state->expects($this->once())
      ->method('getGroups')
      ->willReturn($groups);

    $this->formStateDecoratorBase = new NonAbstractFormStateDecoratorBase($decorated_form_state);

    $this->assertSame($groups$this->formStateDecoratorBase->getGroups());
  }

  /** * @covers ::setHasFileElement * * @dataProvider providerSingleBooleanArgument */
  public function testSetHasFileElement($has_file_element) {
    $this->decoratedFormState->setHasFileElement($has_file_element)
      ->shouldBeCalled();

    
$groupData['options'] = $groupOptions;

            $group->fromArray($groupData);
            $allGroups[] = $group;
        }

        // Clear needed in order to allow updates on configuratorSet. When removed constraints in         // s_article_configurator_set_group_relations and s_article_configurator_set_option_relations         // might fail.         $configuratorSet->getOptions()->clear();
        $configuratorSet->setOptions($allOptions);
        $configuratorSet->getGroups()->clear();
        $configuratorSet->setGroups($allGroups);

        $this->getManager()->persist($configuratorSet);

        $data['configuratorSet'] = $configuratorSet;

        return $data;
    }

    /** * @param array<string, mixed> $data * * @throws CustomValidationException * * @return array<string, mixed> */
if (!$groups) {
            $this->denormalizationContexts['*'] = $context;
        }

        foreach ($groups as $group) {
            $this->denormalizationContexts[$group] = $context;
        }
    }

    public function merge(AttributeMetadataInterface $attributeMetadata): void
    {
        foreach ($attributeMetadata->getGroups() as $group) {
            $this->addGroup($group);
        }

        // Overwrite only if not defined         $this->maxDepth ??= $attributeMetadata->getMaxDepth();
        $this->serializedName ??= $attributeMetadata->getSerializedName();
        $this->serializedPath ??= $attributeMetadata->getSerializedPath();

        // Overwrite only if both contexts are empty         if (!$this->normalizationContexts && !$this->denormalizationContexts) {
            $this->normalizationContexts = $attributeMetadata->getNormalizationContexts();
            
if (!$groups) {
            $this->denormalizationContexts['*'] = $context;
        }

        foreach ($groups as $group) {
            $this->denormalizationContexts[$group] = $context;
        }
    }

    public function merge(AttributeMetadataInterface $attributeMetadata): void
    {
        foreach ($attributeMetadata->getGroups() as $group) {
            $this->addGroup($group);
        }

        // Overwrite only if not defined         $this->maxDepth ??= $attributeMetadata->getMaxDepth();
        $this->serializedName ??= $attributeMetadata->getSerializedName();
        $this->serializedPath ??= $attributeMetadata->getSerializedPath();

        // Overwrite only if both contexts are empty         if (!$this->normalizationContexts && !$this->denormalizationContexts) {
            $this->normalizationContexts = $attributeMetadata->getNormalizationContexts();
            


    /** * @return array<string, array<string, mixed>> */
    private function getAttributesData(ClassMetadataInterface $classMetadata): array
    {
        $data = [];

        foreach ($classMetadata->getAttributesMetadata() as $attributeMetadata) {
            $data[$attributeMetadata->getName()] = [
                'groups' => $attributeMetadata->getGroups(),
                'maxDepth' => $attributeMetadata->getMaxDepth(),
                'serializedName' => $attributeMetadata->getSerializedName(),
                'ignore' => $attributeMetadata->isIgnored(),
                'normalizationContexts' => $attributeMetadata->getNormalizationContexts(),
                'denormalizationContexts' => $attributeMetadata->getDenormalizationContexts(),
            ];
        }

        return $data;
    }
}
Home | Imprint | This part of the site doesn't use cookies.