定制 wieni/wmcustom_entity_form 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wieni/wmcustom_entity_form

最新稳定版本:1.5.0

Composer 安装命令:

composer require wieni/wmcustom_entity_form

包简介

Use custom entity forms per bundle

README 文档

README

Wieni logo

Drupal Custom Entity Form

Use custom entity forms per bundle.

Installation

composer require wieni/wmcustom_entity_form
drush en wmcustom_entity_form

Why

Because you like to build forms tailored to your client's needs. But you also like to keep codebase clean.

Use

This plugin-based module will look for entity forms in the Form/Entity directory of your modules.

The classes have to implement the @EntityForm annotation. The id you give that annotation will be used to match the entity type and bundle.

Caveats

This only works on forms created by the EntityFormBuilder. It won't kick in if your form is shown using inline entity form. In that case you'll still need to use HOOK_inline_entity_form_entity_form_alter

Example

<?php

namespace Drupal\mymodule\Form\Entity;

use Drupal\Core\Form\FormStateInterface;
use Drupal\wmcustom_entity_form\Annotation\EntityForm;
use Drupal\node\NodeForm;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * @EntityForm(
 *     id="node.article"
 * )
 */
class ArticleForm extends NodeForm
{
    public static function create(ContainerInterface $container)
    {
        // use dependency injection
        return new static(...);
    }

    public function form(array $form, FormStateInterface $formState)
    {
        $form = parent::form($form, $formState);
        // alter form without using any hooks

        // use afterbuilds with the :: notation for non-static afterbuilds
        $form['#after_build'][] = '::myAfterBuild';

        // access $this->entity; ( powerful combined with wieni/wmmodel )
        if ($this->entity->getWhatever()) {
            $form['field_foo_bar']['#access'] = false;
        }

        return $form;
    }

    public function myAfterBuild(array $form, FormStateInterface $formState)
    {
        // access to $this scope and all your injected dependencies
    }

    // override protected methods of the original entity form
    protected function actions(array $form, FormStateInterface $formState)
    {
        return parent::actions($form, $formState);
    }
}

Also see

统计信息

  • 总下载量: 17.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-26