You are here

public function Page::addVariant in Page Manager 8

Same name and namespace in other branches
  1. 8.4 src/Entity/Page.php \Drupal\page_manager\Entity\Page::addVariant()

Adds a variant to this page.

Parameters

\Drupal\page_manager\PageVariantInterface $variant: A page variant entity.

Return value

$this

Overrides PageInterface::addVariant

File

src/Entity/Page.php, line 383
Contains \Drupal\page_manager\Entity\Page.

Class

Page
Defines a Page entity class.

Namespace

Drupal\page_manager\Entity

Code

public function addVariant(PageVariantInterface $variant) {

  // If variants hasn't been initialized, we initialize it before adding the
  // new variant.
  if ($this->variants === NULL) {
    $this
      ->getVariants();
  }
  $this->variants[$variant
    ->id()] = $variant;
  $this
    ->sortVariants();
  return $this;
}