class Tour

Same name and namespace in other branches
  1. 10 core/modules/tour/src/Entity/Tour.php \Drupal\tour\Entity\Tour
  2. 8.9.x core/modules/tour/src/Entity/Tour.php \Drupal\tour\Entity\Tour

Defines the configured tour entity.

Plugin annotation


@ConfigEntityType(
  id = "tour",
  label = @Translation("Tour"),
  label_collection = @Translation("Tours"),
  label_singular = @Translation("tour"),
  label_plural = @Translation("tours"),
  label_count = @PluralTranslation(
    singular = "@count tour",
    plural = "@count tours",
  ),
  handlers = {
    "view_builder" = "Drupal\tour\TourViewBuilder",
    "access" = "Drupal\tour\TourAccessControlHandler",
  },
  admin_permission = "administer site configuration",
  entity_keys = {
    "id" = "id",
    "label" = "label"
  },
  config_export = {
    "id",
    "label",
    "module",
    "routes",
    "tips",
  },
  lookup_keys = {
    "routes.*.route_name"
  }
)

Hierarchy

Expanded class hierarchy of Tour

8 files declare their use of Tour
ConfigInstallProfileOverrideTest.php in core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php
tour.module in core/modules/tour/tour.module
Main functions of the module.
tour.post_update.php in core/modules/tour/tour.post_update.php
Post update functions for Tour.
TourCacheTagsTest.php in core/modules/tour/tests/src/Functional/TourCacheTagsTest.php
TourPluginTest.php in core/modules/tour/tests/src/Kernel/TourPluginTest.php

... See full list

20 string references to 'Tour'
ConfigInstallProfileOverrideTest::testInstallProfileConfigOverwrite in core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php
Tests install profile config changes.
config_test.dynamic.override.yml in core/profiles/testing_config_overrides/config/optional/config_test.dynamic.override.yml
core/profiles/testing_config_overrides/config/optional/config_test.dynamic.override.yml
config_test.dynamic.override_unmet.yml in core/modules/config/tests/config_test/config/optional/config_test.dynamic.override_unmet.yml
core/modules/config/tests/config_test/config/optional/config_test.dynamic.override_unmet.yml
demo_umami.info.yml in core/profiles/demo_umami/demo_umami.info.yml
core/profiles/demo_umami/demo_umami.info.yml
standard.info.yml in core/profiles/standard/standard.info.yml
core/profiles/standard/standard.info.yml

... See full list

File

core/modules/tour/src/Entity/Tour.php, line 43

Namespace

Drupal\tour\Entity
View source
class Tour extends ConfigEntityBase implements TourInterface {
  
  /**
   * The name (plugin ID) of the tour.
   *
   * @var string
   */
  protected $id;
  
  /**
   * The module which this tour is assigned to.
   *
   * @var string
   */
  protected $module;
  
  /**
   * The label of the tour.
   *
   * @var string
   */
  protected $label;
  
  /**
   * The routes on which this tour should be displayed.
   *
   * @var array
   */
  protected $routes = [];
  
  /**
   * The routes on which this tour should be displayed, keyed by route id.
   *
   * @var array
   */
  protected $keyedRoutes;
  
  /**
   * Holds the collection of tips that are attached to this tour.
   *
   * @var \Drupal\tour\TipsPluginCollection
   */
  protected $tipsCollection;
  
  /**
   * The array of plugin config, only used for export and to populate the $tipsCollection.
   *
   * @var array
   */
  protected $tips = [];
  
  /**
   * {@inheritdoc}
   */
  public function __construct(array $values, $entity_type) {
    parent::__construct($values, $entity_type);
    $this->tipsCollection = new TipsPluginCollection(\Drupal::service('plugin.manager.tour.tip'), $this->tips);
  }
  
  /**
   * {@inheritdoc}
   */
  public function getRoutes() {
    return $this->routes;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getTip($id) {
    return $this->tipsCollection
      ->get($id);
  }
  
  /**
   * {@inheritdoc}
   */
  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);
  }
  
  /**
   * {@inheritdoc}
   */
  public function getModule() {
    return $this->module;
  }
  
  /**
   * {@inheritdoc}
   */
  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])) {
      // We don't know about this route.
      return FALSE;
    }
    if (empty($this->keyedRoutes[$route_name])) {
      // We don't need to worry about route params, the route name is enough.
      return TRUE;
    }
    foreach ($this->keyedRoutes[$route_name] as $key => $value) {
      // If a required param is missing or doesn't match, return FALSE.
      if (empty($route_params[$key]) || $route_params[$key] !== $value) {
        return FALSE;
      }
    }
    return TRUE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function resetKeyedRoutes() {
    unset($this->keyedRoutes);
  }
  
  /**
   * {@inheritdoc}
   */
  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;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.