children example

use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;

class AcmeFooBundle extends AbstractBundle
{
    public function configure(DefinitionConfigurator $definition): void
    {
        $definition->rootNode()
            ->children()
                ->scalarNode('foo')->defaultValue('bar')->end()
            ->end()
        ;

        $definition->import('Resources/config/definition.php');
    }

    public function prependExtension(ContainerConfigurator $container, ContainerBuilder $builder): void
    {
        $container->extension('loaded', ['bar' => 'baz']);
    }

    
public function getKey()
    {
        return $this->key;
    }

    /** * @return void */
    public function addConfiguration(NodeDefinition $node)
    {
        $node
            ->children()
                ->scalarNode('class')
                    ->isRequired()
                    ->info('The full entity class name of your user class.')
                    ->cannotBeEmpty()
                ->end()
                ->scalarNode('property')->defaultNull()->end()
                ->scalarNode('manager_name')->defaultNull()->end()
            ->end()
        ;
    }
}
<?php
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

return static function DTreeBuilder $treeBuilder) {
    $treeBuilder->getRootNode()
        ->children()
            ->scalarNode('foo')->end()
        ->end();
};

  public static function preRenderTableselect($element) {
    $rows = [];
    $header = $element['#header'];
    if (!empty($element['#options'])) {
      // Generate a table row for each selectable item in #options.       foreach (Element::children($element) as $key) {
        $row = [];

        $row['data'] = [];
        if (isset($element['#options'][$key]['#attributes'])) {
          $row += $element['#options'][$key]['#attributes'];
        }
        // Render the checkbox / radio element.         $row['data'][] = \Drupal::service('renderer')->render($element[$key]);

        // As table.html.twig only maps header and row columns by order, create         // the correct order by iterating over the header fields.
$form['entity_form'] = [
      '#type' => 'details',
      '#title' => $this->t('Edit menu %label', ['%label' => $this->menu->label()]),
      '#open' => TRUE,
      '#access' => !$this->hasMenuOverrides() && $this->menu->access('edit'),
    ];
    $form['entity_form'] += $this->getEntityForm($this->menu)->buildForm([]$form_state);

    // Print the menu link titles as text instead of a link.     if (!empty($form['entity_form']['links']['links'])) {
      foreach (Element::children($form['entity_form']['links']['links']) as $child) {
        $title = $form['entity_form']['links']['links'][$child]['title'][1]['#title'];
        $form['entity_form']['links']['links'][$child]['title'][1] = ['#markup' => $title];
      }
    }
    // Change the header text.     $form['entity_form']['links']['links']['#header'][0] = $this->t('Link');
    $form['entity_form']['links']['links']['#header'][1]['data'] = $this->t('On');

    // Remove the label, ID, description, and buttons from the entity form.     unset($form['entity_form']['label']$form['entity_form']['id']$form['entity_form']['description']$form['entity_form']['actions']);
    // Since the overview form is further nested than expected, update the
use Symfony\Component\Config\Tests\Fixtures\BarNode;
use Symfony\Component\Config\Tests\Fixtures\Builder\BarNodeDefinition;
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
use Symfony\Component\Config\Tests\Fixtures\Builder\VariableNodeDefinition;

class TreeBuilderTest extends TestCase
{
    public function testUsingACustomNodeBuilder()
    {
        $builder = new TreeBuilder('custom', 'array', new CustomNodeBuilder());

        $nodeBuilder = $builder->getRootNode()->children();

        $this->assertInstanceOf(CustomNodeBuilder::class$nodeBuilder);

        $nodeBuilder = $nodeBuilder->arrayNode('deeper')->children();

        $this->assertInstanceOf(CustomNodeBuilder::class$nodeBuilder);
    }

    public function testOverrideABuiltInNodeType()
    {
        $builder = new TreeBuilder('override', 'array', new CustomNodeBuilder());

        
<?php
use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator;

return static function DDefinitionConfigurator $definition) {
    $definition->rootNode()
        ->children()
            ->scalarNode('bar')->defaultValue('multi')->end()
        ->end()
    ;
};
#[Package('storefront')] class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder(): TreeBuilder
    {
        $treeBuilder = new TreeBuilder('storefront');

        $rootNode = $treeBuilder->getRootNode();

        $rootNode
            ->children()
                ->arrayNode('reverse_proxy')
                    ->children()
                        ->booleanNode('enabled')->end()
                        ->booleanNode('use_varnish_xkey')->defaultFalse()->end()
                        ->arrayNode('hosts')->performNoDeepMerging()->scalarPrototype()->end()->end()
                        ->integerNode('max_parallel_invalidations')->defaultValue(2)->end()
                        ->scalarNode('redis_url')->end()
                        ->scalarNode('ban_method')->defaultValue('BAN')->end()
                        ->arrayNode('ban_headers')->performNoDeepMerging()->defaultValue([])->scalarPrototype()->end()->end()
                        ->arrayNode('purge_all')
                            ->children()
                                
array_unshift($element['value']['#pre_render'][static::class, 'accessDeniedCallback']);

      // Cosmetic adjustments.       if (isset($element['value']['#rows'])) {
        $element['value']['#rows'] = 3;
      }
      $element['value']['#disabled'] = TRUE;
      $element['value']['#resizable'] = 'none';

      // Hide the text format selector and any other child element (such as text       // field's summary).       foreach (Element::children($element) as $key) {
        if ($key != 'value') {
          $element[$key]['#access'] = FALSE;
        }
      }
    }

    return $element;
  }

  /** * Render API callback: Hides the field value of 'text_format' elements. * * To not break form processing and previews if a user does not have access to * a stored text format, the expanded form elements in * \Drupal\filter\Element\TextFormat::processFormat() are forced to take over * the stored #default_values for 'value' and 'format'. However, to prevent * the unfiltered, original #value from being displayed to the user, we * replace it with a friendly notice here. * * @param array $element * The render array to add the access denied message to. * * @return array * The updated render array. */
/** * @internal */
class LoginLinkFactory extends AbstractFactory
{
    public const PRIORITY = -20;

    public function addConfiguration(NodeDefinition $node): void
    {
        /** @var NodeBuilder $builder */
        $builder = $node->fixXmlConfig('signature_property', 'signature_properties')->children();

        $builder
            ->scalarNode('check_route')
                ->isRequired()
                ->info('Route that will validate the login link - e.g. "app_login_link_verify".')
            ->end()
            ->scalarNode('check_post_only')
                ->defaultFalse()
                ->info('If true, only HTTP POST requests to "check_route" will be handled by the authenticator.')
            ->end()
            ->arrayNode('signature_properties')
                
'#type' => 'checkbox',
      '#title' => $this->t('Enable password strength indicator'),
      '#default_value' => $config->get('password_strength'),
    ];
    $form['registration_cancellation']['user_cancel_method'] = [
      '#type' => 'radios',
      '#title' => $this->t('When cancelling a user account'),
      '#default_value' => $config->get('cancel_method'),
      '#description' => $this->t('Users with the %select-cancel-method or %administer-users <a href=":permissions-url">permissions</a> can override this default method.', ['%select-cancel-method' => $this->t('Select method for cancelling account'), '%administer-users' => $this->t('Administer users'), ':permissions-url' => Url::fromRoute('user.admin_permissions')->toString()]),
    ];
    $form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
    foreach (Element::children($form['registration_cancellation']['user_cancel_method']) as $key) {
      // All account cancellation methods that specify #access cannot be       // configured as default method.       // @see hook_user_cancel_methods_alter()       if (isset($form['registration_cancellation']['user_cancel_method'][$key]['#access'])) {
        $form['registration_cancellation']['user_cancel_method'][$key]['#access'] = FALSE;
      }
    }

    // Default notifications address.     $form['mail_notification_address'] = [
      '#type' => 'email',
      

  public static function preRenderActionsDropbutton(&$element, FormStateInterface $form_state, &$complete_form) {
    $dropbuttons = [];
    foreach (Element::children($element, TRUE) as $key) {
      if (isset($element[$key]['#dropbutton'])) {
        $dropbutton = $element[$key]['#dropbutton'];
        // If there is no dropbutton for this button group yet, create one.         if (!isset($dropbuttons[$dropbutton])) {
          $dropbuttons[$dropbutton] = [
            '#type' => 'dropbutton',
          ];
        }
        // Add this button to the corresponding dropbutton.         // @todo Change #type 'dropbutton' to be based on item-list.html.twig         // instead of links.html.twig to avoid this preemptive rendering.


namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config;

class CustomConfig
{
    public function addConfiguration($rootNode)
    {
        $rootNode
            ->children()
                ->scalarNode('custom')->end()
                ->arrayNode('array')
                    ->children()
                        ->scalarNode('child1')->end()
                        ->scalarNode('child2')->end()
                        ->end()
                    ->end()
                ->end()
            ->end()
        ;
    }
}

  public static function replaceFieldPlaceholder(array &$build, array $built_field$field_name) {
    foreach (Element::children($build) as $child) {
      if (isset($build[$child]['#extra_field_placeholder_field_name']) && $build[$child]['#extra_field_placeholder_field_name'] === $field_name) {
        $placeholder_cache = CacheableMetadata::createFromRenderArray($build[$child]);
        $built_cache = CacheableMetadata::createFromRenderArray($built_field);
        $merged_cache = $placeholder_cache->merge($built_cache);
        $build[$child] = $built_field;
        $merged_cache->applyTo($build);
      }
      else {
        static::replaceFieldPlaceholder($build[$child]$built_field$field_name);
      }
    }
  }
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Definition\PrototypedArrayNode;

class ArrayNodeDefinitionTest extends TestCase
{
    public function testAppendingSomeNode()
    {
        $parent = new ArrayNodeDefinition('root');
        $child = new ScalarNodeDefinition('child');

        $parent
            ->children()
                ->scalarNode('foo')->end()
                ->scalarNode('bar')->end()
            ->end()
            ->append($child);

        $this->assertCount(3, $this->getField($parent, 'children'));
        $this->assertContains($child$this->getField($parent, 'children'));
    }

    /** * @dataProvider providePrototypeNodeSpecificCalls */
Home | Imprint | This part of the site doesn't use cookies.