createForSubform example

$form['field_layouts']['settings_wrapper'] = [
      '#type' => 'container',
      '#id' => 'field-layout-settings-wrapper',
      '#tree' => TRUE,
    ];

    $form['field_layouts']['settings_wrapper']['icon'] = $layout_plugin->getPluginDefinition()->getIcon();

    if ($layout_plugin instanceof PluginFormInterface) {
      $form['field_layouts']['settings_wrapper']['layout_settings'] = [];
      $subform_state = SubformState::createForSubform($form['field_layouts']['settings_wrapper']['layout_settings']$form$form_state);
      $form['field_layouts']['settings_wrapper']['layout_settings'] = $layout_plugin->buildConfigurationForm($form['field_layouts']['settings_wrapper']['layout_settings']$subform_state);
    }

    return $form;
  }

  /** * Gets the layout plugin for the currently selected field layout. * * @param \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface $entity * The current form entity. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return \Drupal\Core\Layout\LayoutInterface * The layout plugin. */

  public function doBuildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, SectionComponent $component = NULL) {
    $this->sectionStorage = $section_storage;
    $this->delta = $delta;
    $this->uuid = $component->getUuid();
    $this->block = $component->getPlugin();

    $form_state->setTemporaryValue('gathered_contexts', $this->getPopulatedContexts($section_storage));

    $form['#tree'] = TRUE;
    $form['settings'] = [];
    $subform_state = SubformState::createForSubform($form['settings']$form$form_state);
    $form['settings'] = $this->getPluginForm($this->block)->buildConfigurationForm($form['settings']$subform_state);

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->submitLabel(),
      '#button_type' => 'primary',
    ];
    if ($this->isAjax()) {
      $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
      // @todo static::ajaxSubmit() requires data-drupal-selector to be the same       // between the various Ajax requests. A bug in

  protected function getSourceSubFormState(array $form, FormStateInterface $form_state) {
    return SubformState::createForSubform($form['source_dependent']['source_configuration']$form$form_state)
      ->set('operation', $this->operation)
      ->set('type', $this->entity);
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);

    if (isset($form['source_dependent']['source_configuration'])) {
      

  public function form(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;

    // Store the gathered contexts in the form state for other objects to use     // during form building.     $form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts());

    $form['#tree'] = TRUE;
    $form['settings'] = [];
    $subform_state = SubformState::createForSubform($form['settings']$form$form_state);
    $form['settings'] = $this->getPluginForm($entity->getPlugin())->buildConfigurationForm($form['settings']$subform_state);
    $form['visibility'] = $this->buildVisibilityInterface([]$form_state);

    // If creating a new block, calculate a safe default machine name.     $form['id'] = [
      '#type' => 'machine_name',
      '#maxlength' => 64,
      '#description' => $this->t('A unique name for this block instance. Must be alpha-numeric and underscore separated.'),
      '#default_value' => !$entity->isNew() ? $entity->id() : $this->getUniqueMachineName($entity),
      '#machine_name' => [
        'exists' => '\Drupal\block\Entity\Block::load',
        
'#machine_name' => [
        'exists' => [$this, 'exists'],
      ],
      '#disabled' => TRUE,
    ];

    // Add additional form fields from the workflow type plugin.     if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
      $form['type_settings'] = [
        '#tree' => TRUE,
      ];
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $subform_state->set('state', $state);
      $form['type_settings'] += $this->pluginFormFactory
        ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
        ->buildConfigurationForm($form['type_settings']$subform_state);
    }

    $header = [
      'label' => $this->t('Transition'),
      'state' => $this->t('To'),
      'operations' => $this->t('Operations'),
    ];
    
'#type' => 'radios',
      '#title' => $this->t('To'),
      '#required' => TRUE,
      '#options' => $states,
    ];

    // Add additional form fields from the workflow type plugin.     if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
      $form['type_settings'] = [
        '#tree' => TRUE,
      ];
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $form['type_settings'] += $this->pluginFormFactory
        ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
        ->buildConfigurationForm($form['type_settings']$subform_state);
    }

    return $form;
  }

  /** * Determines if the workflow transition already exists. * * @param string $transition_id * The workflow transition ID. * * @return bool * TRUE if the workflow transition exists, FALSE otherwise. */
'#required' => TRUE,
      '#default_value' => $transition->to()->id(),
      '#options' => $states,
      '#disabled' => TRUE,
    ];

    // Add additional form fields from the workflow type plugin.     if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
      $form['type_settings'] = [
        '#tree' => TRUE,
      ];
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $subform_state->set('transition', $transition);
      $form['type_settings'] += $this->pluginFormFactory
        ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
        ->buildConfigurationForm($form['type_settings']$subform_state);
    }

    return $form;
  }

  /** * {@inheritdoc} */

      ];
    }
    $form['transitions_container']['transition_add'] = [
      '#markup' => $workflow->toLink($this->t('Add a new transition'), 'add-transition-form')->toString(),
    ];

    if ($workflow_type->hasFormClass(WorkflowTypeInterface::PLUGIN_FORM_KEY)) {
      $form['type_settings'] = [
        '#tree' => TRUE,
      ];
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $form['type_settings'] += $this->pluginFormFactory
        ->createInstance($workflow_type, WorkflowTypeInterface::PLUGIN_FORM_KEY)
        ->buildConfigurationForm($form['type_settings']$subform_state);
    }

    return $form;
  }

  /** * {@inheritdoc} */
  
$form['id'] = [
      '#type' => 'machine_name',
      '#machine_name' => [
        'exists' => [$this, 'exists'],
      ],
    ];

    if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
      $form['type_settings'] = [
        '#tree' => TRUE,
      ];
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $form['type_settings'] += $this->pluginFormFactory
        ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
        ->buildConfigurationForm($form['type_settings']$subform_state);
    }

    return $form;
  }

  /** * Determines if the workflow state already exists. * * @param string $state_id * The workflow state ID. * * @return bool * TRUE if the workflow state exists, FALSE otherwise. */
$manager = new ConditionManager(\Drupal::service('container.namespaces'), \Drupal::cache('discovery'), \Drupal::moduleHandler());
    $this->condition = $manager->createInstance('entity_bundle:node');
    $this->conditionCurrentTheme = $manager->createInstance('current_theme');
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['#tree'] = TRUE;
    $form['entity_bundle'] = [];
    $subformState = SubformState::createForSubform($form['entity_bundle']$form$form_state);
    $form['entity_bundle'] = $this->condition->buildConfigurationForm($form['entity_bundle']$subformState);

    $form['current_theme'] = [];
    $subformState = SubformState::createForSubform($form['current_theme']$form$form_state);
    $form['current_theme'] = $this->conditionCurrentTheme->buildConfigurationForm($form['current_theme']$subformState);

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Submit'),
    ];
    return $form;
  }
$form['#attached']['library'][] = 'image/admin';
    $form['uuid'] = [
      '#type' => 'value',
      '#value' => $this->imageEffect->getUuid(),
    ];
    $form['id'] = [
      '#type' => 'value',
      '#value' => $this->imageEffect->getPluginId(),
    ];

    $form['data'] = [];
    $subform_state = SubformState::createForSubform($form['data']$form$form_state);
    $form['data'] = $this->imageEffect->buildConfigurationForm($form['data']$subform_state);
    $form['data']['#tree'] = TRUE;

    // Check the URL for a weight, then the image effect, otherwise use default.     $form['weight'] = [
      '#type' => 'hidden',
      '#value' => $request->query->has('weight') ? (int) $request->query->get('weight') : $this->imageEffect->getWeight(),
    ];

    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      

  public function testGetValues(array $parents$expected) {
    $parent_form_state = new FormState();
    $parent_form_state->setValues($this->formStateValues);

    $subform = NestedArray::getValue($this->parentForm, $parents);
    $subform_state = SubformState::createForSubform($subform$this->parentForm, $parent_form_state);
    $subform_state_values = &$subform_state->getValues();
    $this->assertSame($expected$subform_state_values);

    // Modify the retrieved values and confirm they are modified by reference in     // the parent form state.     $subform_state_values['fish'] = 'Jim';
    $this->assertSame($subform_state_values$subform_state->getValues());
  }

  /** * Provides data to self::testGetValues(). */
      $default_configuration = $plugin->defaultConfiguration();
      $configuration_stored_out_of_band = empty($default_configuration);
      // If this plugin is configurable but has not yet had user interaction,       // the default configuration will still be active and may trigger       // validation errors. Do not trigger those validation errors until the       // form is actually saved, to allow the user to first configure other       // CKEditor 5 functionality.       $default_configurations[$plugin_id] = $default_configuration;

      if ($form_state->hasValue(['plugins', $plugin_id])) {
        $subform = $form['plugins'][$plugin_id];
        $subform_state = SubformState::createForSubform($subform$form$form_state);
        $plugin->validateConfigurationForm($subform$subform_state);
        $plugin->submitConfigurationForm($subform$subform_state);

        // If the configuration is stored out of band, ::submitConfigurationForm         // will already have stored it. If it is not stored out of band,         // populate $settings, to populate $submitted_editor.         if (!$configuration_stored_out_of_band) {
          $settings['plugins'][$plugin_id] = $plugin->getConfiguration();
        }
      }
      // @see \Drupal\ckeditor5\Plugin\Editor\CKEditor5::injectPluginSettingsForm()
$form['#title'] = $this->t('Configure @section', ['@section' => $label]);
      }
    }
    // Passing available contexts to the layout plugin here could result in an     // exception since the layout may not have a context mapping for a required     // context slot on creation.     $this->layout = $section->getLayout();

    $form_state->setTemporaryValue('gathered_contexts', $this->getPopulatedContexts($this->sectionStorage));
    $form['#tree'] = TRUE;
    $form['layout_settings'] = [];
    $subform_state = SubformState::createForSubform($form['layout_settings']$form$form_state);
    $form['layout_settings'] = $this->getPluginForm($this->layout)->buildConfigurationForm($form['layout_settings']$subform_state);

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->isUpdate ? $this->t('Update') : $this->t('Add section'),
      '#button_type' => 'primary',
    ];
    if ($this->isAjax()) {
      $form['actions']['submit']['#ajax']['callback'] = '::ajaxSubmit';
      // @todo static::ajaxSubmit() requires data-drupal-selector to be the same       // between the various Ajax requests. A bug in
public function buildForm(array $form, FormStateInterface $form_state) {
    $form['foo'] = [
      '#type' => 'fieldset',
      '#title' => $this->t('Wrapper'),
      '#tree' => TRUE,
      '#parents' => ['foo'],
    ];
    $entity = EntityTest::load(1);
    if ($entity) {
      if ($entity) {
        $display = EntityFormDisplay::collectRenderDisplay($entity, 'default');
        $subform_state = SubformState::createForSubform($form['foo']$form$form_state);
        $display->buildForm($entity$form['foo']$subform_state);
        \Drupal::classResolver(FieldLayoutBuilder::class)->buildForm($form['foo']$display$subform_state);
      }
    }
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    
Home | Imprint | This part of the site doesn't use cookies.