setValues example


    ];
    $this->assertSame($expected$form_state->getValues());
  }

  /** * @covers ::getValue * * @dataProvider providerGetValue */
  public function testGetValue($key$expected$default = NULL) {
    $form_state = (new FormStateValuesTraitStub())->setValues([
      'foo' => 'one',
      'bar' => [
        'baz' => 'two',
      ],
    ]);
    $this->assertSame($expected$form_state->getValue($key$default));
  }

  /** * Provides data to self::testGetValue(). * * @return array[] * Items are arrays of two items: * - The key for which to get the value (string) * - The expected value (mixed). * - The default value (mixed). */

  public function testEffectFormValidationErrors() {
    $form_builder = $this->container->get('form_builder');

    /** @var \Drupal\image\ImageStyleInterface $image_style */
    $image_style = ImageStyle::create(['name' => 'foo']);
    $effect_id = $image_style->addImageEffect(['id' => 'image_scale']);
    $image_style->save();

    $form = new ImageEffectEditForm();
    $form_state = (new FormState())->setValues([
      'data' => ['width' => '', 'height' => ''],
    ]);
    $form_builder->submitForm($form$form_state$image_style$effect_id);

    $errors = $form_state->getErrors();
    $this->assertCount(1, $errors);
    $error = reset($errors);
    $this->assertEquals('Width and height can not both be blank.', $error);
  }

}
$this->container->get('plugin.manager.field.formatter'),
      $this->container->get('entity_display.repository'),
      $this->container->get('entity_field.manager')
    );
    $form_object->setEntity($entity->reveal());

    $form = [
      '#fields' => array_keys($field_values),
      '#extra' => [],
    ];
    $form_state = new FormState();
    $form_state->setValues(['fields' => $field_values]);
    $form_state->setProcessInput();

    $form_object->buildEntity($form$form_state);
    $form_state->setSubmitted();

    // Flag one field for updating plugin settings.     $form_state->set('plugin_settings_update', 'field_plugin_settings_update');
    // During form submission, buildEntity() will be called twice. Simulate that     // here to prove copyFormValuesToEntity() is idempotent.     $form_object->buildEntity($form$form_state);
  }

}
$entity_id = 'test_config_entity_id';
    $values = ['id' => $entity_id];
    $entity = $this->getMockBuilder('\Drupal\Tests\Core\Config\Entity\Fixtures\ConfigEntityBaseWithPluginCollections')
      ->setConstructorArgs([$values, 'test_config_entity'])
      ->onlyMethods(['getPluginCollections'])
      ->getMock();
    $entity->expects($this->atLeastOnce())
      ->method('getPluginCollections')
      ->willReturn(['key_controlled_by_plugin_collection' => NULL]);
    $this->entityForm->setEntity($entity);

    $form_state = (new FormState())->setValues([
      'regular_key' => 'foo',
      'key_controlled_by_plugin_collection' => 'bar',
    ]);
    $result = $this->entityForm->buildEntity([]$form_state);

    $this->assertSame($entity_id$result->id());
    // The regular key should have a value, but the one controlled by a plugin     // collection should not have been set.     $this->assertSame('foo', $result->get('regular_key'));
    $this->assertNull($result->get('key_controlled_by_plugin_collection'));
  }

  
protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        if (!$value instanceof TaggedIteratorArgument) {
            return parent::processValue($value$isRoot);
        }

        $exclude = $value->getExclude();
        if ($value->excludeSelf()) {
            $exclude[] = $this->currentId;
        }

        $value->setValues($this->findAndSortTaggedServices($value$this->container, $exclude));

        return $value;
    }
}


    private function sortFirewallContextListeners(Definition $definition, ContainerBuilder $container): void
    {
        /** @var IteratorArgument $listenerIteratorArgument */
        $listenerIteratorArgument = $definition->getArgument(0);
        $prioritiesByServiceId = $this->getListenerPriorities($listenerIteratorArgument$container);

        $listeners = $listenerIteratorArgument->getValues();
        usort($listenersfn (Reference $a, Reference $b) => $prioritiesByServiceId[(string) $b] <=> $prioritiesByServiceId[(string) $a]);

        $listenerIteratorArgument->setValues(array_values($listeners));
    }

    private function getListenerPriorities(IteratorArgument $listeners, ContainerBuilder $container): array
    {
        $priorities = [];

        foreach ($listeners->getValues() as $reference) {
            $id = (string) $reference;
            $def = $container->getDefinition($id);

            // We must assume that the class value has been correctly filled, even if the service is created by a factory
$locator = $container->getDefinition('reverse_container')->getArgument(1);

        if ($locator instanceof Reference) {
            $locator = $container->getDefinition((string) $locator);
        }
        if ($locator instanceof Definition) {
            foreach ($services as $id => $ref) {
                $services[$id] = new ServiceClosureArgument($ref);
            }
            $locator->replaceArgument(0, $services);
        } else {
            $locator->setValues($services);
        }
    }
}
/** * Represents a collection of values to lazily iterate over. * * @author Titouan Galopin <galopintitouan@gmail.com> */
class IteratorArgument implements ArgumentInterface
{
    private array $values;

    public function __construct(array $values)
    {
        $this->setValues($values);
    }

    public function getValues(): array
    {
        return $this->values;
    }

    /** * @return void */
    public function setValues(array $values)
    {
public function bindValue($param$value$type = ParameterType::STRING): bool
    {
        $this->query->setValue($param$value$type);

        return parent::bindValue($param$value$type);
    }

    public function execute($params = null): ResultInterface
    {
        if (null !== $params) {
            $this->query->setValues($params);
        }

        // clone to prevent variables by reference to change         $this->debugDataHolder->addQuery($this->connectionName, $query = clone $this->query);

        $this->stopwatch?->start('doctrine', 'doctrine');
        $query->start();

        try {
            $result = parent::execute($params);
        } finally {
            
if (!$container->hasDefinition('test.private_services_locator')) {
            return;
        }

        $privateContainer = $container->getDefinition('test.private_services_locator');
        $definitions = $container->getDefinitions();
        $privateServices = $privateContainer->getArgument(0);
        $renamedIds = [];

        foreach ($privateServices as $id => $argument) {
            if (isset($definitions[$target = (string) $argument->getValues()[0]])) {
                $argument->setValues([new Reference($target)]);
                if ($id !== $target) {
                    $renamedIds[$id] = $target;
                }
                if ($inner = $definitions[$target]->getTag('container.decorator')[0]['inner'] ?? null) {
                    $renamedIds[$id] = $inner;
                }
            } else {
                unset($privateServices[$id]);
            }
        }

        


        // Additionally, self::doBuildForm() places the button value in         // $form_state->getValue(BUTTON_NAME). If it's still there, after         // validation handlers have run, copy it to $values, but do not override         // what may already be in $values.         $name = $triggering_element['#name'];
        if (!isset($values[$name]) && $form_state->getValue($name) === $button_value) {
          $values[$name] = $button_value;
        }
      }
      $form_state->setValues($values);
    }
  }

  /** * Finalizes validation. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param string $form_id * The unique string identifying the form. */
$this->beforeSaveElement($elementData);

        $values = Shopware()->Events()->filter(
            'Shopware_Controllers_Backend_Config_Before_Save_Config_Element',
            $values,
            [
                'subject' => $this,
                'element' => $element,
            ]
        );

        $element->setValues(new ArrayCollection($values));

        $modelManager->flush($element);

        Shopware()->Events()->notify('Shopware_Controllers_Backend_Config_After_Save_Config_Element', [
            'subject' => $this,
            'element' => $element,
        ]);
    }

    private function getFallbackLocaleId(int $currentLocaleId): int
    {
        
/** * @covers ::handleErrorsWithLimitedValidation * * @dataProvider providerTestHandleErrorsWithLimitedValidation */
  public function testHandleErrorsWithLimitedValidation($sections$triggering_element$values$expected) {
    $form_validator = new FormValidator(new RequestStack()$this->getStringTranslationStub()$this->csrfToken, $this->logger, $this->formErrorHandler);

    $triggering_element['#limit_validation_errors'] = $sections;
    $form = [];
    $form_state = (new FormState())
      ->setValues($values)
      ->setTriggeringElement($triggering_element);

    $form_validator->validateForm('test_form_id', $form$form_state);
    $this->assertSame($expected$form_state->getValues());
  }

  public function providerTestHandleErrorsWithLimitedValidation() {
    return [
      // Test with a non-existent section.       [
        [['test1']['test3']],
        [],
protected function processValue(mixed $value, bool $isRoot = false): mixed
    {
        if (!$value instanceof TaggedIteratorArgument) {
            return parent::processValue($value$isRoot);
        }

        $exclude = $value->getExclude();
        if ($value->excludeSelf()) {
            $exclude[] = $this->currentId;
        }

        $value->setValues($this->findAndSortTaggedServices($value$this->container, $exclude));

        return $value;
    }
}
$this->assertSame('media_test', $type->getSource()->createSourceField($type)->getName());
  }

  /** * Tests configuration form submit handler on the base media source plugin. */
  public function testSourceConfigurationSubmit() {
    /** @var \Drupal\media\MediaSourceManager $manager */
    $manager = $this->container->get('plugin.manager.media.source');
    $form = [];
    $form_state = new FormState();
    $form_state->setValues(['test_config_value' => 'Somewhere over the rainbow.']);

    /** @var \Drupal\media\MediaSourceInterface $source */
    $source = $manager->createInstance('test', []);
    $source->submitConfigurationForm($form$form_state);
    $expected = ['source_field' => 'field_media_test_1', 'test_config_value' => 'Somewhere over the rainbow.'];
    $this->assertSame($expected$source->getConfiguration(), 'Submitted values were saved correctly.');

    // Try to save a NULL value.     $form_state->setValue('test_config_value', NULL);
    $source->submitConfigurationForm($form$form_state);
    $expected['test_config_value'] = NULL;
    
Home | Imprint | This part of the site doesn't use cookies.