2

Suppose, I've two entities:

entityA
entityB

A user creates an entityA and has the option of creating multiple types of entityB referenced from a single entityA. For example, a parent-child relationship. Parent being entityA and child being entityB.

In the module, I want the users to select an entityA object, go to a new page page for creating entityB. So, at this point, (add-form of entityB) I should have the data of that particular entityA object that the user clicked on.

So, far I'm able to get "all" the data of entityA on the add-form of entityB, which is of no help as I'm unable to get the specific id of entityA.

The relevant code are:

routing.yml

mymodule.entityB_add:
  path: '/admin/config/mymodule/{entityA}/entityB/add'
  defaults:
    _entity_form: 'mymodule_entityA_entityB.default'
    _title: 'EntityB'
  requirements:
    _entity_create_access: 'mymodule_entityA'

When, I'm shown the form addition page of entityB (type: ../../testentitya/entityA/add), how do I pass the entityA object to the form and what will be the structure of entityB's config schema?

  • "entityB's config schema" -- is entityB a config entity?? – user49 Jul 24 '14 at 8:40
  • @chx: Yes. Both entities are config entity. – xan Jul 24 '14 at 8:44
  • I don't understand the difference of this question to drupal.stackexchange.com/questions/124065/…? seems exactly the same to me and does answer the question IMHO. Yes, it uses content and config entities/bundles, but that doesn't really matter. – Berdir Jul 25 '14 at 21:19
  • @Berdir: Yes, they don't have any difference. I've already flagged it for moderators asking them to delete it. After posting this question, I realized I should have edited that one. My bad. – xan Jul 26 '14 at 18:43
2

Regarding the references: config entities are simple beasts. Entity references are only supported on content entities; however you are on the way of building it out yourself tailored for your needs. So, just store a string with the id of configA and that's about it. What you do with a string is your call.

2

Have a look at https://www.drupal.org/node/2310425

This should explaine everything needed.

Here is an example how it would look like:

mymodule.entityB_add:
  path: '/admin/config/mymodule/{entityA}/{entityB}/add'
  defaults:
    _entity_form: 'mymodule_entityA_entityB.default'
    _title: 'EntityB'
  requirements:
    _entity_create_access: 'mymodule_entityA'
  options:
    parameters:
      entityA:
        type: entity:entity_type_a
      entityB:
        type: entity:entity_type_b
  • The example doesn't make too much sense to me, as you're adding an entityB, you can't pass anything to it? You only pass around entityA? – Berdir Jul 25 '14 at 21:18

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.