Skip to content

Commit

Permalink
Issue #3090756 by wengerk: Drupal 9 Readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK authored Mar 27, 2020
2 parents 2e0f864 + 7c05b1c commit 6b24c29
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 36 deletions.
27 changes: 16 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ language: php
sudo: false

php:
- 7
- 7.1
- 7.2
- 7.3

services:
- mysql

matrix:
fast_finish: true
allow_failures:
- php: hhvm
include:
- name: D8.8
env: DRUPAL_TI_RUNNERS="phpunit-core" DRUPAL_TI_CORE_BRANCH="8.8.x" DRUPAL_TI_PHPUNIT_ARGS="--group template_whisperer"
- name: D8.9
env: DRUPAL_TI_RUNNERS="phpunit-core" DRUPAL_TI_CORE_BRANCH="8.9.x" DRUPAL_TI_PHPUNIT_ARGS="--group template_whisperer"
- name: D9.0
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"

env:
global:
Expand All @@ -39,8 +41,11 @@ env:
# The environment to use, supported are: drupal-7, drupal-8
- DRUPAL_TI_ENVIRONMENT="drupal-8"

# Switch to 8.6.x versions instead of 8.1.x by default.
- DRUPAL_TI_CORE_BRANCH="8.6.x"
# The drush version to use, by default: drush/drush:8.0.*
- DRUPAL_TI_DRUSH_VERSION="drush/drush:^10.1.1"

# Switch to 8.9.x versions instead of 8.1.x by default.
- DRUPAL_TI_CORE_BRANCH="8.9.x"

# The installation profile to use:
#- DRUPAL_TI_INSTALL_PROFILE="testing"
Expand Down Expand Up @@ -71,6 +76,7 @@ env:
- DRUPAL_TI_BEHAT_BROWSER="firefox"

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

install:
- drupal-ti install

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

script:
# Disable deprecations helper to avoid build failed caused by usage of
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Github repo

```bash
git remote add github \
https://github.com/antistatique/drupal-template-whisperer.git
git@github.com:antistatique/drupal-bamboo-twig.git
```

## 🔧 Prerequisites
Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,23 @@ but those are some of the obvious uses of Template Whisperer.

## Template Whisperer versions

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

This version should work with all Drupal 8 releases, and it is always
recommended to keep Drupal core installations up to date.
- If you are running Drupal `8.7.x`, use Template Whisperer `2.x`.
- If you are running Drupal `8.8.x`, use Bamboo Twig `3.x`.

The version `8.x-3.x` is not compatible with Drupal `8.7.x`.
Drupal `8.8.x` brings some breaking change with tests and so you
must upgrade to `8.x-3.x` version of **Bamboo Twig**.

## Which version should I use?

|Drupal Core|Bamboo Twig|
|:---------:|:---------:|
|8.0.x |1.x |
|8.4.x |2.x |
|8.8.x |3.x |
|9.x |3.x |

## Dependencies

Expand Down
24 changes: 17 additions & 7 deletions src/Controller/AdminSuggestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\template_whisperer\Controller;

use Drupal\Core\Pager\PagerManagerInterface;
use Drupal\template_whisperer\Entity\TemplateWhispererSuggestionEntityInterface;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -35,13 +36,21 @@ class AdminSuggestionController extends ControllerBase {
*/
protected $urlGenerator;

/**
* The pager manager.
*
* @var \Drupal\Core\Pager\PagerManagerInterface
*/
protected $pagerManager;

/**
* Class constructor.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, TemplateWhispererSuggestionUsage $tw_suggestion_usage, UrlGeneratorInterface $url_generator) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, TemplateWhispererSuggestionUsage $tw_suggestion_usage, UrlGeneratorInterface $url_generator, PagerManagerInterface $pager_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->twSuggestionUsage = $tw_suggestion_usage;
$this->urlGenerator = $url_generator;
$this->pagerManager = $pager_manager;
}

/**
Expand All @@ -50,10 +59,11 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Tem
public static function create(ContainerInterface $container) {
// Instantiates this form class.
return new static(
// Load the service required to construct this class.
$container->get('entity_type.manager'),
$container->get('template_whisperer.suggestion.usage'),
$container->get('url_generator')
// Load the service required to construct this class.
$container->get('entity_type.manager'),
$container->get('template_whisperer.suggestion.usage'),
$container->get('url_generator'),
$container->get('pager.manager')
);
}

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

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

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

Expand Down
5 changes: 5 additions & 0 deletions src/Entity/TemplateWhispererSuggestionEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
* "collection" = "/admin/structure/template-whisperer",
* "usage" = "/admin/structure/template-whisperer/{template_whisperer_suggestion}/usage",
* },
* config_export = {
* "id",
* "name",
* "suggestion",
* }
* )
*/
class TemplateWhispererSuggestionEntity extends ConfigEntityBase implements TemplateWhispererSuggestionEntityInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/Condition/TemplateWhisperer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @Condition(
* id = "template_whisperer",
* label = @Translation("Template Whisperer"),
* context = {
* context_definitions = {
* "node" = @ContextDefinition("entity:node", label = @Translation("Node"))
* }
* )
Expand Down
3 changes: 2 additions & 1 deletion src/TemplateWhispererSuggestionListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;

/**
* Defines a class to build a listing of templates whisperer entities.
Expand Down Expand Up @@ -54,7 +55,7 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('url_generator'),
$container->get('template_whisperer.suggestion.usage')
);
Expand Down
2 changes: 1 addition & 1 deletion template_whisperer.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Template Whisperer
type: module
description: Provides a formalized way to declare and suggest page templates.
core: 8.x
core_version_requirement: ^8.8 || ^9
package: Fields types

dependencies:
Expand Down
5 changes: 5 additions & 0 deletions tests/src/Functional/TemplateWhispererTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/
abstract class TemplateWhispererTestBase extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'classy';

/**
* Enables Twig debugging.
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/src/Functional/UiFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
class UiFieldTest extends TemplateWhispererTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/src/Functional/UiPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
class UiPageTest extends TemplateWhispererTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
Expand Down
25 changes: 15 additions & 10 deletions tests/src/Functional/WidgetFormElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Drupal\Tests\template_whisperer\Functional;

use Drupal\Core\Entity\Entity\EntityFormDisplay;

/**
* @coversDefaultClass \Drupal\template_whisperer\Plugin\Field\FieldWidget\TemplateWhispererWidget
*
Expand Down Expand Up @@ -90,11 +92,10 @@ protected function setupArticle() {
'bundle' => 'article',
])->save();

entity_get_form_display('node', 'article', 'default')
->setComponent('field_template_whisperer_1', [
'type' => 'template_whisperer',
'weight' => 20,
])->save();
EntityFormDisplay::load('node.article.default')->setComponent('field_template_whisperer_1', [
'type' => 'template_whisperer',
'weight' => 20,
])->save();

$this->article = $em->getStorage('node')->create([
'type' => 'article',
Expand Down Expand Up @@ -127,11 +128,15 @@ protected function setupTag() {
'bundle' => 'tags',
])->save();

entity_get_form_display('taxonomy_term', 'tags', 'default')
->setComponent('field_template_whisperer_2', [
'type' => 'template_whisperer',
'weight' => 20,
])->save();
EntityFormDisplay::create([
'targetEntityType' => 'taxonomy_term',
'bundle' => 'tags',
'mode' => 'default',
'status' => TRUE,
])->setComponent('field_template_whisperer_2', [
'type' => 'template_whisperer',
'weight' => 20,
])->save();

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

0 comments on commit 6b24c29

Please sign in to comment.