*/
protected $_variant = '';
+ /**
+ * @var array
+ */
+ protected $_availableVariants = [];
+
/**
* @var CubistMagicPageModel
*/
public function getCanonicalURL(): string
{
+ $canonicalVariant = null;
+ if (App::hasVariant()) {
+ $availableVariants = $this->getAvailableVariants();
+
+ if (count($availableVariants) > 1 && $this->getVariant() !== $availableVariants[0]) {
+ $canonicalVariant = $availableVariants[0];
+ }
+ }
+
$canonical = $this->getCanonical() === '' ? $this->getHref() : $this->getCanonical();
- return $this->_getURL($canonical);
+ return $this->_getURL($canonical, null, $canonicalVariant);
}
public function getURL()
return $this->_getURL($this->getHref());
}
- protected function _getURL($href)
+ protected function _getURL($href, $locale = null, $variant = null)
{
- $domain = Locale::getMainDomain($this->getLocale(), $this->getVariant());
+ if (null === $locale) {
+ $locale = $this->getLocale();
+ }
+ if (null === $variant) {
+ $variant = $this->getVariant();
+ }
+
+ $domain = Locale::getMainDomain($locale, $variant);
if ($href === 'home') {
$href = '';
$this->_variant = $variant;
}
+ /**
+ * @param array $availableVariants
+ */
+ public function setAvailableVariants(array $availableVariants): void
+ {
+ $this->_availableVariants = $availableVariants;
+ }
+
+ /**
+ * @return array
+ */
+ public function getAvailableVariants(): array
+ {
+ return $this->_availableVariants;
+ }
+
/**
* @return bool
*/
use Cubist\Backpack\app\Magic\Models\CMSPage;
use Cubist\Backpack\app\Magic\Models\CubistMagicPageModel;
+use Cubist\Backpack\Facades\App;
class PageItem extends Item
{
$this->setSlug($data->get('slug'));
$this->setTitle($data->get('title'));
$this->setRobots($data->get('robots', true));
+ $this->setAvailableVariants($data->get('variant', App::getVariants()));
$desktop = $entity->menu_desktop == '' ? 'children' : $entity->menu_desktop;