Same filename and directory in other branches
- 8.9.x core/modules/tour/src/Entity/Tour.php
- 9 core/modules/tour/src/Entity/Tour.php
Namespace
Drupal\tour\Entity
File
core/modules/tour/src/Entity/Tour.php
View source
<?php
namespace Drupal\tour\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\tour\TipsPluginCollection;
use Drupal\tour\TourInterface;
class Tour extends ConfigEntityBase implements TourInterface {
protected $id;
protected $module;
protected $label;
protected $routes = [];
protected $keyedRoutes;
protected $tipsCollection;
protected $tips = [];
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
$this->tipsCollection = new TipsPluginCollection(\Drupal::service('plugin.manager.tour.tip'), $this->tips);
}
public function getRoutes() {
return $this->routes;
}
public function getTip($id) {
return $this->tipsCollection
->get($id);
}
public function getTips() {
$tips = [];
foreach ($this->tips as $id => $tip) {
$tips[] = $this
->getTip($id);
}
uasort($tips, function ($a, $b) {
return $a
->getWeight() <=> $b
->getWeight();
});
\Drupal::moduleHandler()
->alter('tour_tips', $tips, $this);
return array_values($tips);
}
public function getModule() {
return $this->module;
}
public function hasMatchingRoute($route_name, $route_params) {
if (!isset($this->keyedRoutes)) {
$this->keyedRoutes = [];
foreach ($this
->getRoutes() as $route) {
$this->keyedRoutes[$route['route_name']] = $route['route_params'] ?? [];
}
}
if (!isset($this->keyedRoutes[$route_name])) {
return FALSE;
}
if (empty($this->keyedRoutes[$route_name])) {
return TRUE;
}
foreach ($this->keyedRoutes[$route_name] as $key => $value) {
if (empty($route_params[$key]) || $route_params[$key] !== $value) {
return FALSE;
}
}
return TRUE;
}
public function resetKeyedRoutes() {
unset($this->keyedRoutes);
}
public function calculateDependencies() {
parent::calculateDependencies();
foreach ($this->tipsCollection as $instance) {
$definition = $instance
->getPluginDefinition();
$this
->addDependency('module', $definition['provider']);
}
$this
->addDependency('module', $this->module);
return $this;
}
}
Classes
Name |
Description |
Tour |
Defines the configured tour entity. |