An open API service indexing awesome lists of open source software.

https://github.com/wieni/wmcustom_entity_form

An easy way to extend from a Drupal core EntityForm per bundle.
https://github.com/wieni/wmcustom_entity_form

Last synced: 3 months ago
JSON representation

An easy way to extend from a Drupal core EntityForm per bundle.

Awesome Lists containing this project

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
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

- [wieni/wmmodel](https://github.com/wieni/wmmodel) to have a model class per bundle.
- [wieni/wmcontroller](https://github.com/wieni/wmcontroller) to have a controller per bundle.