Skip to content

Commit add7bb5

Browse files
committed
update code to be compliant with drupal 8.8 & drupal 9
1 parent a3cbff0 commit add7bb5

9 files changed

+56
-20
lines changed

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)