Skip to main content

快速生成 Form 的工具包 - Form Factory Kits

很方便生产自己的Form,Module 链接: Form Factory Kits

demo:

public function buildForm(array $form, FormStateInterface $form_state) {
    $factory = $this->formFactory->load($form);
    $k = $this->formFactoryKitsService;

    // Create VerticalTabsKit & add it to the FormFactory instance.
    $tabs = $k->verticalTabs();
    $factory->append($tabs);
    $factory->append( $k->date('foo')->setTitle($this->t('Foo')));

    // Create a "dogs" TabKit & add it to the VerticalTabsKit instance.
    $dogsTab = $tabs->createTab('dogs')
      ->setTitle($this->t('Dogs'));
    $dogsTab->append(
      $k->image('dogs_image')
        ->setTitle($this->t('Image'))
    );
    $dogsTab->append(
      $k->textarea('dogs_description')
        ->setTitle($this->t('Description'))
    );
    $dogsTab->append(
      $k->checkboxes('dogs_attributes')
        ->setTitle($this->t('Attributes'))
        ->appendOption(['a' => $this->t('A')])
        ->appendOption(['b' => $this->t('B')])
        ->appendOption(['c' => $this->t('C')])
        ->setDefaultValue(['b'])
    );

    // Create a "cats" TabKit & add it to the VerticalTabsKit instance.
    $tabs->createTab('cats')
      ->setTitle($this->t('Cats'))
      ->append($k->image('cats_image')->setTitle($this->t('Image')))
      ->append($k->textarea('cats_description')->setTitle($this->t('Description')));

    // Create a SubmitKit & add it to the FormFactory instance.
    $factory->append($k->submit());

    // Return the modified $form render array.
    return $factory->getForm();
}

另外推荐几个 Module:

H5P : 可生产试题模板,种类很多,功能强大

Vsauce Sticky Popup : 方便在页面添加浮动标签

Toast UI Editor : markdown 编辑器