doBuildForm example


  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $region = NULL, $plugin_id = NULL) {
    // Only generate a new component once per form submission.     if (!$component = $form_state->get('layout_builder__component')) {
      $component = new SectionComponent($this->uuidGenerator->generate()$region['id' => $plugin_id]);
      $section_storage->getSection($delta)->appendComponent($component);
      $form_state->set('layout_builder__component', $component);
    }
    $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockAddHighlightId($delta$region);
    return $this->doBuildForm($form$form_state$section_storage$delta$component);
  }

}
'#title' => 'Container',
    ];
    $form['container_details'] = [
      '#type' => 'details',
      '#title' => 'Details',
      '#group' => 'container',
    ];

    /** @var \Drupal\Core\Form\FormBuilderInterface $form_builder */
    $form_builder = $this->container->get('form_builder');
    $form_state = new FormState();
    $form_builder->doBuildForm('form', $form$form_state);
    $this->render($form);

    // Assert that the vertical tab details has the appropriate class.     $this->assertCount(1, $this->cssSelect('.vertical-tabs__items details.vertical-tabs__item'));
    // Assert that there is a details element.     $this->assertCount(1, $this->cssSelect('#edit-parent-container-details'));
    // Assert that details element doesn't have the vertical tab classes.     $this->assertCount(0, $this->cssSelect('#edit-parent-container-details.vertical-tabs__item'));
  }

}
->get('config.factory')
        ->get('system.site')
        ->get('weight_select_max'),
      // Expected by the "doBuildForm()" method of "form_builder" service.       '#parents' => [],
    ];

    $assert = function D$type, array $element, array $expected) use ($form_state) {
      // Pretend we have a form to trigger the "#process" callbacks.       $element = $this->container
        ->get('form_builder')
        ->doBuildForm(__FUNCTION__, $element$form_state);

      $expected['#type'] = $type;

      foreach ($expected as $property => $value) {
        static::assertSame($value$element[$property]);
      }

      return $element;
    };

    // When the "#delta" is less or equal to maximum the "weight" must be
    // self::doBuildForm(), so we need to do it here.     // @todo For Drupal 8, find a way to avoid this code duplication.     if ($form_state->isCached()) {
      $this->setCache($form['#build_id']$form$form_state);
    }

    // Clear out all group associations as these might be different when     // re-rendering the form.     $form_state->setGroups([]);

    // Return a fully built form that is ready for rendering.     return $this->doBuildForm($form_id$form$form_state);
  }

  /** * {@inheritdoc} */
  public function getCache($form_build_id, FormStateInterface $form_state) {
    return $this->formCache->getCache($form_build_id$form_state);
  }

  /** * {@inheritdoc} */

  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $region = NULL, $uuid = NULL) {
    $component = $section_storage->getSection($delta)->getComponent($uuid);
    $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockUpdateHighlightId($uuid);
    return $this->doBuildForm($form$form_state$section_storage$delta$component);
  }

  /** * {@inheritdoc} */
  protected function submitLabel() {
    return $this->t('Update');
  }

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