Skip to content

Commit

Permalink
Fix Site not not using the site name as the default title
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Jul 10, 2023
1 parent 3de2ac3 commit 38a1cd6
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/nodetypes/SiteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
namespace verbb\navigation\nodetypes;

use verbb\navigation\base\NodeType;
use verbb\navigation\elements\Node;

use Craft;
use craft\models\Site;

class SiteType extends NodeType
{
Expand Down Expand Up @@ -51,17 +53,41 @@ public function getSettingsHtml(): ?string
return Craft::$app->getView()->renderTemplate('navigation/_types/site/settings');
}

public function getDefaultTitle(): string
{
if ($site = $this->_getSite()) {
if ($site->hasUrls) {
return $site->name;
}
}

return parent::getDefaultTitle();
}

public function getUrl(): ?string
{
if ($site = $this->_getSite()) {
if ($site->hasUrls) {
return rtrim($site->getBaseUrl(), '/');
}
}

return null;
}


// Private Methods
// =========================================================================

private function _getSite(): ?Site
{
$data = $this->node->data ?? [];

if ($data) {
$siteId = $data['siteId'] ?? null;

if ($siteId && $site = Craft::$app->getSites()->getSiteById($siteId)) {
if ($site->hasUrls) {
return rtrim($site->getBaseUrl(), '/');
}
return $site;
}
}

Expand Down

0 comments on commit 38a1cd6

Please sign in to comment.