/** * Tests the getHandler() method when no controller is defined. * * @covers ::getHandler * * @expectedException \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ public function testGetHandlerMissingHandler() { $entity = $this->prophesize(EntityTypeInterface::class); $entity->getHandlerClass('storage')->willReturn(''); $this->setUpEntityTypeDefinitions(['test_entity_type' => $entity]); $this->entityTypeManager->getHandler('test_entity_type', 'storage'); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { /** @var \Drupal\entity_clone\EntityClone\EntityCloneInterface $entity_clone_handler */ $entity_clone_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone'); if ($this->entityTypeManager->hasHandler($this->entityTypeDefinition->id(), 'entity_clone_form')) { $entity_clone_form_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone_form'); } $properties = []; if (isset($entity_clone_form_handler) && $entity_clone_form_handler) { $properties = $entity_clone_form_handler->getNewValues($form_state); } $cloned_entity = $entity_clone_handler->cloneEntity($this->entity, $this->entity->createDuplicate(), $properties); drupal_set_message($this->stringTranslationManager->translate('The entity <em>@entity (@entity_id)</em> of type <em>@type</em> was cloned', [ '@entity' => $this->entity->label(), '@entity_id' => $this->entity->id(), '@type' => $this->entity->getEntityTypeId(), ])); if ($cloned_entity && $cloned_entity->hasLinkTemplate('canonical')) { $form_state->setRedirect($cloned_entity->toUrl() ->getRouteName(), $cloned_entity->toUrl()->getRouteParameters()); } $form_state->setRedirect('<front>'); }