setupBundle example

$this->entityTypeId = 'comment';
    $this->bundle = 'comment_article';
    $this->testLanguageSelector = FALSE;
    $this->subject = $this->randomMachineName();
    parent::setUp();
  }

  /** * {@inheritdoc} */
  public function setupBundle() {
    parent::setupBundle();
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'article']);
    // Add a comment field to the article content type.     $this->addDefaultCommentField('node', 'article', 'comment_article', CommentItemInterface::OPEN, 'comment_article');
    // Create a page content type.     $this->drupalCreateContentType(['type' => 'page', 'name' => 'page']);
    // Add a comment field to the page content type - this one won't be     // translatable.     $this->addDefaultCommentField('node', 'page', 'comment');
    // Mark this bundle as translatable.     $this->container->get('content_translation.manager')->setEnabled('comment', 'comment_article', TRUE);
  }

  
/** * {@inheritdoc} */
  protected function getTranslatorPermissions() {
    return array_merge(parent::getTranslatorPermissions()$this->commonPermissions);
  }

  /** * {@inheritdoc} */
  protected function setupBundle() {
    parent::setupBundle();
    $this->createContentType(['type' => $this->bundle]);
    $this->createEditorialWorkflow();
  }

  /** * Loads the active revision translation for the specified entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity being edited. * @param string $langcode * The translation language code. * * @return \Drupal\Core\Entity\ContentEntityInterface|null * The active revision translation or NULL if none could be identified. */

  protected function setUp(): void {
    $this->entityTypeId = 'taxonomy_term';
    $this->bundle = 'tags';
    parent::setUp();
  }

  /** * {@inheritdoc} */
  protected function setupBundle() {
    parent::setupBundle();

    // Create a vocabulary.     $this->vocabulary = Vocabulary::create([
      'name' => $this->bundle,
      'description' => $this->randomMachineName(),
      'vid' => $this->bundle,
      'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
      'weight' => mt_rand(0, 10),
    ]);
    $this->vocabulary->save();
  }

  

  protected $manager;

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->setupLanguages();
    $this->setupBundle();
    $this->enableTranslation();
    $this->setupUsers();
    $this->setupTestFields();

    $this->manager = $this->container->get('content_translation.manager');
    $this->controller = $this->manager->getTranslationHandler($this->entityTypeId);

    // Rebuild the container so that the new languages are picked up by services     // that hold a list of languages.     $this->rebuildContainer();
  }

  
Home | Imprint | This part of the site doesn't use cookies.