コード例 #1
0
ファイル: EntityCloneForm.php プロジェクト: eloiv/botafoc.cat
  /**
   * {@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>');
  }
コード例 #2
0
 /**
  * Tests the hasHandler() method.
  *
  * @covers ::hasHandler
  *
  * @dataProvider providerTestHasHandler
  */
 public function testHasHandler($entity_type_id, $expected)
 {
     $apple = $this->prophesize(EntityTypeInterface::class);
     $apple->hasHandlerClass('storage')->willReturn(TRUE);
     $banana = $this->prophesize(EntityTypeInterface::class);
     $banana->hasHandlerClass('storage')->willReturn(FALSE);
     $this->setUpEntityTypeDefinitions(['apple' => $apple, 'banana' => $banana]);
     $entity_type = $this->entityTypeManager->hasHandler($entity_type_id, 'storage');
     $this->assertSame($expected, $entity_type);
 }