Skip to content
Snippets Groups Projects
Commit 3f56f11c authored by Stefan Auditor's avatar Stefan Auditor
Browse files

Issue #3399342 by sanduhrs: Add gitlab ci template

parent e577b77d
No related branches found
No related tags found
1 merge request!16Issue #3399342 by sanduhrs: Add gitlab ci template
Pipeline #44625 passed
################
# DrupalCI GitLabCI template
#
# Gitlab-ci.yml to replicate DrupalCI testing for Contrib
#
# With thanks to:
# * The GitLab Acceleration Initiative participants
# * DrupalSpoons
################
################
# Guidelines
#
# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification. It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
#
# However, you can modify this template if you have additional needs for your project.
################
################
# Includes
#
# Additional configuration can be provided through includes.
# One advantage of include files is that if they are updated upstream, the changes affect all pipelines using that include.
#
# Includes can be overridden by re-declaring anything provided in an include, here in gitlab-ci.yml
# https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-values
################
include:
################
# DrupalCI includes:
# As long as you include this, any future includes added by the Drupal Association will be accessible to your pipelines automatically.
# View these include files at https://git.drupalcode.org/project/gitlab_templates/
################
- project: $_GITLAB_TEMPLATES_REPO
ref: $_GITLAB_TEMPLATES_REF
file:
- '/includes/include.drupalci.main.yml'
# EXPERIMENTAL: For Drupal 7, remove the above line and uncomment the below.
# - '/includes/include.drupalci.main-d7.yml'
- '/includes/include.drupalci.variables.yml'
- '/includes/include.drupalci.workflows.yml'
################
# Pipeline configuration variables
#
# These are the variables provided to the Run Pipeline form that a user may want to override.
#
# Docs at https://git.drupalcode.org/project/gitlab_templates/-/blob/1.0.x/includes/include.drupalci.variables.yml
################
# variables:
# SKIP_ESLINT: '1'
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
#
###################################################################################
......@@ -2,9 +2,9 @@
namespace Drupal\glossify_node\Plugin\Filter;
use Drupal\glossify\GlossifyBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\filter\FilterProcessResult;
use Drupal\glossify\GlossifyBase;
use Drupal\node\Entity\NodeType;
/**
......@@ -25,7 +25,7 @@ use Drupal\node\Entity\NodeType;
* weight = -10
* )
*/
class NodeTooltip extends GlossifyBase {
final class NodeTooltip extends GlossifyBase {
/**
* {@inheritdoc}
......@@ -138,7 +138,7 @@ class NodeTooltip extends GlossifyBase {
$terms = [];
// Get node data.
$query = \Drupal::database()->select('node_field_data', 'nfd');
$query = $this->database->select('node_field_data', 'nfd');
$query->addfield('nfd', 'nid', 'id');
$query->addfield('nfd', 'title', 'name');
$query->addfield('nfd', 'title', 'name_norm');
......
......@@ -6,12 +6,11 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Render;
/**
* Implements hook_help().
*/
function glossify_taxonomies_help($route_name, RouteMatchInterface $route_match) {
function glossify_taxonomy_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.glossify_taxonomies':
......
......@@ -2,9 +2,9 @@
namespace Drupal\glossify_taxonomy\Plugin\Filter;
use Drupal\glossify\GlossifyBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\filter\FilterProcessResult;
use Drupal\glossify\GlossifyBase;
use Drupal\taxonomy\Entity\Vocabulary;
/**
......@@ -25,7 +25,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
* weight = -10
* )
*/
class TaxonomyTooltip extends GlossifyBase {
final class TaxonomyTooltip extends GlossifyBase {
/**
* {@inheritdoc}
......@@ -134,13 +134,13 @@ class TaxonomyTooltip extends GlossifyBase {
$vocabs = explode(';', $this->settings['glossify_taxonomy_vocabs']);
// Let other modules override $vocabs.
\Drupal::moduleHandler()->alter('glossify_taxonomy_vocabs', $vocabs);
$this->moduleHandler->alter('glossify_taxonomy_vocabs', $vocabs);
if (count($vocabs)) {
$terms = [];
// Get taxonomy term data.
$query = \Drupal::database()->select('taxonomy_term_field_data', 'tfd');
$query = $this->database->select('taxonomy_term_field_data', 'tfd');
$query->addfield('tfd', 'tid', 'id');
$query->addfield('tfd', 'name');
$query->addfield('tfd', 'name', 'name_norm');
......
......@@ -2,16 +2,113 @@
namespace Drupal\glossify;
use Drupal\filter\Plugin\FilterBase;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Render\Renderer;
use Drupal\Core\Url;
use Drupal\filter\Plugin\FilterBase;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Base implementation of tooltip filter type plugin.
*/
abstract class GlossifyBase extends FilterBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected Connection $database;
/**
* The render service.
*
* @var \Drupal\Core\Render\Renderer
*/
protected Renderer $renderer;
/**
* The current path service.
*
* @var \Drupal\Core\Path\CurrentPathStack
*/
protected CurrentPathStack $currentPath;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected ModuleHandlerInterface $moduleHandler;
/**
* The logger service.
*
* @var \Psr\Log\LoggerInterface
*/
protected LoggerInterface $logger;
// phpcs:disable
/**
* The class constructor.
*
* @param array $configuration
* The plugin configuration array.
* @param $plugin_id
* The plugin id.
* @param $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Database\Connection $database
* The databse service.
* @param \Drupal\Core\Render\Renderer $renderer
* The render service.
* @param \Drupal\Core\Path\CurrentPathStack $current_path
* The current path service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
* @param \Psr\Log\LoggerInterface $logger
* The logger service.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
Connection $database,
Renderer $renderer,
CurrentPathStack $current_path,
ModuleHandlerInterface $module_handler,
LoggerInterface $logger
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->database = $database;
$this->renderer = $renderer;
$this->currentPath = $current_path;
$this->moduleHandler = $module_handler;
$this->logger = $logger;
}
// phpcs:enable
/**
* {@inheritdoc}
*/
public static function createInstance(
ContainerInterface $container
) {
// @phpstan-ignore-next-line
return new static(
$container->get('database'),
$container->get('renderer'),
$container->get('path.current'),
$container->get('module_handler'),
$container->get('logger.factory')->get('glossify')
);
}
/**
* Convert terms in text to links.
*
......@@ -43,10 +140,9 @@ abstract class GlossifyBase extends FilterBase {
*/
protected function parseTooltipMatch($text, array $terms, $case_sensitivity, $first_only, $displaytype, $tooltip_truncate, $urlpattern, $langcode) {
if (!Unicode::validateUtf8($text)) {
\Drupal::logger('glossify')
->debug($this->t('The text is apparently is not a valid utf8 charset: @text', [
'@text' => $text,
]));
$this->logger->debug($this->t('The text is apparently is not a valid utf8 charset: @text', [
'@text' => $text,
]));
return $text;
}
......@@ -156,6 +252,7 @@ abstract class GlossifyBase extends FilterBase {
$tip = $this->sanitizeTip((string) $term->tip, $tooltip_truncate);
$tip_raw = $this->sanitizeRawTip((string) $term->tip, $tooltip_truncate);
}
// @phpstan-ignore-next-line
if (\Drupal::hasContainer()) {
$tipurl = Url::fromUri('internal:' . str_replace('[id]', $term->id, $urlpattern));
}
......@@ -208,21 +305,21 @@ abstract class GlossifyBase extends FilterBase {
* Render tip for found match.
*/
protected function renderTip($word_tip) {
return trim(\Drupal::service('renderer')->render($word_tip));
return trim($this->renderer->render($word_tip));
}
/**
* Render link for found match.
*/
protected function renderLink($word_link) {
return trim(\Drupal::service('renderer')->render($word_link));
return trim($this->renderer->render($word_link));
}
/**
* Get current path.
*/
protected function currentPath() {
return \Drupal::service('path.current')->getPath();
return $this->currentPath->getPath();
}
/**
......@@ -264,6 +361,7 @@ abstract class GlossifyBase extends FilterBase {
private function sanitizeRawTip($tip, $truncate = TRUE) {
// Maximise tooltip text length.
if ($truncate) {
// phpcs:ignore
// @todo: How to properly truncate the tip if it contains HTML?
// @see https://www.drupal.org/project/drupal/issues/2279655
$tip = Unicode::truncate($tip, 300, TRUE, TRUE);
......
......@@ -2,9 +2,9 @@
namespace Drupal\Tests\glossify\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\glossify\GlossifyBase;
use Drupal\Component\Utility\Unicode;
use Drupal\glossify\GlossifyBase;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\glossify\GlossifyBase
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment