-1

I will start off by saying i have already studied these posts, to no avail:

Overriding an entity add/edit form through alterroute

How to load my Entity in Entity form

https://www.drupal.org/docs/8/api/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones

I am trying to alter my add-entity route to be not under /admin, as we want this form to use the default theme, not admin theme.

My module is 'project', my entity is 'project'. Here is my route in the project.routing.yml file:

mycompany.project.add_form:
  path: '/mycompany/project/add/{project_type}'
  defaults:
    _entity_form: 'project.default' #I have also tried custom form_mode here
    _title: 'Add Project'
  requirements:
    _permission: 'add project entities'

I get the error: Call to a member function id() on string in /Applications/MAMP/htdocs/sfchapter6nov2/core/lib/Drupal/Core/Entity/EntityForm.php on line 363

Yes, this error has been documented before, with posts such as the ones above. I believe my unique problem is because my entity has an entity type, ie a bundle. The {project_type} is my bundle name. The EntityForm does not have an instance of the entity, and I cannot find where to create it.

Help and suggestions much appreciated! Mary Edith

1

The problem is that now the route parameter is a string and so you generate the error. You need to upcast the route parameter to an entity (the config entity of the bundle):

  options:
    parameters:
      project_type:
        type: entity:project_type

More info https://www.drupal.org/docs/8/api/routing-system/parameter-upcasting-in-routes

  • Thank you very very much, 4k4. This information was in the other posts, but not in a way that enabled me to I understand how to use it. I had tried 'type:project:city_project', using my bundle name rather than bundle type name. I appreciate so much getting speedy answers on this site!!!! – MEI Nov 29 '17 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.