i have:
/** * @ContentEntityType( * id = "my_entity", * label = @Translation("drwywr werwer label"), * bundle_label = @Translation("My entity type"), * handlers = { * bla... * "form" = { * "default" = "Drupal\my_entity\Form\MyEntityForm", * "edit" = "Drupal\my_entity\Form\MyEntityForm", * "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm" * }, * bla... * }, * translatable = FALSE, * entity_keys = { bla... }, * bundle_entity_type = "my_entity_type", * links = { * "collection" = "/admin/test/entity/collection", * "canonical" = "/admin/test/entity/{my_entity}", * "edit-form" = "/admin/test/entity/{my_entity}/edit", * "delete-form" = "/admin/test/entity/{my_entity}/delete" * } * ) */ based on above, how do i load my entity in form below:
<?php namespace Drupal\my_entity\Form; use bla... /** * Form controller for the node edit forms. */ class MyEntityForm extends ContentEntityForm { //how to load my entity type here? } i tried a couple way but i keep receiving:
Error: Call to a member function getEntityTypeId() on null
mainly because the entity is not loaded (null value)
this is how i create the route:
in my_entity.routing.yml:
route_callbacks: - 'entity.my_entity.routes::routes' in routes:
public function routes() { // Build Entity Create Route - CREATE $route = new Route( (substr($type->getRoute()['path'], -1) == '/' ? $type->getRoute()['path'] . $type->id() : $type->getRoute()['path'] . '/' . $type->id()) . '/create', [ '_form' => '\Drupal\my_entity\Form\MyEntityForm', //TODO : not finish 'entity_type' => 'my_entity', 'bundle' => $type->id(), '_title' => 'Create ' . $type->getRoute()['label'], ], ['_permission' => 'entity admin settings'] ); $route_collection->add('entity.my_entity.' . $type->id() . '_create', $route); } if you see in my content entity type config above, i have:
* links = { * "collection" = "/admin/test/entity/collection", * "canonical" = "/admin/test/entity/{my_entity}", * "edit-form" = "/admin/test/entity/{my_entity}/edit", * "delete-form" = "/admin/test/entity/{my_entity}/delete" * } which i want those: edit, delete to be able to 'link' with my form as well - how to do this?
what i'm trying to achieve is: to generate forms based on field define in my entity type