1. Go to this page and download the library: Download wieni/wmcustom_entity_form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wieni / wmcustom_entity_form example snippets
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);
}
}
composer wmcustom_entity_form
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.