0

I have created two entities and I want to connect them by route. my edit route is:

entity.entity_two.edit_form:

  path: 
'/property/configuration/communication/{entity_one}/variant/{entity_two}/edit'

  defaults:

    _entity_form: communication_variant.edit
    _title: 'Add/Edit Email Variant'
    entity_one: '%id'
  options:

    parameters:
      entity_one:
        type: 'entity_one'
      communication_variant:
        type: entity:node 

but I get an error on edit path as it says: entity one is empty but as i check entity one has value in the table. so my idea is that on submission of entity two form, I get entity_one id by entity reference and set in my route. so I want to implement that idea any help?

  • that type definition there looks wrong, are you sure that is what you used? What are your actual entity type ids? – Berdir Feb 20 '18 at 18:39
0

I have found the way to pass the value in edit route without using route subscriber or any pram converter. I will pass the value to Entity list builder default operations function. From there I can change the URL of edit and delete.

public function getDefaultOperations(EntityInterface $entity) {
    /* @var $entity \Drupal\my_module\Entity\entity_two */
    $operations = parent::getDefaultOperations($entity);
    $cid = $entity->cid->getString();
    $edit= \Drupal\Core\Url::fromRoute('entity.entity_two.edit_form',array('entity_one' => $cid , 'entity_two' => $entity->id()));
    $operations['edit'] = array(
        'title' => $this->t('edit'),
        'weight' => 10,
        'url' => $edit,
    );
    $delete= \Drupal\Core\Url::fromRoute('entity.entity_two.delete_form',array('entity_one' => $cid , 'entity_two' => $entity->id()));
    $operations['delete'] = array(
        'title' => $this->t('delete'),
        'weight' => 11,
        'url' => $delete,
    );

    return $operations;

}  

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.