Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\forum\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Breadcrumb\BreadcrumbBuilderInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\forum\ForumManagerInterface;
|
||||
|
||||
/**
|
||||
* Provides a forum breadcrumb base class.
|
||||
*
|
||||
* This just holds the dependency-injected config, entity manager, and forum
|
||||
* manager objects.
|
||||
*/
|
||||
abstract class ForumBreadcrumbBuilderBase implements BreadcrumbBuilderInterface {
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* Configuration object for this builder.
|
||||
*
|
||||
* @var \Drupal\Core\Config\Config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* The forum manager service.
|
||||
*
|
||||
* @var \Drupal\forum\ForumManagerInterface
|
||||
*/
|
||||
protected $forumManager;
|
||||
|
||||
/**
|
||||
* Constructs a forum breadcrumb builder object.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The configuration factory.
|
||||
* @param \Drupal\forum\ForumManagerInterface $forum_manager
|
||||
* The forum manager service.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, ForumManagerInterface $forum_manager) {
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->config = $config_factory->get('forum.settings');
|
||||
$this->forumManager = $forum_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>');
|
||||
|
||||
$vocabulary = $this->entityManager
|
||||
->getStorage('taxonomy_vocabulary')
|
||||
->load($this->config->get('vocabulary'));
|
||||
$breadcrumb[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder.
|
||||
*/
|
||||
|
||||
namespace Drupal\forum\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Provides a breadcrumb builder base class for forum listing pages.
|
||||
*/
|
||||
class ForumListingBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applies(RouteMatchInterface $route_match) {
|
||||
return $route_match->getRouteName() == 'forum.page' && $route_match->getParameter('taxonomy_term');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb = parent::build($route_match);
|
||||
|
||||
// Add all parent forums to breadcrumbs.
|
||||
$term_id = $route_match->getParameter('taxonomy_term')->id();
|
||||
$parents = $this->forumManager->getParents($term_id);
|
||||
if ($parents) {
|
||||
foreach (array_reverse($parents) as $parent) {
|
||||
if ($parent->id() != $term_id) {
|
||||
$breadcrumb[] = Link::createFromRoute($parent->label(), 'forum.page', array(
|
||||
'taxonomy_term' => $parent->id(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder.
|
||||
*/
|
||||
|
||||
namespace Drupal\forum\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
|
||||
/**
|
||||
* Breadcrumb builder for forum nodes.
|
||||
*/
|
||||
class ForumNodeBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applies(RouteMatchInterface $route_match) {
|
||||
return $route_match->getRouteName() == 'entity.node.canonical'
|
||||
&& $route_match->getParameter('node')
|
||||
&& $this->forumManager->checkNodeType($route_match->getParameter('node'));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb = parent::build($route_match);
|
||||
|
||||
$parents = $this->forumManager->getParents($route_match->getParameter('node')->forum_tid);
|
||||
if ($parents) {
|
||||
$parents = array_reverse($parents);
|
||||
foreach ($parents as $parent) {
|
||||
$breadcrumb[] = Link::createFromRoute($parent->label(), 'forum.page',
|
||||
array(
|
||||
'taxonomy_term' => $parent->id(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue