Skip to content

Commit

Permalink
[#393] Drupal 9 deprecations fixes (#397)
Browse files Browse the repository at this point in the history
* [#393] Drupal 9 deprecations fixes.

* [#393] Drupal 9 deprecations fixes.

* [#393] D9 composer and .info fixes.

* [#393] Drupal 9 readiness: remove some changes.

* [#393] Drupal 9 readiness: fix entity singular/plural label and getLowercaseLabel().

* [#393] Drupal 9 readiness: fix entity singular/plural label and getLowercaseLabel().

* [#393] Drupal 9 readiness: fix tests.

* [#393] Drupal 9 readiness: avoid breaking BC.

* [#393] Drupal 9 readiness: more fixes.

* [#393] Drupal 9 readiness: apigee_edge_actions submodules are D8 only - no rules for D9 yet.

* [#393] Drupal 9 readiness: fixing tests.

* [#393] Drupal 9 readiness: use mb_* functions where there is user input.

* [#393] Drupal 9 readiness: use lowercase entity labels in plugin definitions.

* [#393] code sniffer fixes.
  • Loading branch information
arlina-espinoza authored May 12, 2020
1 parent a80f355 commit 73f1f3b
Show file tree
Hide file tree
Showing 74 changed files with 265 additions and 174 deletions.
2 changes: 1 addition & 1 deletion apigee_edge.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Apigee Edge Drupal integration.
package: Apigee

type: module
core: 8.x
core_version_requirement: ^8.7.7 || ^9

dependencies:
- drupal:file
Expand Down
4 changes: 2 additions & 2 deletions apigee_edge.install
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* Install, update and uninstall functions for Apigee Edge.
*/

use Apigee\Edge\Utility\OrganizationFeatures;
use Drupal\apigee_edge\OauthTokenFileStorage;
use Drupal\Core\Installer\InstallerKernel;
use Drupal\Core\Url;
use Drupal\user\RoleInterface;

Expand All @@ -36,7 +36,7 @@ function apigee_edge_requirements($phase) {

if ($phase === 'install') {
// This should be checked only if Drupal is installed.
if (!drupal_installation_attempted()) {
if (!InstallerKernel::installationAttempted()) {
$missing_mails = \Drupal::entityQuery('user')
->notExists('mail')
->condition('uid', '0', '<>')
Expand Down
2 changes: 1 addition & 1 deletion apigee_edge.module
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ function apigee_edge_existing_developer_registration_hash(UserInterface $account
function apigee_edge_existing_developer_registration_hash_validate(UserInterface $account, string $token, string $timestamp) {
$current = \Drupal::time()->getRequestTime();
$timeout = \Drupal::config('apigee_edge.developer_settings')->get('verification_token_expires');
if ($timestamp <= $current && $current - $timestamp < $timeout && Crypt::hashEquals($token, apigee_edge_existing_developer_registration_hash($account, $timestamp))) {
if ($timestamp <= $current && $current - $timestamp < $timeout && hash_equals($token, apigee_edge_existing_developer_registration_hash($account, $timestamp))) {
return TRUE;
}
return FALSE;
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=7.1",
"ext-json": "*",
"apigee/apigee-client-php": "^2.0.4",
"drupal/core": "~8.7",
"drupal/core": "^8.7.7 || ^9",
"drupal/entity": "^1.0",
"drupal/key": "^1.8",
"php-http/guzzle6-adapter": "^1.1.1"
Expand All @@ -17,12 +17,11 @@
"behat/mink-extension": "v2.2",
"bex/behat-screenshot": "^1.2",
"cweagans/composer-patches": "^1.6",
"drupal/core-dev": "^8.7",
"drupal/core-dev": "^8.7 || ^9",
"drupal/drupal-extension": "master-dev",
"drush/drush": "^9.0",
"phpmd/phpmd": "^2.8",
"phpmetrics/phpmetrics": "^2.5",
"phpunit/phpunit": "^6.5",
"drupal/console": "~1.0"
},
"conflict": {
Expand Down
2 changes: 1 addition & 1 deletion modules/apigee_edge_actions/apigee_edge_actions.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Apigee Edge Actions
description: Rules integration for Apigee Edge.
package: Apigee (Experimental)
type: module
core: 8.x
core_version_requirement: ^8
configure: entity.rules_reaction_rule.collection
dependencies:
- apigee_edge:apigee_edge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: Apigee Edge Actions Debug
description: Logs debug information for Apigee Edge Actions.
package: Apigee (Experimental)
type: module
core: 8.x
core_version_requirement: ^8
dependencies:
- apigee_edge_actions:apigee_edge_actions
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Apigee Edge Actions Examples
description: Example rules for Apigee Edge.
package: Apigee (Experimental)
type: module
core: 8.x
core_version_requirement: ^8
configure: entity.rules_reaction_rule.collection
dependencies:
- apigee_edge_actions:apigee_edge_actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Role based access control over view operation on API products.
package: Apigee

type: module
core: 8.x
core_version_requirement: ^8 || ^9

dependencies:
- apigee_edge:apigee_edge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function apigee_edge_apiproduct_rbac_form_apigee_edge_api_product_access_control
// the query level does not work).
uasort($api_products, function (ApiProductInterface $a, ApiProductInterface $b) {
// Ignore case and malicious characters.
return strcmp(strtolower(Xss::filter($a->getDisplayName())), strtolower(Xss::filter($b->getDisplayName())));
return strcmp(mb_strtolower(Xss::filter($a->getDisplayName())), mb_strtolower(Xss::filter($b->getDisplayName())));
});
$product_names = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "Support module for the Apigee Edge API Product RBAC tests."
package: Testing

type: module
core: 8.x
core_version_requirement: ^8 || ^9

dependencies:
- apigee_edge:apigee_edge_apiproduct_rbac
2 changes: 1 addition & 1 deletion modules/apigee_edge_debug/apigee_edge_debug.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Debug helper for Apigee Edge Drupal integration.
package: Apigee

type: module
core: 8.x
core_version_requirement: ^8 || ^9

dependencies:
- apigee_edge:apigee_edge
Expand Down
2 changes: 1 addition & 1 deletion modules/apigee_edge_teams/apigee_edge_teams.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function hook_apigee_edge_teams_team_listing_page_title_alter(\Drupal\Core\Strin
*/
function hook_apigee_edge_teams_team_api_product_access(\Drupal\apigee_edge\Entity\ApiProductInterface $api_product, string $operation, \Drupal\apigee_edge_teams\Entity\TeamInterface $team, \Drupal\Core\Session\AccountInterface $account) {
// Grant access if API product's name is prefixed with the team's name.
return \Drupal\Core\Access\AccessResult::allowedIf(strpos($api_product->id(), $team->id()) === 0);
return \Drupal\Core\Access\AccessResult::allowedIf(mb_strpos($api_product->id(), $team->id()) === 0);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/apigee_edge_teams/apigee_edge_teams.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Provides shared app functionality by allowing developers to be orga
package: Apigee (Experimental)

type: module
core: 8.x
core_version_requirement: ^8 || ^9

dependencies:
- apigee_edge:apigee_edge
Expand Down
2 changes: 1 addition & 1 deletion modules/apigee_edge_teams/apigee_edge_teams.module
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function apigee_edge_teams_entity_type_alter(array &$entity_types) {
* The title of the page.
*/
function apigee_edge_teams_team_listing_page_title(): TranslatableMarkup {
$args['@teams'] = \Drupal::entityTypeManager()->getDefinition('team')->getPluralLabel();
$args['@teams'] = \Drupal::entityTypeManager()->getDefinition('team')->getCollectionLabel();
$title = t('@teams', $args);
// Modules and themes can alter the title.
\Drupal::moduleHandler()->alter('apigee_edge_teams_team_listing_page_title', $title);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function nonMemberApiProductAccessWarningElement(array $form, FormStat

if (!in_array($this->getTeamName($form, $form_state), $this->getTeamMembershipMananger()->getTeams(\Drupal::currentUser()->getEmail()))) {
$element['#message_list']['warning'][] = t('You are not member of this @team. You may see @api_products here that a @team member can not see.', [
'@team' => $this->getEntityTypeManager()->getDefinition('team')->getLowercaseLabel(),
'@team' => mb_strtolower($this->getEntityTypeManager()->getDefinition('team')->getSingularLabel()),
'@api_products' => $this->getEntityTypeManager()->getDefinition('api_product')->getPluralLabel(),
]);
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apigee_edge_teams/src/Entity/Form/TeamDeleteForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TeamDeleteForm extends EdgeEntityDeleteForm {
*/
protected function verificationCodeErrorMessage() {
return $this->t('The name does not match the @entity you are attempting to delete.', [
'@entity' => $this->entityTypeManager->getDefinition($this->getEntity()->getEntityTypeId())->getLowercaseLabel(),
'@entity' => mb_strtolower($this->entityTypeManager->getDefinition($this->getEntity()->getEntityTypeId())->getSingularLabel()),
]);
}

Expand All @@ -55,7 +55,7 @@ public function getDescription() {

return $this->t('<strong>All apps, credentials and @team membership information will be deleted.</strong> @original', [
'@original' => $original,
'@team' => $this->entityTypeManager->getDefinition($this->entity->getEntityTypeId())->getLowercaseLabel(),
'@team' => mb_strtolower($this->entityTypeManager->getDefinition($this->entity->getEntityTypeId())->getSingularLabel()),
]);
}

Expand Down
6 changes: 3 additions & 3 deletions modules/apigee_edge_teams/src/Entity/Form/TeamForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function exists(string $name, array $element, FormStateInterface $form_st
protected function actions(array $form, FormStateInterface $form_state) {
/** @var \Drupal\apigee_edge_teams\Entity\TeamInterface $team */
$team = $this->entity;
$label = $this->entityTypeManager->getDefinition('team')->getLowercaseLabel();
$label = mb_strtolower($this->entityTypeManager->getDefinition('team')->getSingularLabel());
$actions = parent::actions($form, $form_state);

if ($team->isNew()) {
Expand Down Expand Up @@ -203,7 +203,7 @@ public function save(array $form, FormStateInterface $form_state) {
'%email' => $this->currentUser->getEmail(),
'%team_name' => $team->label(),
'%admin_role' => $admin_role->label(),
'@team' => $this->entityTypeManager->getDefinition('team')->getLowercaseLabel(),
'@team' => mb_strtolower($this->entityTypeManager->getDefinition('team')->getSingularLabel()),
'link' => $team->toLink()->toString(),
];
$this->messenger()->addError($this->t('Failed to grant %admin_role team role in %team_name @team.', $context));
Expand All @@ -214,7 +214,7 @@ public function save(array $form, FormStateInterface $form_state) {
catch (ApiException $exception) {
$this->messenger()->addError($this->t('Failed to register team membership in %team_name @team.', [
'%team_name' => $team->label(),
'@team' => $this->entityTypeManager->getDefinition('team')->getLowercaseLabel(),
'@team' => mb_strtolower($this->entityTypeManager->getDefinition('team')->getSingularLabel()),
]));
$context = [
'%email' => $this->currentUser->getEmail(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function render() {
* The title of the page.
*/
public function pageTitle(): TranslatableMarkup {
return $this->t('@team_apps', ['@team_apps' => $this->entityType->getPluralLabel()]);
return $this->t('@team_apps', ['@team_apps' => $this->entityType->getCollectionLabel()]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function getDefaultOperations(EntityInterface $entity) {
if ($team_app_list_url->access()) {
$team_app_entity_def = $this->entityTypeManager->getDefinition('team_app');
$operations['apps'] = [
'title' => $team_app_entity_def->getPluralLabel(),
'title' => $team_app_entity_def->getCollectionLabel(),
'url' => $team_app_list_url,
'weight' => -10,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface;
Expand Down Expand Up @@ -65,8 +67,8 @@ class TeamMemberRoleStorage extends SqlContentEntityStorage implements TeamMembe
* The entity type definition.
* @param \Drupal\Core\Database\Connection $database
* The database connection to be used.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The entity field manager.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend to be used.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
Expand All @@ -77,9 +79,13 @@ class TeamMemberRoleStorage extends SqlContentEntityStorage implements TeamMembe
* The team membership manager service.
* @param \Psr\Log\LoggerInterface $logger
* The logger.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, TeamMembershipManagerInterface $team_membership_manager, LoggerInterface $logger) {
parent::__construct($entity_type, $database, $entity_manager, $cache, $language_manager, $memory_cache);
public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityFieldManagerInterface $entity_field_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache, TeamMembershipManagerInterface $team_membership_manager, LoggerInterface $logger, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, EntityTypeManagerInterface $entity_type_manager = NULL) {
parent::__construct($entity_type, $database, $entity_field_manager, $cache, $language_manager, $memory_cache, $entity_type_bundle_info, $entity_type_manager);
$this->teamMembershipManager = $team_membership_manager;
$this->logger = $logger;
}
Expand All @@ -91,12 +97,14 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
return new static(
$entity_type,
$container->get('database'),
$container->get('entity.manager'),
$container->get('entity_field.manager'),
$container->get('cache.entity'),
$container->get('language_manager'),
$container->get('entity.memory_cache'),
$container->get('apigee_edge_teams.team_membership_manager'),
$container->get('logger.channel.apigee_edge_teams')
$container->get('logger.channel.apigee_edge_teams'),
$container->get('entity_type.bundle.info'),
$container->get('entity_type.manager')
);
}

Expand Down
10 changes: 6 additions & 4 deletions modules/apigee_edge_teams/src/Entity/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
* @\Drupal\apigee_edge\Annotation\EdgeEntityType(
* id = "team",
* label = @Translation("Team"),
* label_singular = @Translation("Team"),
* label_plural = @Translation("Teams"),
* label_collection = @Translation("Teams"),
* label_singular = @Translation("team"),
* label_plural = @Translation("teams"),
* label_count = @PluralTranslation(
* singular = "@count Team",
* plural = "@count Teams",
* singular = "@count team",
* plural = "@count teams",
* ),
* config_with_labels = "apigee_edge_teams.team_settings",
* handlers = {
Expand Down Expand Up @@ -273,6 +274,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$team_singular_label = \Drupal::entityTypeManager()
->getDefinition('team')
->getSingularLabel();
$team_singular_label = mb_convert_case($team_singular_label, MB_CASE_TITLE);

$definitions['displayName']
->setDisplayOptions('view', [
Expand Down
10 changes: 6 additions & 4 deletions modules/apigee_edge_teams/src/Entity/TeamApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
* @\Drupal\apigee_edge\Annotation\EdgeEntityType(
* id = "team_app",
* label = @Translation("Team App"),
* label_singular = @Translation("Team App"),
* label_plural = @Translation("Team Apps"),
* label_collection = @Translation("Team Apps"),
* label_singular = @Translation("team app"),
* label_plural = @Translation("team apps"),
* label_count = @PluralTranslation(
* singular = "@count Team App",
* plural = "@count Team Apps",
* singular = "@count team app",
* plural = "@count team apps",
* ),
* config_with_labels = "apigee_edge_teams.team_app_settings",
* handlers = {
Expand Down Expand Up @@ -152,6 +153,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
/** @var \Drupal\Core\Field\BaseFieldDefinition[] $definitions */
$definitions = parent::baseFieldDefinitions($entity_type);
$team_app_singular_label = \Drupal::entityTypeManager()->getDefinition('team_app')->getSingularLabel();
$team_app_singular_label = mb_convert_case($team_app_singular_label, MB_CASE_TITLE);

$definitions['displayName']
->setLabel(t('@team_app name', ['@team_app' => $team_app_singular_label]));
Expand Down
4 changes: 3 additions & 1 deletion modules/apigee_edge_teams/src/Entity/TeamTitleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class TeamTitleProvider extends EdgeEntityTitleProvider {
*/
public function teamMembersList(RouteMatchInterface $route_match, EntityInterface $_entity = NULL) {
if ($entity = $this->doGetEntity($route_match, $_entity)) {
return $this->t('@entity_type Members', ['@entity_type' => $this->entityTypeManager->getDefinition($entity->getEntityTypeId())->getSingularLabel()]);
return $this->t('@entity_type Members', [
'@entity_type' => ucfirst($this->entityTypeManager->getDefinition($entity->getEntityTypeId())->getSingularLabel()),
]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public function onRespond(FilterResponseEvent $event) {

if ($team && $team->getStatus() === TeamInterface::STATUS_INACTIVE) {
$this->messenger->addWarning($this->t('This @team has inactive status so @team members will not be able to use @team_app credentials until the @team gets activated. Please contact support for further assistance.', [
'@team' => $this->entityTypeManager->getDefinition('team')->getLowercaseLabel(),
'@team_app' => $this->entityTypeManager->getDefinition('team_app')->getLowercaseLabel(),
'@team' => mb_strtolower($this->entityTypeManager->getDefinition('team')->getSingularLabel()),
'@team_app' => mb_strtolower($this->entityTypeManager->getDefinition('team_app')->getSingularLabel()),
]));
}
}
Expand Down
11 changes: 8 additions & 3 deletions modules/apigee_edge_teams/src/Form/AddTeamMembersForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public function buildForm(array $form, FormStateInterface $form_state, TeamInter

$form['developers'] = [
'#title' => $this->t('Developers'),
'#description' => $this->t('Enter the email of one or more developers to add them to the @team.', ['@team' => $this->team->getEntityType()->getLowercaseLabel()]),
'#description' => $this->t('Enter the email of one or more developers to add them to the @team.', [
'@team' => mb_strtolower($this->team->getEntityType()->getSingularLabel()),
]),
'#type' => 'entity_autocomplete',
'#target_type' => 'user',
'#tags' => TRUE,
Expand All @@ -117,7 +119,10 @@ public function buildForm(array $form, FormStateInterface $form_state, TeamInter
];

$form['team_roles']['description'] = [
'#markup' => $this->t('Assign one or more roles to <em>all developers</em> that you selected in %team_label @team.', ['%team_label' => $this->team->label(), '@team' => $this->team->getEntityType()->getLowercaseLabel()]),
'#markup' => $this->t('Assign one or more roles to <em>all developers</em> that you selected in %team_label @team.', [
'%team_label' => $this->team->label(),
'@team' => mb_strtolower($this->team->getEntityType()->getSingularLabel()),
]),
];

$form['actions'] = [
Expand Down Expand Up @@ -157,7 +162,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {

$context = [
'@developers' => implode('', $developer_emails),
'@team' => $this->team->getEntityType()->getLowercaseLabel(),
'@team' => mb_strtolower($this->team->getEntityType()->getSingularLabel()),
'%team_id' => $this->team->id(),
];

Expand Down
2 changes: 1 addition & 1 deletion modules/apigee_edge_teams/src/Form/EditTeamMemberForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function buildForm(array $form, FormStateInterface $form_state, TeamInter
'#markup' => $this->t('Modify roles of %developer in the %team_label @team.', [
'%developer' => $this->developer->getOwner()->label(),
'%team_label' => $this->team->label(),
'@team' => $this->team->getEntityType()->getLowercaseLabel(),
'@team' => mb_strtolower($this->team->getEntityType()->getSingularLabel()),
]),
];

Expand Down
Loading

0 comments on commit 73f1f3b

Please sign in to comment.