Skip to content

Commit

Permalink
added back else statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleverrier committed Nov 8, 2019
1 parent 6d0d73b commit c3d51d5
Showing 1 changed file with 17 additions and 44 deletions.
61 changes: 17 additions & 44 deletions src/services/BreadcrumbService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace youandmedigital\breadcrumb\services;

use youandmedigital\breadcrumb\Breadcrumb;

use Craft;
use craft\base\Component;

Expand Down Expand Up @@ -61,9 +62,7 @@ public function buildBreadcrumb($settings) : array
}

// set custom baseUrl
if (
$customBaseUrl
) {
if ($customBaseUrl) {
$baseUrl = $customBaseUrl;
}

Expand All @@ -80,60 +79,40 @@ public function buildBreadcrumb($settings) : array
$isElement = Craft::$app->elements->getElementByUri(ltrim($path, '/'));

// if isElement belongs to element interface...
if (
$isElement instanceof \craft\base\ElementInterface
) {
if ($isElement instanceof \craft\base\ElementInterface) {

// check if isElement has a traditional title
if (
$isElement->hasTitles()
) {
if ($isElement->hasTitles()) {

// check if hasCustomFieldSetting returns true
if (
$hasCustomFieldSetting
) {
if ($hasCustomFieldSetting) {
// set title to customFieldHandle if it returns a value, otherwise fallback to element title
$title = $isElement->$customFieldHandle ? $isElement->$customFieldHandle : $isElement->title;
}

// check if hasCustomFieldSetting returns false
if (
!$hasCustomFieldSetting
) {
// otherwise use the title field
else {
$title = $isElement->title;
}

}

// check if isElement has no title
if (
!$isElement->hasTitles()
) {
// if isElement has no title
else {

// check if hasCustomFieldSetting returns true
if (
$hasCustomFieldSetting
) {
if ($hasCustomFieldSetting) {
// set title to customFieldHandle if it returns a value, otherwise fallback to URL segment
$title = $isElement->$customFieldHandle ? $isElement->$customFieldHandle : $generatedTitle;
}

// check if hasCustomFieldSetting returns false
if (
!$hasCustomFieldSetting
) {
// otherwise use the URL segment
else {
$title = $generatedTitle;
}

}

}

// if isElement does not belong to element interface...
if (
!$isElement instanceof \craft\base\ElementInterface
) {
// otherwise, we're not dealing with an element
else {
// we're out of options. build the title from the URL segment
$title = $generatedTitle;
}
Expand All @@ -153,9 +132,7 @@ public function buildBreadcrumb($settings) : array
}

// last segment title
if (
$lastSegmentTitle
) {
if ($lastSegmentTitle) {
// move internal pointer to the end of the array
end($breadcrumbArray);
// fetch last key in array...
Expand All @@ -165,17 +142,13 @@ public function buildBreadcrumb($settings) : array
}

// skip URL segment
if (
$skipUrlSegment
) {
if ($skipUrlSegment) {
$index = $skipUrlSegment - 1;
unset($breadcrumbArray[$index]);
}

// limit and return the amount of results
if (
$limit
) {
if ($limit) {
return array_slice($breadcrumbArray, 0, $limit);
}

Expand Down

0 comments on commit c3d51d5

Please sign in to comment.