Skip to main content
2 of 3
edited tags
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How do I upcast route parameters for entity_revision?

My custom entity is revisionable, I can see revisions, but my revision revert form does not work. When I attempt to revert, I get the following error:

TypeError: Argument 3 passed to Drupal\msul_rovi_games\Form\RoviGameRevisionRevertForm::buildForm() must implement interface Drupal\msul_rovi_games\Entity\RoviGameInterface or be null, string given in Drupal\msul_rovi_games\Form\RoviGameRevisionRevertForm->buildForm() (line 116 of /opt/drupal/web/modules/custom/msul_rovi_games/src/Form/RoviGameRevisionRevertForm.php)

I am not sure why it is not upcasting. I am sure I am missing something obvious, but hours of searching have not led me to what I am missing.

What am I missing? Any insight into why it is not upcasting would be greatly appreciated!


Relevant portion of msul_rovi_games.routing.yml

entity.rovi_game.revision_revert_confirm:
  path: '/rovi_game/{rovi_game}/revisions/{rovi_game_revision}/revert'
  defaults:
    _title: 'Revert to an earlier revision'
    _form: '\Drupal\msul_rovi_games\Form\RoviGameRevisionRevertForm'
  requirements:
    _permission: 'administer rovi_game entities'
    rovi_game: \d+
  options:
    _node_operation_route: TRUE
    rovi_game:
      type: entity:rovi_game
    rovi_game_revision:
      type: entity_revision:rovi_game

Relevant portion of src/Form/RoviGameRevisionRevertForm.php

<?php

namespace Drupal\msul_rovi_games\Form;

use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\msul_rovi_games\Entity\RoviGameInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Provides a form for reverting a rovi_game revision.
 *
 * @internal
 */
class RoviGameRevisionRevertForm extends ConfirmFormBase {

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state, RoviGameInterface $rovi_game_revision = NULL) {
    $this->revision = $rovi_game_revision;
    $form = parent::buildForm($form, $form_state);

    return $form;
  }
}