setData example

if ($overrider) {
      $config = $overrider->createConfigObject($name$collection);
    }
    else {
      $config = new Config($name$this->storageComparer->getTargetStorage($collection)$this->eventDispatcher, $this->typedConfigManager);
    }
    if ($op == 'delete') {
      $config->delete();
    }
    else {
      $data = $this->storageComparer->getSourceStorage($collection)->read($name);
      $config->setData($data ? $data : []);
      $config->save();
    }
    $this->setProcessedConfiguration($collection$op$name);
  }

  /** * Invokes import* methods on configuration entity storage. * * Allow modules to take over configuration change operations for higher-level * configuration data. * * @todo Add support for other extension types; e.g., themes etc. * * @param string $collection * The configuration collection. * @param string $op * The change operation to get the unprocessed list for, either delete, * create, rename, or update. * @param string $name * The name of the configuration to process. * * @return bool * TRUE if the configuration was imported as a configuration entity. FALSE * otherwise. * * @throws \Drupal\Core\Entity\EntityStorageException * Thrown if the data is owned by an entity type, but the entity storage * does not support imports. */
$all_config = array_merge($existing_config$list);
    $all_config = array_combine($all_config$all_config);
    $config_to_create = $storage->readMultiple($list);
    // Check to see if the corresponding override storage has any overrides or     // new configuration that can be installed.     if ($profile_storage) {
      $config_to_create = $profile_storage->readMultiple($list) + $config_to_create;
    }
    // Sort $config_to_create in the order of the least dependent first.     $dependency_manager = new ConfigDependencyManager();
    $dependency_manager->setData($config_to_create);
    $config_to_create = array_merge(array_flip($dependency_manager->sortAll())$config_to_create);
    if (!empty($dependency)) {
      // In order to work out dependencies we need the full config graph.       $dependency_manager->setData($this->getActiveStorages()->readMultiple($existing_config) + $config_to_create);
      $dependencies = $dependency_manager->getDependentEntities(key($dependency)reset($dependency));
    }

    foreach ($config_to_create as $config_name => $data) {
      // Remove configuration where its dependencies cannot be met.       $remove = !$this->validateDependencies($config_name$data$enabled_extensions$all_config);
      // Remove configuration that is not dependent on $dependency, if it is
// use binds if available else use QBSet value but with RawSql to avoid escape                 $set[$k] = isset($this->binds[$k]) ? $this->binds[$k][0] : new RawSql($value);
            }

            $this->binds = [];

            $this->resetRun([
                'QBSet'  => [],
                'QBKeys' => [],
            ]);

            $this->setData($set, true); // unescaped items are RawSql now         } elseif ($set !== null) {
            $this->setData($set$escape);
        } // else setData() has already been used and we need to do nothing
        return $this->batchExecute('_upsertBatch');
    }

    /** * Compiles batch upsert strings and runs the queries * * @param array|object|null $set a dataset * * @return false|int|string[] Number of affected rows or FALSE on failure, SQL array when testMode * * @throws DatabaseException */
$this->_adapter = $options['adapter'];
        } else {
            $this->_adapter = self::$_defaultAdapter;
        }
        if (isset($options['section'])) {
            $this->setSection($options['section']);
        }
        if (isset($options['extends'])) {
            $this->setExtends($options['extends']);
        }
        if (\is_array($config)) {
            $this->setData($config);
        } elseif ($config !== null) {
            $this->setName($config);
        } else {
            throw new Enlight_Config_Exception('Please specify configuration data');
        }
    }

    /** * Supports isset() overloading on PHP 5.1 * * @param string $name * * @return bool */

        $form->submit(null);

        $this->assertSame($emptyData$form->getViewData());
        $this->assertSame($expectedData$form->getNormData());
        $this->assertSame($expectedData$form->getData());
    }

    public function testDefaultFormattingWithDefaultRounding()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, ['scale' => 0]);
        $form->setData('12345.54321');

        $this->assertSame('12346', $form->createView()->vars['value']);
    }

    public function testDefaultFormattingWithSpecifiedRounding()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, ['scale' => 0, 'rounding_mode' => \NumberFormatter::ROUND_DOWN]);
        $form->setData('12345.54321');

        $this->assertSame('12345', $form->createView()->vars['value']);
    }

    
$lock = $this->createMock(LockInterface::class);
        $lock->method('acquire')->willReturn(true);
        $lockFactory->expects(static::once())->method('createLock')->willReturn($lock);

        $versionCommit = new VersionCommitEntity();
        $versionCommitData = new VersionCommitDataEntity();
        $versionCommitData->setAction('insert');
        $versionCommitData->setId(Uuid::randomHex());
        $versionCommitData->setEntityName('product');
        $versionCommitData->setEntityId([Uuid::randomHex()]);
        $versionCommit->setData(new VersionCommitDataCollection([$versionCommitData]));
        $versionCommit->setId(Uuid::randomHex());

        $entityReaderMock->expects(static::once())->method('read')->willReturn(new VersionCommitCollection([$versionCommit]));

        $writeContextMock = $this->createMock(WriteContext::class);

        $this->versionManager->merge(
            Uuid::randomHex(),
            $writeContextMock
        );
    }

    


    public function testMatchesNotWithWithWrongCountry(): void
    {
        $type = new TaxRuleTypeEntity();
        $type->setTechnicalName(ZipCodeRuleTypeFilter::TECHNICAL_NAME);

        $rule = new TaxRuleEntity();
        $rule->setActiveFrom(new \DateTime('2020-01-01'));
        $rule->setType($type);
        $rule->setCountryId('other-country-id');
        $rule->setData(['states' => ['state-id']]);

        $filter = new ZipCodeRuleTypeFilter();
        static::assertFalse($filter->match($rule, null, ShippingLocation::createFromAddress($this->getAddress())));
    }

    public function testMatchesNotWithWithWrongZipCode(): void
    {
        $type = new TaxRuleTypeEntity();
        $type->setTechnicalName(ZipCodeRuleTypeFilter::TECHNICAL_NAME);

        $rule = new TaxRuleEntity();
        
/** * @return void */
    public function mapDataToForms(mixed $choices, \Traversable $checkboxes)
    {
        if (!\is_array($choices ??= [])) {
            throw new UnexpectedTypeException($choices, 'array');
        }

        foreach ($checkboxes as $checkbox) {
            $value = $checkbox->getConfig()->getOption('value');
            $checkbox->setData(\in_array($value$choices, true));
        }
    }

    /** * @return void */
    public function mapFormsToData(\Traversable $checkboxes, mixed &$choices)
    {
        if (!\is_array($choices)) {
            throw new UnexpectedTypeException($choices, 'array');
        }

        
public function testPreSetDataDifferentTimezones()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'model_timezone' => 'UTC',
            'view_timezone' => 'Europe/Berlin',
            'input' => 'datetime',
            'with_seconds' => true,
            'reference_date' => new \DateTimeImmutable('2019-01-01', new \DateTimeZone('UTC')),
            'widget' => 'choice',
        ]);
        $form->setData(new \DateTime('2022-01-01 15:09:10', new \DateTimeZone('UTC')));

        $this->assertSame('15:09:10', $form->getData()->format('H:i:s'));
        $this->assertSame([
            'hour' => '16',
            'minute' => '9',
            'second' => '10',
        ]$form->getViewData());
    }

    public function testPreSetDataDifferentTimezonesDuringDaylightSavingTime()
    {
        
public function testHtml5EnablesSpecificFormatting()
    {
        \Locale::setDefault('de_CH');

        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'html5' => true,
            'rounding_mode' => \NumberFormatter::ROUND_UP,
            'scale' => 2,
            'type' => 'integer',
        ]);
        $form->setData('1234.56');

        $this->assertSame('1234.56', $form->createView()->vars['value']);
        $this->assertSame('number', $form->createView()->vars['type']);
    }

    public function testSubmitWithoutRoundingMode()
    {
        $form = $this->factory->create(self::TESTED_TYPE, null, [
            'scale' => 2,
        ]);

        
'type_class' => HiddenType::class,
            'synchronized' => true,
            'passed_options' => [],
            'resolved_options' => [],
        ]$this->dataExtractor->extractConfiguration($form));
    }

    public function testExtractDefaultData()
    {
        $form = $this->createBuilder('name')->getForm();

        $form->setData('Foobar');

        $this->assertSame([
            'default_data' => [
                'norm' => 'Foobar',
            ],
            'submitted_data' => [],
        ]$this->dataExtractor->extractDefaultData($form));
    }

    public function testExtractDefaultDataStoresModelDataIfDifferent()
    {
        
    // factory also ensures configuration entity dependency discovery has no     // dependencies on the config entity classes. Assume data with UUID is a     // config entity. Only configuration entities can be depended on so we can     // ignore everything else.     $data = array_map(function D$config) {
      $data = $config->get();
      if (isset($data['uuid'])) {
        return $data;
      }
      return FALSE;
    }$this->configFactory->loadMultiple($this->activeStorage->listAll()));
    $dependency_manager->setData(array_filter($data));
    return $dependency_manager;
  }

  /** * {@inheritdoc} */
  public function findConfigEntityDependencies($type, array $names, ConfigDependencyManager $dependency_manager = NULL) {
    if (!$dependency_manager) {
      $dependency_manager = $this->getConfigDependencyManager();
    }
    $dependencies = [];
    
$this->assertEquals([1 => new ChoiceView($entity1, '1', 'Foo'), 2 => new ChoiceView($entity2, '2', 'Bar')]$field->createView()->vars['choices']);
    }

    public function testSetDataSingleNull()
    {
        $field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
            'multiple' => false,
            'em' => 'default',
            'class' => self::SINGLE_IDENT_CLASS,
        ]);
        $field->setData(null);

        $this->assertNull($field->getData());
        $this->assertSame('', $field->getViewData());
    }

    public function testSetDataMultipleExpandedNull()
    {
        $field = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
            'multiple' => true,
            'expanded' => true,
            'em' => 'default',
            


  /** * {@inheritdoc} */
  public function processAttachments(AttachmentsInterface $response) {
    assert($response instanceof AjaxResponse, '\Drupal\Core\Ajax\AjaxResponse instance expected.');

    $request = $this->requestStack->getCurrentRequest();

    if ($response->getContent() == '{}') {
      $response->setData($this->buildAttachmentsCommands($response$request));
    }

    return $response;
  }

  /** * Prepares the AJAX commands to attach assets. * * @param \Drupal\Core\Ajax\AjaxResponse $response * The AJAX response to update. * @param \Symfony\Component\HttpFoundation\Request $request * The request object that the AJAX is responding to. * * @return array * An array of commands ready to be returned as JSON. */
static::assertIsArray($response->getData());
        static::assertEmpty($response->getData());

        static::assertNull($response->getContext());
    }

    public function testSetData(): void
    {
        $response = new StorefrontResponse();

        $response->setData([]);
        static::assertEmpty($response->getData());

        /** @deprecated tag:v6.6.0 - This can be removed if parameter `$data` will be strictly typed to `array` in `setData` */
        $this->expectExceptionMessageMatches('/deprecated functionality:/');
        $response->setData(null);
    }

    public function testSetContext(): void
    {
        $response = new StorefrontResponse();

        
Home | Imprint | This part of the site doesn't use cookies.