-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates #14
- Loading branch information
Showing
4 changed files
with
76 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
# @copyright 2017 City of Bloomington, Indiana | ||
# @copyright 2017-2021 City of Bloomington, Indiana | ||
# @license https://www.gnu.org/licenses/old-licenses/gpl-2.0 GNU/GPL2, see LICENSE | ||
# | ||
# This file is part of the Google Calendar drupal module. | ||
# | ||
# The calendar module is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# The calendar module is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with the calendar module. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0/>. | ||
--- | ||
services: | ||
calendar.twig.TwigExtension: | ||
class: '\Drupal\calendar\Twig\TwigExtension' | ||
tags: | ||
- { name: twig.extension } | ||
calendar.breadcrumb: | ||
class: '\Drupal\calendar\Breadcrumb\BreadcrumbBuilder' | ||
tags: | ||
- { name: 'breadcrumb_builder', priority: 100 } | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* @copyright 2021 City of Bloomington, Indiana | ||
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0 GNU/GPL2, see LICENSE | ||
*/ | ||
namespace Drupal\calendar\Breadcrumb; | ||
use Drupal\calendar\GoogleGateway; | ||
|
||
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface; | ||
use Drupal\Core\Routing\RouteMatchInterface; | ||
use Drupal\Core\Breadcrumb\Breadcrumb; | ||
use Drupal\Core\Link; | ||
use Drupal\Core\Url; | ||
|
||
class BreadcrumbBuilder implements BreadcrumbBuilderInterface | ||
{ | ||
public function applies(RouteMatchInterface $route_match) | ||
{ | ||
$name = explode('.', $route_match->getRouteName()); | ||
return $name[0] == 'calendar'; | ||
} | ||
|
||
public function build(RouteMatchInterface $route_match): Breadcrumb | ||
{ | ||
$route = $route_match->getRouteName(); | ||
$breadcrumb = new Breadcrumb(); | ||
$breadcrumb->addCacheContexts(['url']); | ||
$breadcrumb->addLink(Link::createFromRoute('Home', '<front>')); | ||
|
||
$config = \Drupal::config('calendar.settings'); | ||
$nids = explode(',', $config->get('calendar_breadcrumb')); | ||
$nodes = \Drupal::entityTypeManager()->getStorage('node')->loadMultiple($nids); | ||
foreach ($nodes as $n) { | ||
$breadcrumb->addLink(Link::createFromRoute($n->title->value, 'entity.node.canonical', ['node'=>$n->nid->value])); | ||
} | ||
if ($route == 'calendar.event_view') { | ||
try { | ||
$id = $route_match->getParameter('calendar_id'); | ||
$cal = GoogleGateway::calendar($id); | ||
$uri = "https://calendar.google.com/calendar/embed?src=$id&ctz=America/New_York"; | ||
$url = Url::fromUri($uri, ['absolute' => true, 'https' => true]); | ||
$breadcrumb->addLink(Link::fromTextAndUrl($cal->summary, $url)); | ||
|
||
} | ||
catch (\Exception $e) { } | ||
} | ||
|
||
return $breadcrumb; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters