Skip to content

Commit 6b24c29

Browse files
authored
Issue #3090756 by wengerk: Drupal 9 Readiness
2 parents 2e0f864 + 7c05b1c commit 6b24c29

12 files changed

+89
-36
lines changed

.travis.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@ language: php
88
sudo: false
99

1010
php:
11-
- 7
12-
- 7.1
13-
- 7.2
11+
- 7.3
1412

1513
services:
1614
- mysql
1715

1816
matrix:
19-
fast_finish: true
20-
allow_failures:
21-
- php: hhvm
17+
include:
18+
- name: D8.8
19+
env: DRUPAL_TI_RUNNERS="phpunit-core" DRUPAL_TI_CORE_BRANCH="8.8.x" DRUPAL_TI_PHPUNIT_ARGS="--group template_whisperer"
20+
- name: D8.9
21+
env: DRUPAL_TI_RUNNERS="phpunit-core" DRUPAL_TI_CORE_BRANCH="8.9.x" DRUPAL_TI_PHPUNIT_ARGS="--group template_whisperer"
22+
- name: D9.0
23+
env: DRUPAL_TI_RUNNERS="phpunit-core" DRUPAL_TI_ENVIRONMENT="drupal-9" DRUPAL_TI_CORE_BRANCH="9.0.x" DRUPAL_TI_PHPUNIT_ARGS="--group template_whisperer"
2224

2325
env:
2426
global:
@@ -39,8 +41,11 @@ env:
3941
# The environment to use, supported are: drupal-7, drupal-8
4042
- DRUPAL_TI_ENVIRONMENT="drupal-8"
4143

42-
# Switch to 8.6.x versions instead of 8.1.x by default.
43-
- DRUPAL_TI_CORE_BRANCH="8.6.x"
44+
# The drush version to use, by default: drush/drush:8.0.*
45+
- DRUPAL_TI_DRUSH_VERSION="drush/drush:^10.1.1"
46+
47+
# Switch to 8.9.x versions instead of 8.1.x by default.
48+
- DRUPAL_TI_CORE_BRANCH="8.9.x"
4449

4550
# The installation profile to use:
4651
#- DRUPAL_TI_INSTALL_PROFILE="testing"
@@ -71,6 +76,7 @@ env:
7176
- DRUPAL_TI_BEHAT_BROWSER="firefox"
7277

7378
# PHPUnit specific commandline arguments.
79+
- DRUPAL_TI_PHPUNIT_VERSION="^7.0"
7480
- DRUPAL_TI_PHPUNIT_ARGS=""
7581
# Specifying the phpunit-core src/ directory is useful when e.g. a vendor/
7682
# directory is present in the module directory, which phpunit would then
@@ -106,16 +112,15 @@ mysql:
106112
before_install:
107113
- composer self-update
108114
- cd ./tests
109-
- composer global require "lionsad/drupal_ti:1.*"
115+
- composer global config repositories.repo-name git https://github.com/wengerk/drupal_ti
116+
- composer global require "lionsad/drupal_ti:dev-add-drupal-9-support"
110117
- drupal-ti before_install
111118

112119
install:
113120
- drupal-ti install
114121

115122
before_script:
116123
- drupal-ti before_script
117-
# Update from PHPUnit 4.x to 6.x as required by Drupal 8.6.x.
118-
- composer run-script drupal-phpunit-upgrade --working-dir=/home/travis/build/antistatique/drupal-8/drupal --no-interaction
119124

120125
script:
121126
# Disable deprecations helper to avoid build failed caused by usage of

DEVELOPPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Github repo
1818

1919
```bash
2020
git remote add github \
21-
https://github.com/antistatique/drupal-template-whisperer.git
21+
git@github.com:antistatique/drupal-bamboo-twig.git
2222
```
2323

2424
## 🔧 Prerequisites

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,23 @@ but those are some of the obvious uses of Template Whisperer.
6868

6969
## Template Whisperer versions
7070

71-
Template Whisperer is only available for Drupal 8 !
72-
The module is ready to be used in Drupal 8, there are no known issues.
71+
Template Whisperer is available for Drupal 8 and Drupal 9!
7372

74-
This version should work with all Drupal 8 releases, and it is always
75-
recommended to keep Drupal core installations up to date.
73+
- If you are running Drupal `8.7.x`, use Template Whisperer `2.x`.
74+
- If you are running Drupal `8.8.x`, use Bamboo Twig `3.x`.
75+
76+
The version `8.x-3.x` is not compatible with Drupal `8.7.x`.
77+
Drupal `8.8.x` brings some breaking change with tests and so you
78+
must upgrade to `8.x-3.x` version of **Bamboo Twig**.
79+
80+
## Which version should I use?
81+
82+
|Drupal Core|Bamboo Twig|
83+
|:---------:|:---------:|
84+
|8.0.x |1.x |
85+
|8.4.x |2.x |
86+
|8.8.x |3.x |
87+
|9.x |3.x |
7688

7789
## Dependencies
7890

src/Controller/AdminSuggestionController.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Drupal\template_whisperer\Controller;
44

5+
use Drupal\Core\Pager\PagerManagerInterface;
56
use Drupal\template_whisperer\Entity\TemplateWhispererSuggestionEntityInterface;
67
use Drupal\Core\Controller\ControllerBase;
78
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -35,13 +36,21 @@ class AdminSuggestionController extends ControllerBase {
3536
*/
3637
protected $urlGenerator;
3738

39+
/**
40+
* The pager manager.
41+
*
42+
* @var \Drupal\Core\Pager\PagerManagerInterface
43+
*/
44+
protected $pagerManager;
45+
3846
/**
3947
* Class constructor.
4048
*/
41-
public function __construct(EntityTypeManagerInterface $entity_type_manager, TemplateWhispererSuggestionUsage $tw_suggestion_usage, UrlGeneratorInterface $url_generator) {
49+
public function __construct(EntityTypeManagerInterface $entity_type_manager, TemplateWhispererSuggestionUsage $tw_suggestion_usage, UrlGeneratorInterface $url_generator, PagerManagerInterface $pager_manager) {
4250
$this->entityTypeManager = $entity_type_manager;
4351
$this->twSuggestionUsage = $tw_suggestion_usage;
4452
$this->urlGenerator = $url_generator;
53+
$this->pagerManager = $pager_manager;
4554
}
4655

4756
/**
@@ -50,10 +59,11 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Tem
5059
public static function create(ContainerInterface $container) {
5160
// Instantiates this form class.
5261
return new static(
53-
// Load the service required to construct this class.
54-
$container->get('entity_type.manager'),
55-
$container->get('template_whisperer.suggestion.usage'),
56-
$container->get('url_generator')
62+
// Load the service required to construct this class.
63+
$container->get('entity_type.manager'),
64+
$container->get('template_whisperer.suggestion.usage'),
65+
$container->get('url_generator'),
66+
$container->get('pager.manager')
5767
);
5868
}
5969

@@ -84,8 +94,8 @@ public function usage(TemplateWhispererSuggestionEntityInterface $template_whisp
8494
$usages = $this->twSuggestionUsage->listUsage($template_whisperer_suggestion);
8595
$count = $this->twSuggestionUsage->countUsage($template_whisperer_suggestion);
8696

97+
$this->pagerManager->createPager($count, 30);
8798
// Pager.
88-
pager_default_initialize($count, 30);
8999
$output[] = [
90100
'#type' => 'pager',
91101
'#quantity' => '3',
@@ -105,7 +115,7 @@ public function usage(TemplateWhispererSuggestionEntityInterface $template_whisp
105115

106116
// Build the table empty state.
107117
if (!empty($entity)) {
108-
$output['table'][$i]['entity'] = ['#markup' => '<a target="_blank" href="' . $entity->url() . '">' . $entity->getTitle() . '</a>'];
118+
$output['table'][$i]['entity'] = ['#markup' => '<a target="_blank" href="' . $entity->toUrl()->toString() . '">' . $entity->getTitle() . '</a>'];
109119
}
110120
}
111121

src/Entity/TemplateWhispererSuggestionEntity.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
* "collection" = "/admin/structure/template-whisperer",
3535
* "usage" = "/admin/structure/template-whisperer/{template_whisperer_suggestion}/usage",
3636
* },
37+
* config_export = {
38+
* "id",
39+
* "name",
40+
* "suggestion",
41+
* }
3742
* )
3843
*/
3944
class TemplateWhispererSuggestionEntity extends ConfigEntityBase implements TemplateWhispererSuggestionEntityInterface {

src/Plugin/Condition/TemplateWhisperer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @Condition(
1616
* id = "template_whisperer",
1717
* label = @Translation("Template Whisperer"),
18-
* context = {
18+
* context_definitions = {
1919
* "node" = @ContextDefinition("entity:node", label = @Translation("Node"))
2020
* }
2121
* )

src/TemplateWhispererSuggestionListBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Drupal\Core\Entity\EntityStorageInterface;
99
use Drupal\Core\Routing\UrlGeneratorInterface;
1010
use Drupal\Core\Entity\EntityInterface;
11+
use Drupal\Core\Entity\EntityTypeManagerInterface;
1112

1213
/**
1314
* Defines a class to build a listing of templates whisperer entities.
@@ -54,7 +55,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter
5455
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
5556
return new static(
5657
$entity_type,
57-
$container->get('entity.manager')->getStorage($entity_type->id()),
58+
$container->get('entity_type.manager')->getStorage($entity_type->id()),
5859
$container->get('url_generator'),
5960
$container->get('template_whisperer.suggestion.usage')
6061
);

template_whisperer.info.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Template Whisperer
22
type: module
33
description: Provides a formalized way to declare and suggest page templates.
4-
core: 8.x
4+
core_version_requirement: ^8.8 || ^9
55
package: Fields types
66

77
dependencies:

tests/src/Functional/TemplateWhispererTestBase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
*/
1010
abstract class TemplateWhispererTestBase extends BrowserTestBase {
1111

12+
/**
13+
* {@inheritdoc}
14+
*/
15+
protected $defaultTheme = 'classy';
16+
1217
/**
1318
* Enables Twig debugging.
1419
*/

tests/src/Functional/UiFieldTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*/
1313
class UiFieldTest extends TemplateWhispererTestBase {
1414

15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected $defaultTheme = 'stark';
19+
1520
/**
1621
* {@inheritdoc}
1722
*/

tests/src/Functional/UiPageTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*/
1313
class UiPageTest extends TemplateWhispererTestBase {
1414

15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected $defaultTheme = 'stark';
19+
1520
/**
1621
* {@inheritdoc}
1722
*/

tests/src/Functional/WidgetFormElementTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Drupal\Tests\template_whisperer\Functional;
44

5+
use Drupal\Core\Entity\Entity\EntityFormDisplay;
6+
57
/**
68
* @coversDefaultClass \Drupal\template_whisperer\Plugin\Field\FieldWidget\TemplateWhispererWidget
79
*
@@ -90,11 +92,10 @@ protected function setupArticle() {
9092
'bundle' => 'article',
9193
])->save();
9294

93-
entity_get_form_display('node', 'article', 'default')
94-
->setComponent('field_template_whisperer_1', [
95-
'type' => 'template_whisperer',
96-
'weight' => 20,
97-
])->save();
95+
EntityFormDisplay::load('node.article.default')->setComponent('field_template_whisperer_1', [
96+
'type' => 'template_whisperer',
97+
'weight' => 20,
98+
])->save();
9899

99100
$this->article = $em->getStorage('node')->create([
100101
'type' => 'article',
@@ -127,11 +128,15 @@ protected function setupTag() {
127128
'bundle' => 'tags',
128129
])->save();
129130

130-
entity_get_form_display('taxonomy_term', 'tags', 'default')
131-
->setComponent('field_template_whisperer_2', [
132-
'type' => 'template_whisperer',
133-
'weight' => 20,
134-
])->save();
131+
EntityFormDisplay::create([
132+
'targetEntityType' => 'taxonomy_term',
133+
'bundle' => 'tags',
134+
'mode' => 'default',
135+
'status' => TRUE,
136+
])->setComponent('field_template_whisperer_2', [
137+
'type' => 'template_whisperer',
138+
'weight' => 20,
139+
])->save();
135140

136141
$this->tag = $em->getStorage('taxonomy_term')->create([
137142
'name' => 'Tags N°1',

0 commit comments

Comments
 (0)