Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
132
web/core/modules/tour/src/Plugin/HelpSection/TourHelpSection.php
Normal file
132
web/core/modules/tour/src/Plugin/HelpSection/TourHelpSection.php
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\tour\Plugin\HelpSection;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\help\Plugin\HelpSection\HelpSectionPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides the tours list section for the help page.
|
||||
*
|
||||
* @HelpSection(
|
||||
* id = "tour",
|
||||
* title = @Translation("Tours"),
|
||||
* description = @Translation("Tours guide you through workflows or explain concepts on various user interface pages. The tours with links in this list are on user interface landing pages; the tours without links will show on individual pages (such as when editing a View using the Views UI module). Available tours:"),
|
||||
* permission = "access tour"
|
||||
* )
|
||||
*/
|
||||
class TourHelpSection extends HelpSectionPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Constructs a TourHelpSection object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity manager service.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static(
|
||||
$configuration,
|
||||
$plugin_id,
|
||||
$plugin_definition,
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheMaxAge() {
|
||||
// The calculation of which URL (if any) gets put on which tour depends
|
||||
// on a route access check. This can have a lot of inputs, including user
|
||||
// permissions and other factors. Rather than doing a complicated
|
||||
// accounting of the cache metadata for all of these possible factors, set
|
||||
// the max age of the cache to zero to prevent using incorrect cached
|
||||
// information.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listTopics() {
|
||||
/** @var \Drupal\tour\TourInterface[] $tours */
|
||||
$tours = $this->entityTypeManager->getStorage('tour')->loadMultiple();
|
||||
// Sort in the manner defined by Tour.
|
||||
uasort($tours, ['Drupal\tour\Entity\Tour', 'sort']);
|
||||
|
||||
// Make a link to each tour, using the first of its routes that can
|
||||
// be linked to by this user, if any.
|
||||
$topics = [];
|
||||
foreach ($tours as $tour) {
|
||||
$title = $tour->label();
|
||||
$id = $tour->id();
|
||||
$routes = $tour->getRoutes();
|
||||
$made_link = FALSE;
|
||||
foreach ($routes as $route) {
|
||||
// Some tours are for routes with parameters. For instance, there is
|
||||
// currently a tour in the Language module for the language edit page,
|
||||
// which appears on all pages with URLs like:
|
||||
// /admin/config/regional/language/edit/LANGCODE.
|
||||
// There is no way to make a link to the page that displays the tour,
|
||||
// because it is a set of pages. The easiest way to detect this is to
|
||||
// use a try/catch exception -- try to make a link, and it will error
|
||||
// out with a missing parameter exception if the route leads to a set
|
||||
// of pages instead of a single page.
|
||||
try {
|
||||
$params = isset($route['route_params']) ? $route['route_params'] : [];
|
||||
$url = Url::fromRoute($route['route_name'], $params);
|
||||
// Skip this route if the current user cannot access it.
|
||||
if (!$url->access()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Generate the link HTML directly, using toString(), to catch
|
||||
// missing parameter exceptions now instead of at render time.
|
||||
$topics[$id] = Link::fromTextAndUrl($title, $url)->toString();
|
||||
// If the line above didn't generate an exception, we have a good
|
||||
// link that the user can access.
|
||||
$made_link = TRUE;
|
||||
break;
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// Exceptions are normally due to routes that need parameters. If
|
||||
// there is an exception, just try the next route and see if we can
|
||||
// find one that will work for us.
|
||||
}
|
||||
}
|
||||
if (!$made_link) {
|
||||
// None of the routes worked to make a link, so at least display the
|
||||
// tour title.
|
||||
$topics[$id] = $title;
|
||||
}
|
||||
}
|
||||
|
||||
return $topics;
|
||||
}
|
||||
|
||||
}
|
||||
122
web/core/modules/tour/src/Plugin/tour/tip/TipPluginText.php
Normal file
122
web/core/modules/tour/src/Plugin/tour/tip/TipPluginText.php
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\tour\Plugin\tour\tip;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\Core\Utility\Token;
|
||||
use Drupal\tour\TipPluginBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Displays some text as a tip.
|
||||
*
|
||||
* @Tip(
|
||||
* id = "text",
|
||||
* title = @Translation("Text")
|
||||
* )
|
||||
*/
|
||||
class TipPluginText extends TipPluginBase implements ContainerFactoryPluginInterface {
|
||||
|
||||
/**
|
||||
* The body text which is used for render of this Text Tip.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
/**
|
||||
* Token service.
|
||||
*
|
||||
* @var \Drupal\Core\Utility\Token
|
||||
*/
|
||||
protected $token;
|
||||
|
||||
/**
|
||||
* The forced position of where the tip will be located.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $location;
|
||||
|
||||
/**
|
||||
* Constructs a \Drupal\tour\Plugin\tour\tip\TipPluginText object.
|
||||
*
|
||||
* @param array $configuration
|
||||
* A configuration array containing information about the plugin instance.
|
||||
* @param string $plugin_id
|
||||
* The plugin_id for the plugin instance.
|
||||
* @param mixed $plugin_definition
|
||||
* The plugin implementation definition.
|
||||
* @param \Drupal\Core\Utility\Token $token
|
||||
* The token service.
|
||||
*/
|
||||
public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token) {
|
||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
|
||||
return new static($configuration, $plugin_id, $plugin_definition, $container->get('token'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ID that is guaranteed uniqueness.
|
||||
*
|
||||
* @return string
|
||||
* A unique id to be used to generate aria attributes.
|
||||
*/
|
||||
public function getAriaId() {
|
||||
static $id;
|
||||
if (!isset($id)) {
|
||||
$id = Html::getUniqueId($this->get('id'));
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns body of the text tip.
|
||||
*
|
||||
* @return string
|
||||
* The tip body.
|
||||
*/
|
||||
public function getBody() {
|
||||
return $this->get('body');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns location of the text tip.
|
||||
*
|
||||
* @return string
|
||||
* The tip location.
|
||||
*/
|
||||
public function getLocation() {
|
||||
return $this->get('location');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttributes() {
|
||||
$attributes = parent::getAttributes();
|
||||
$attributes['data-aria-describedby'] = 'tour-tip-' . $this->getAriaId() . '-contents';
|
||||
$attributes['data-aria-labelledby'] = 'tour-tip-' . $this->getAriaId() . '-label';
|
||||
if ($location = $this->get('location')) {
|
||||
$attributes['data-options'] = 'tipLocation:' . $location;
|
||||
}
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOutput() {
|
||||
$output = '<h2 class="tour-tip-label" id="tour-tip-' . $this->getAriaId() . '-label">' . Html::escape($this->getLabel()) . '</h2>';
|
||||
$output .= '<p class="tour-tip-body" id="tour-tip-' . $this->getAriaId() . '-contents">' . $this->token->replace($this->getBody()) . '</p>';
|
||||
return array('#markup' => $output);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue