diff --git a/.travis.yml b/.travis.yml index ca8b51b6a632c9b005eb9b8bc0a76ee2b440b81e..4c275908a898b883193890650fec88f5c0414072 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: @@ -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" @@ -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 @@ -106,7 +112,8 @@ 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: @@ -114,8 +121,6 @@ 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 diff --git a/DEVELOPPING.md b/DEVELOPPING.md index ad4d43305a204b954e01d09bb3e638840429d978..7202f9743d3d79076f01b148ad0a50e3adcbb98a 100644 --- a/DEVELOPPING.md +++ b/DEVELOPPING.md @@ -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 diff --git a/README.md b/README.md index d6410aab2c6707cce0002017ddc61f25b1c97e0e..4ac09c5084c01f63cf41e85912fb80c05b36956a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Controller/AdminSuggestionController.php b/src/Controller/AdminSuggestionController.php index c02ebb6103ab1740d3fa7f8059d4bdc47d54c6ff..8693e4f0809970a01f211e99c79dad643259c92f 100644 --- a/src/Controller/AdminSuggestionController.php +++ b/src/Controller/AdminSuggestionController.php @@ -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; @@ -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; } /** @@ -50,10 +59,11 @@ class AdminSuggestionController extends ControllerBase { 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') ); } @@ -84,8 +94,8 @@ class AdminSuggestionController extends ControllerBase { $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', @@ -105,7 +115,7 @@ class AdminSuggestionController extends ControllerBase { // 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>']; } } diff --git a/src/Entity/TemplateWhispererSuggestionEntity.php b/src/Entity/TemplateWhispererSuggestionEntity.php index 3ac62d5f5ba0e5d13f1092ae2a73b3cfc721e5a6..cbf3e0ffd6a619c89484213a9afc83b562f3997c 100644 --- a/src/Entity/TemplateWhispererSuggestionEntity.php +++ b/src/Entity/TemplateWhispererSuggestionEntity.php @@ -34,6 +34,11 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; * "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 { diff --git a/src/Plugin/Condition/TemplateWhisperer.php b/src/Plugin/Condition/TemplateWhisperer.php index 29b43c541e2c9960bf30f671f8cffaa5b27d354c..b528a7f5f36b63f667a00a49c1d88b699d3a6e9f 100644 --- a/src/Plugin/Condition/TemplateWhisperer.php +++ b/src/Plugin/Condition/TemplateWhisperer.php @@ -15,7 +15,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @Condition( * id = "template_whisperer", * label = @Translation("Template Whisperer"), - * context = { + * context_definitions = { * "node" = @ContextDefinition("entity:node", label = @Translation("Node")) * } * ) diff --git a/src/TemplateWhispererSuggestionListBuilder.php b/src/TemplateWhispererSuggestionListBuilder.php index e92920d62b92052e3f890230d75219a4ad481250..ccfbf22e182190500f90bba5a605d3d6bd22bd16 100644 --- a/src/TemplateWhispererSuggestionListBuilder.php +++ b/src/TemplateWhispererSuggestionListBuilder.php @@ -8,6 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; 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. @@ -54,7 +55,7 @@ class TemplateWhispererSuggestionListBuilder extends ConfigEntityListBuilder { 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') ); diff --git a/template_whisperer.info.yml b/template_whisperer.info.yml index 0ba9b41a0f418d3e75cb32b332df8128233b9cd0..1b539886193b829ec9db136dbbe0d98b5bd0bff8 100644 --- a/template_whisperer.info.yml +++ b/template_whisperer.info.yml @@ -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: diff --git a/tests/src/Functional/TemplateWhispererTestBase.php b/tests/src/Functional/TemplateWhispererTestBase.php index 1ac74f11e5a82631cf50a8cc226e8db4d748f9ae..44d93a7a6a47490a7d4b43258239eb1736d6e47b 100644 --- a/tests/src/Functional/TemplateWhispererTestBase.php +++ b/tests/src/Functional/TemplateWhispererTestBase.php @@ -9,6 +9,11 @@ use Drupal\Tests\BrowserTestBase; */ abstract class TemplateWhispererTestBase extends BrowserTestBase { + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'classy'; + /** * Enables Twig debugging. */ diff --git a/tests/src/Functional/UiFieldTest.php b/tests/src/Functional/UiFieldTest.php index 8c0ec94649690154571f99f7b2cdfb915e11c96d..7a9230cd2763d2692e704dfd906b931f383a468e 100644 --- a/tests/src/Functional/UiFieldTest.php +++ b/tests/src/Functional/UiFieldTest.php @@ -12,6 +12,11 @@ namespace Drupal\Tests\template_whisperer\Functional; */ class UiFieldTest extends TemplateWhispererTestBase { + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + /** * {@inheritdoc} */ diff --git a/tests/src/Functional/UiPageTest.php b/tests/src/Functional/UiPageTest.php index d30d185a964a11bddb485b6be1d94e642a4ca54e..d473af72e8debcac1efd7192b3c970dedcb3fe56 100644 --- a/tests/src/Functional/UiPageTest.php +++ b/tests/src/Functional/UiPageTest.php @@ -12,6 +12,11 @@ namespace Drupal\Tests\template_whisperer\Functional; */ class UiPageTest extends TemplateWhispererTestBase { + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; + /** * {@inheritdoc} */ diff --git a/tests/src/Functional/WidgetFormElementTest.php b/tests/src/Functional/WidgetFormElementTest.php index 73d5c44e90cb33b0752822ca948c01a077ba4a38..0f67ae1286355a48c11cbad96ab46e934478156e 100644 --- a/tests/src/Functional/WidgetFormElementTest.php +++ b/tests/src/Functional/WidgetFormElementTest.php @@ -2,6 +2,8 @@ namespace Drupal\Tests\template_whisperer\Functional; +use Drupal\Core\Entity\Entity\EntityFormDisplay; + /** * @coversDefaultClass \Drupal\template_whisperer\Plugin\Field\FieldWidget\TemplateWhispererWidget * @@ -90,11 +92,10 @@ class WidgetFormElementTest extends TemplateWhispererTestBase { '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', @@ -127,11 +128,15 @@ class WidgetFormElementTest extends TemplateWhispererTestBase { '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',