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.
- Host: GitHub
- URL: https://github.com/wieni/wmcustom_entity_form
- Owner: wieni
- Created: 2019-09-23T06:21:40.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-09-12T12:16:54.000Z (over 1 year ago)
- Last Synced: 2025-01-28T01:02:27.373Z (4 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 0
- Watchers: 7
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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.