Skip to content

Commit

Permalink
Drupal 10 compatibility (#436)
Browse files Browse the repository at this point in the history
* Bump Drupal version
  • Loading branch information
divya-intelli authored Jul 3, 2023
1 parent dcda03d commit 43f7c5f
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 31 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
drupal-core:
Expand All @@ -42,9 +41,19 @@ jobs:
instance-type:
- "Edge"
- "X"
#include:
# - php-version: "8.1"
# drupal-core: "10.0.x"
include:
- php-version: "8.1"
drupal-core: "10.0.x"
instance-type: "Edge"
- php-version: "8.1"
drupal-core: "10.0.x"
instance-type: "X"
- php-version: "8.1"
drupal-core: "10.1.x"
instance-type: "Edge"
- php-version: "8.1"
drupal-core: "10.1.x"
instance-type: "X"

steps:

Expand Down Expand Up @@ -99,8 +108,6 @@ jobs:
composer config --no-plugins allow-plugins.php-http/discovery true
composer config preferred-install."drupal/apigee_edge" source
composer config preferred-install."apigee/apigee-client-php" source
composer require drupal/rules:3.0.0-alpha7
composer require --dev drush/drush
composer config minimum-stability dev
composer require drupal/commerce:^2.16
composer require drupal/token:~1.0
Expand Down
4 changes: 2 additions & 2 deletions apigee_m10n.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ description: Apigee Edge Monetization Drupal integration
package: Apigee

type: module
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9 || ^10

dependencies:
- apigee_edge:apigee_edge
- drupal:link
- requirement:requirement

php: "7.1"
php: 8.0
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
"type": "drupal-module",
"description": "Apigee Edge Monetization for Drupal",
"require": {
"php": "^7.4 || ^8.0",
"php": "~8.0 || ~8.1",
"ext-bcmath": "*",
"cweagans/composer-patches": "~1.6",
"commerceguys/intl": "~1.0",
"drupal/apigee_edge": "^2.0.2",
"drupal/core": "^9.4",
"drupal/requirement": "~1.0",
"apigee/apigee-client-php": "^2.0.16"
"commerceguys/intl": "~1.0 || ^2.0",
"drupal/apigee_edge": "^2.0.2 || ^3.0.0",
"drupal/core": "^9.4 || ^10.0",
"drupal/requirement": "^1.2",
"drupal/jquery_ui_dialog": "^2.0",
"apigee/apigee-client-php": "^2.0.16 || ^3.0.0"
},
"require-dev": {
"apigee/apigee-mock-client-php": "^1.1.1",
"behat/mink-extension": "^2.0",
"bex/behat-screenshot": "^1.2",
"drupal/core-dev": "^9.4",
"drush/drush": "^9.0 || ^10.0",
"drupal/drupal-extension": "^4.2.1 || ~5",
"drupal/core-dev": "^9.4 || ^10.0",
"drush/drush": "^11.5",
"mglaman/drupal-check": "^1.3",
"phpmd/phpmd": "^2.8.2",
"phpmetrics/phpmetrics": "^2.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ content:
date_format: medium
custom_date_format: ''
timezone: ''
tooltip:
date_format: long
custom_date_format: ''
time_diff:
enabled: false
future_format: '@interval hence'
past_format: '@interval ago'
granularity: 2
refresh: 60
third_party_settings: { }
ratePlan:
type: entity_reference_label
Expand All @@ -42,6 +51,15 @@ content:
date_format: medium
custom_date_format: ''
timezone: ''
tooltip:
date_format: long
custom_date_format: ''
time_diff:
enabled: false
future_format: '@interval hence'
past_format: '@interval ago'
granularity: 2
refresh: 60
third_party_settings: { }
hidden:
created: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ content:
date_format: custom
custom_date_format: m/d/Y
timezone: ''
tooltip:
date_format: long
custom_date_format: ''
time_diff:
enabled: false
future_format: '@interval hence'
past_format: '@interval ago'
granularity: 2
refresh: 60
text: 'This plan has a new version effective @date. Toggle below to see the future rate plan.'
third_party_settings: { }
products:
Expand Down
58 changes: 58 additions & 0 deletions config/schema/apigee_m10n.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,35 @@ field.formatter.settings.apigee_datestamp:
timezone:
type: string
label: 'Timezone'
tooltip:
type: mapping
label: Tooltip
mapping:
date_format:
type: string
label: 'Tooltip date format'
custom_date_format:
type: string
label: 'Tooltip custom date format'
time_diff:
type: mapping
label: 'Time difference'
mapping:
enabled:
type: boolean
label: 'Show as time difference'
future_format:
type: string
label: 'Future format'
past_format:
type: string
label: 'Past format'
granularity:
type: integer
label: 'Time units'
refresh:
type: integer
label: 'Refresh interval in seconds'

field.formatter.settings.apigee_tnc_default:
type: mapping
Expand All @@ -112,6 +141,35 @@ field.formatter.settings.apigee_date_and_text_formatter:
timezone:
type: string
label: 'Timezone'
tooltip:
type: mapping
label: Tooltip
mapping:
date_format:
type: string
label: 'Tooltip date format'
custom_date_format:
type: string
label: 'Tooltip custom date format'
time_diff:
type: mapping
label: 'Time difference'
mapping:
enabled:
type: boolean
label: 'Show as time difference'
future_format:
type: string
label: 'Future format'
past_format:
type: string
label: 'Past format'
granularity:
type: integer
label: 'Time units'
refresh:
type: integer
label: 'Refresh interval in seconds'
text:
type: string
label: 'Text'
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Provides the ability to create a Drupal Commerce "Add Credit" produ
package: Apigee

type: module
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9 || ^10

dependencies:
- apigee_m10n:apigee_m10n
Expand All @@ -14,5 +14,6 @@ dependencies:
- commerce:commerce_order
- commerce:commerce_cart
- commerce:commerce_checkout
- jquery_ui_dialog:jquery_ui_dialog

php: "7.1"
php: 8.0
16 changes: 16 additions & 0 deletions modules/apigee_m10n_add_credit/apigee_m10n_add_credit.install
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,19 @@ function apigee_m10n_add_credit_install() {
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, AddCreditServiceInterface::DEFAULT_AUTHENTICATED_PERMISSIONS);
}
}

/**
* Install jquery_ui_dialog module if apigee_m10n_add_credit module is installed.
*/
function apigee_m10n_add_credit_update_9000(&$sandbox) {
// When upgrading, jquery_ui_dialog module is not enabled.
// Check if apigee_m10n_add_credit module is enabled.
if (Drupal::moduleHandler()->moduleExists('apigee_m10n_add_credit')) {
$installer = \Drupal::service('module_installer');
// Install jquery_ui_dialog module.
$installer->install(['jquery_ui_dialog']);
}

// Clear all caches.
drupal_flush_all_caches();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
attach: function attach(context) {
var self = this;
$(".two_decimal_price div input").keyup(function(){
var number = ($(this).val().split('.'));
if (number[1].length > 2)
var number = ($(this).val().split('.'));
// Check if there is value after decimal.
if (number[1] && number[1].length > 2)
{
var price = parseFloat($(this).val());
$(this).val(price.toFixed(2));
Expand Down
2 changes: 1 addition & 1 deletion modules/apigee_m10n_add_credit/src/AddCreditService.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function apigeeM10nPrepaidBalanceListAlter(array &$build, EntityInterface
$build['table']['#attached'] = [
'library' => [
'core/drupal.dialog.ajax',
'core/jquery.ui.dialog',
'jquery_ui_dialog/dialog',
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AddCreditFunctionalTestBase extends MonetizationFunctionalTestBase {
'commerce',
'user',
'field_ui',
'jquery_ui_dialog'
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class AddCreditFunctionalTestBase extends MonetizationFunctionalTestBase {
'commerce',
'user',
'field_ui',
'jquery_ui_dialog'
];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class AddCreditCustomAmountTest extends AddCreditFunctionalJavascriptTestBase {
*/
protected $developer;

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

/**
* {@inheritdoc}
*
Expand Down
4 changes: 2 additions & 2 deletions modules/apigee_m10n_teams/apigee_m10n_teams.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ description: Adds monetization support for Apigee Edge Teams.
package: Apigee (Experimental)

type: module
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9 || ^10

dependencies:
- apigee_m10n:apigee_m10n
- apigee_edge:apigee_edge_teams

php: "7.1"
php: 8.0
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,14 @@ protected function memberViewPurchasedRatePlans() {

$this->setRawContent($response->getContent());
static::assertSame(Response::HTTP_OK, $response->getStatusCode());

// Checking "Active and Future Purchased Plans" table columns.
// As div generated for startdate is different for Drupal 10.1
// hence need to check Drupal version and select the div.
$div_to_use = floatval(\Drupal::VERSION) <= 10.0 ? '.purchased-plan-row:nth-child(1) td.purchased-plan-start-date div' : '.purchased-plan-row:nth-child(1) td.purchased-plan-start-date div time';

$this->assertCssElementText('.purchased-plan-row:nth-child(1) td.purchased-plan-status span', 'Active');
$this->assertCssElementText('.purchased-plan-row:nth-child(1) td.purchased-plan-rate-plan a', $this->rate_plan->getDisplayName());
$this->assertCssElementText('.purchased-plan-row:nth-child(1) td.purchased-plan-start-date div', $this->purchased_plan->getStartDate()->format('m/d/Y'));
$this->assertCssElementText($div_to_use, $this->purchased_plan->getStartDate()->format('m/d/Y'));
$this->assertCssElementText('.purchased-plan-row:nth-child(1) td.purchased-plan-end-date', '');
}

Expand Down
3 changes: 2 additions & 1 deletion src/Plugin/Field/FieldFormatter/DateAndTextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
foreach ($items as $delta => $item) {
// Grab the formatted date from the TimestampFormatter and add it to the
// text.
// For Drupal 10.1, date is available in '#text'.
$elements[$delta] = [
'#markup' => t($text, [
'@date' => $elements[$delta]['#markup'],
'@date' => $elements[$delta]['#markup'] ?? $elements[$delta]['#text'],
]),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Routing/MonetizationRouteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function alterRoutes(RouteCollection $collection) {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
public static function getSubscribedEvents(): array {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = ['onAlterRoutes', -101];
return $events;
Expand Down
2 changes: 1 addition & 1 deletion tests/modules/apigee_m10n_test/apigee_m10n_test.info.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Apigee Monetization: Testing'
type: module
description: 'Support module for the Apigee Monetization tests.'
core_version_requirement: ^8.7.7 || ^9
core_version_requirement: ^9 || ^10
package: Testing

dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public function testView() {
'date_format' => $date_format,
'custom_date_format' => $custom_date_format,
'timezone' => '',
'tooltip' => [
'date_format' => $date_format,
'custom_date_format' => 'm/d/Y'
],
'time_diff' => [
'enabled' => FALSE,
'future_format' => '@interval hence',
'past_format' => '@interval ago',
'granularity' => 2,
'refresh' => 60,
]
],
'label' => TRUE,
'view_mode' => 'default',
Expand All @@ -127,7 +138,8 @@ public function testView() {

static::assertSame('Start Date', (string) $build['#title']);
static::assertTrue($build['#label_display']);
static::assertSame($expected, (string) $build[0]['#markup']);
// For Drupal 10.1, date is available in '#text'.
static::assertSame($expected, (string) ($build[0]['#markup'] ?? $build[0]['#text']));
}

}

0 comments on commit 43f7c5f

Please sign in to comment.