getConfig example


  public function testModerationWithFieldConfigOverride() {
    $this->createContentType([
      'type' => 'test_type',
    ]);

    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow, 'node', 'test_type');

    $fields = $this->container->get('entity_field.manager')->getFieldDefinitions('node', 'test_type');
    $field_config = $fields['moderation_state']->getConfig('test_type');
    $field_config->setLabel('Field Override!');
    $field_config->save();

    $node = Node::create([
      'title' => 'Test node',
      'type' => 'test_type',
    ]);
    $node->save();
    $this->assertFalse($node->isPublished());
    $this->assertEquals('draft', $node->moderation_state->value);

    
/** * Updates the locale strings when a translated active configuration is saved. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */
  public function onConfigSave(ConfigCrudEvent $event) {
    // Only attempt to feed back configuration translation changes to locale if     // the update itself was not initiated by locale data changes.     if (!InstallerKernel::installationAttempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) {
      $config = $event->getConfig();
      $langcode = $config->get('langcode') ?: 'en';
      $this->updateLocaleStorage($config$langcode);
    }
  }

  /** * Updates the locale strings when a configuration override is saved/deleted. * * @param \Drupal\language\Config\LanguageConfigOverrideCrudEvent $event * The language configuration event. */
  
public function testGenerateAppConfigWithThemeAndScriptAndStylePaths(): void
    {
        $appPath = __DIR__ . '/_fixture/apps/theme/';
        $this->loadAppsFromDir($appPath);
        $projectDir = $this->getContainer()->getParameter('kernel.project_dir');

        if (mb_strpos($appPath$projectDir) === 0) {
            // make relative             $appPath = ltrim(mb_substr($appPathmb_strlen($projectDir)), '/');
        }

        $configs = $this->configGenerator->getConfig();

        static::assertArrayHasKey('SwagApp', $configs);

        $appConfig = $configs['SwagApp'];
        static::assertEquals(
            $appPath,
            $appConfig['basePath']
        );
        static::assertEquals(['Resources/views']$appConfig['views']);
        static::assertEquals('swag-app', $appConfig['technicalName']);
        static::assertArrayNotHasKey('administration', $appConfig);

        
$this->themeHandler = $theme_handler;
    $this->cacheTagsInvalidator = $cache_tags_invalidator;
  }

  /** * Invalidate cache tags when particular system config objects are saved. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The Event to process. */
  public function onSave(ConfigCrudEvent $event) {
    $config_name = $event->getConfig()->getName();
    // Changing the site settings may mean a different route is selected for the     // front page. Additionally a change to the site name or similar must     // invalidate the render cache since this could be used anywhere.     if ($config_name === 'system.site') {
      $this->cacheTagsInvalidator->invalidateTags(['route_match', 'rendered']);
    }

    // Theme configuration and global theme settings.     if (in_array($config_name['system.theme', 'system.theme.global'], TRUE)) {
      $this->cacheTagsInvalidator->invalidateTags(['rendered']);
    }

    
$container->registerExtension($ext = new EnvExtension());
        $container->prependExtensionConfig('env_extension', $expected = [
            'scalar_node' => '%env(NULLED)%',
            'scalar_node_not_empty' => '%env(FLOATISH)%',
            'int_node' => '%env(int:FOO)%',
            'float_node' => '%env(float:BAR)%',
            'string_node' => '%env(UNDEFINED)%',
        ]);

        $this->doProcess($container);

        $this->assertSame($expected$container->resolveEnvPlaceholders($ext->getConfig()));
    }

    public function testDefaultEnvIsValidatedInConfig()
    {
        $this->expectException(InvalidConfigurationException::class);
        $this->expectExceptionMessage('Invalid configuration for path "env_extension.string_node": "fail" is not a valid string');
        $container = new ContainerBuilder();
        $container->setParameter('env(STRING)', 'fail');
        $container->registerExtension($ext = new EnvExtension());
        $container->prependExtensionConfig('env_extension', $expected = [
            'string_node' => '%env(STRING)%',
        ]);


    public function testName(): void
    {
        $rule = new CustomerLoggedInRule();
        static::assertSame('customerLoggedIn', $rule->getName());
    }

    public function testGetConfig(): void
    {
        $rule = new CustomerLoggedInRule();
        $config = $rule->getConfig();
        static::assertEquals([
            'fields' => [
                [
                    'name' => 'isLoggedIn',
                    'type' => 'bool',
                    'config' => [],
                ],
            ],
            'operatorSet' => null,
        ]$config->getData());
    }

    
public function __construct(Enlight_Event_EventManager $eventManager)
    {
        $this->eventManager = $eventManager;
    }

    /** * {@inheritdoc} */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $this->eventManager->notify('Shopware_Form_BuildForm', [
            'reference' => $builder->getForm()->getConfig()->getType()->getBlockPrefix(),
            'builder' => $builder,
        ]);

        $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'triggerEvent']);
    }

    /** * Returns the name of the type being extended. * * @return string The name of the type being extended */
    
'fields' => [
                [
                    'name' => 'identifiers',
                    'type' => 'multi-entity-id-select',
                    'config' => [
                        'entity' => 'tag',
                    ],
                ],
            ],
        ];

        $data = $this->rule->getConfig()->getData();
        static::assertEquals($expectedConfiguration$data);
    }

    public function testConstraints(): void
    {
        $operators = [
            Rule::OPERATOR_EQ,
            Rule::OPERATOR_NEQ,
            Rule::OPERATOR_EMPTY,
        ];

        
/** * @internal */
class InputFieldTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);
        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());
        $config = $flowActions->getActions()->getActions()[0]->getConfig()->getConfig();
        static::assertCount(4, $config);

        $firstInputField = $config[0];

        static::assertEquals('textField', $firstInputField->getName());
        static::assertEquals('text', $firstInputField->getType());
        static::assertEquals([
            'en-GB' => 'To',
            'de-DE' => 'To DE',
        ]$firstInputField->getLabel());
        static::assertEquals([
            
$this->cacheTagsInvalidator = $cache_tags_invalidator;
    $this->entityTypeManager = $entity_type_manager;
  }

  /** * Updates entity type definitions and ensures routes are rebuilt when needed. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The ConfigCrudEvent to process. */
  public function onSave(ConfigCrudEvent $event) {
    $saved_config = $event->getConfig();
    if ($saved_config->getName() === 'media.settings' && $event->isChanged('standalone_url')) {
      $this->cacheTagsInvalidator->invalidateTags([
        // The configuration change triggers entity type definition changes,         // which in turn triggers routes to appear or disappear.         // @see media_entity_type_alter()         'entity_types',
        // The 'rendered' cache tag needs to be explicitly invalidated to ensure         // that all links to Media entities are re-rendered. Ideally, this would         // not be necessary; invalidating the 'entity_types' cache tag should be         // sufficient. But that cache tag would then need to be on nearly         // everything, resulting in excessive complexity. We prefer pragmatism.
use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(ColorType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please select a valid color.', $form->getConfig()->getOption('invalid_message'));
    }
}
use Symfony\Component\Form\FormInterface;

/** * Writes and reads values to/from an object or array using callback functions. * * @author Yonel Ceruto <yonelceruto@gmail.com> */
class CallbackAccessor implements DataAccessorInterface
{
    public function getValue(object|array $data, FormInterface $form): mixed
    {
        if (null === $getter = $form->getConfig()->getOption('getter')) {
            throw new AccessException('Unable to read from the given form data as no getter is defined.');
        }

        return ($getter)($data$form);
    }

    public function setValue(object|array &$data, mixed $value, FormInterface $form): void
    {
        if (null === $setter = $form->getConfig()->getOption('setter')) {
            throw new AccessException('Unable to write the given value as no setter is defined.');
        }

        (
new Type('string'),
            ],
            'amount' => [
                new NotBlank(),
                new Type('numeric'),
            ],
        ]$constraints);
    }

    public function testConfig(): void
    {
        $config = (new CartTotalPurchasePriceRule())->getConfig();
        $configData = $config->getData();

        static::assertArrayHasKey('operatorSet', $configData);
        static::assertEquals([
            'operators' => RuleConfig::OPERATOR_SET_NUMBER,
            'isMatchAny' => false,
        ]$configData['operatorSet']);

        static::assertArrayHasKey('fields', $configData);
        static::assertCount(2, $configData['fields']);
        static::assertEquals([
            [

        return $this->updateBy;
    }

    public function get(string $key): mixed
    {
        return $this->parameters[$key] ?? null;
    }

    public static function fromLog(ImportExportLogEntity $log): self
    {
        $config = $log->getConfig();

        return new Config(
            $config['mapping'] ?? [],
            $config['parameters'] ?? [],
            $config['updateBy'] ?? []
        );
    }
}
'identifiers' => [new NotBlank()new ArrayOfUuid()],
            'operator' => [new NotBlank()new Choice([
                Rule::OPERATOR_EQ,
                Rule::OPERATOR_NEQ,
            ])],
        ]$rule->getConstraints());
    }

    public function testGetConfig(): void
    {
        $rule = new PromotionLineItemRule(Rule::OPERATOR_EQ, ['foo', 'bar']);
        $config = $rule->getConfig();

        static::assertEquals([
            'operatorSet' => [
                'operators' => [
                    Rule::OPERATOR_EQ,
                    Rule::OPERATOR_NEQ,
                ],
                'isMatchAny' => true,
            ],
            'fields' => [
                [
                    
Home | Imprint | This part of the site doesn't use cookies.