Skip to content

Commit

Permalink
Drupal 10.3 compatibility udpates.
Browse files Browse the repository at this point in the history
  • Loading branch information
joegl committed Nov 7, 2024
1 parent 6d60564 commit 801be24
Show file tree
Hide file tree
Showing 29 changed files with 52 additions and 462 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#options' => array_combine($values, $values),
];

$node_ids = [];
foreach ($this->context['list'] as $item) {
$node_ids[] = $item[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CloneNodeTest extends KernelTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'system',
'node',
'user',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DateTest extends KernelTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'system',
'node',
'user',
Expand Down Expand Up @@ -194,12 +194,12 @@ public function testDaylightSavingsFromJune() {

$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$pre_render = $view_builder->view($this->node);
$rendered_output = \Drupal::service('renderer')->renderPlain($pre_render);
$rendered_output = \Drupal::service('renderer')->renderInIsolation($pre_render);
$this->assertStringContainsString('June 2, 2019 2:15 AM', (string) $rendered_output);

$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$pre_render = $view_builder->view($new_node);
$rendered_output = \Drupal::service('renderer')->renderPlain($pre_render);
$rendered_output = \Drupal::service('renderer')->renderInIsolation($pre_render);
$this->assertStringContainsString('December 2, 2019 2:15 AM', (string) $rendered_output);
}

Expand Down Expand Up @@ -231,12 +231,12 @@ public function testDaylightSavingsFromDecember() {

$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$pre_render = $view_builder->view($this->node);
$rendered_output = \Drupal::service('renderer')->renderPlain($pre_render);
$rendered_output = \Drupal::service('renderer')->renderInIsolation($pre_render);
$this->assertStringContainsString('December 2, 2019 3:15 AM', (string) $rendered_output);

$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$pre_render = $view_builder->view($new_node);
$rendered_output = \Drupal::service('renderer')->renderPlain($pre_render);
$rendered_output = \Drupal::service('renderer')->renderInIsolation($pre_render);
$this->assertStringContainsString('June 2, 2020 3:15 AM', (string) $rendered_output);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class HsBasicPageKernelTest extends KernelTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'system',
'user',
'node',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function blockAccess(AccountInterface $account) {

$components = $this->getComponents();
// This prevents the block label from displaying if there are no contents.
if (empty($this->renderer->renderPlain($components))) {
if (empty($this->renderer->renderInIsolation($components))) {
return AccessResult::forbidden();
}
return parent::blockAccess($account);
Expand Down
6 changes: 4 additions & 2 deletions docroot/modules/humsci/hs_capx/src/Capx.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,14 @@ public static function getWorkgroupUrl($workgroups) {
* @return int
* Total number of profiles.
*/
public function getTotalProfileCount($url) {
public function getTotalProfileCount($url): int {
$token = $this->getAccessToken();
$response = self::getApiResponse("$url&ps=1&access_token=$token");
if ($response) {
$response = json_decode($response, TRUE);
return $response['totalCount'] ?? 0;
}
return 0;
}

/**
Expand Down Expand Up @@ -276,7 +277,7 @@ protected function getOrgData() {
* @return string
* API Token.
*/
protected function getAccessToken() {
protected function getAccessToken(): string {
if ($cache = $this->cache->get('capx:access_token')) {
return $cache->data['access_token'];
}
Expand All @@ -293,6 +294,7 @@ protected function getAccessToken() {
]);
return $result['access_token'];
}
return '';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class HSPubJson extends Json {
/**
* {@inheritDoc}
*/
protected function getSourceData(string $url): array {
$source_data = parent::getSourceData($url);
protected function getSourceData(string $url, string|int $item_selector = ''): array {
$source_data = parent::getSourceData($url, $item_selector);
$modified_data = [];
foreach ($source_data as $item) {
if (!empty($item['publications'])) {
Expand Down
1 change: 1 addition & 0 deletions docroot/modules/humsci/hs_capx/tests/src/Unit/CapxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function guzzleRequestCallback($method, $url) {
* Cached data.
*/
public function cacheGetCallback($cid) {
$data = '';
switch ($cid) {
case 'capx:org_data':
$data = json_decode(file_get_contents(__DIR__ . '/orgs.json'), TRUE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: 'H&S Courses Importer'
type: module
description: 'Courses Migration Importer'
core_version_requirement: ^10.3 || ^11
version: 8.3.0
package: 'Humanities & Sciences'
dependencies:
- hs_courses
- migrate_tools
- migrate_plus
version: 8.2.7
Original file line number Diff line number Diff line change
Expand Up @@ -5,59 +5,13 @@
* hs_courses_importer.post_update.php
*/

use Drupal\migrate\MigrateMessage;
use Drupal\migrate_tools\MigrateExecutable;
use Drupal\Core\Config\FileStorage;

/**
* Rollback courses, revert the migration config.
*/
function hs_courses_importer_post_update_8001() {
$migrations = hs_field_helpers_migration_list();
/** @var \Drupal\migrate_plus\Entity\Migration $course_migration */
$course_migration = $migrations['hs_courses']['hs_courses'];
$log = new MigrateMessage();
$executable = new MigrateExecutable($course_migration, $log);
if (\Drupal::database()->schema()->tableExists('migrate_map_hs_courses')) {
$executable->rollback();
}

// Delete all machine readable.
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadTree('hs_course_tags', 0, NULL, TRUE);
/** @var \Drupal\taxonomy\Entity\Term $term */
foreach ($terms as $term) {
if (strpos($term->label(), '::') !== FALSE) {
$term->delete();
}
}
}

/**
* Drop the migrate table for courses.
*/
function hs_courses_importer_post_update_8002() {
$source = new FileStorage('../config/default');
/** @var \Drupal\Core\Config\CachedStorage $config_storage */
$config_storage = \Drupal::service('config.storage');
$config_storage->write('migrate_plus.migration.hs_courses', $source->read('migrate_plus.migration.hs_courses'));

// I added the course id & course code to source.ids. Anytime the ids are
// added/deleted the table must be deleted so that it can be rebuilt with the
// additional columns on the next import.
\Drupal::database()->schema()->dropTable('migrate_map_hs_courses');
drupal_flush_all_caches();
}

/**
* Import courses with new mapping.
* Implements hook_removed_post_updates().
*/
function hs_courses_importer_post_update_8003() {
$migrations = hs_field_helpers_migration_list();
/** @var \Drupal\migrate_plus\Entity\Migration $course_migration */
$course_migration = $migrations['hs_courses']['hs_courses'];
$log = new MigrateMessage();
$executable = new MigrateExecutable($course_migration, $log);
$executable->import();
function hs_courses_importer_removed_post_updates() {
return [
'hs_courses_importer_post_update_8001' => '8.3.0',
'hs_courses_importer_post_update_8002' => '8.3.0',
'hs_courses_importer_post_update_8003' => '8.3.0',
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CourseTagListBuilderTest extends EntityKernelTestBase {
*
* @var array
*/
public static $modules = ['system', 'hs_courses_importer'];
protected static $modules = ['system', 'hs_courses_importer'];

/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract class HsCoursesImporterTestBase extends EntityKernelTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'system',
'hs_courses_importer',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TranslateCourseTagTest extends EntityKernelTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'system',
'hs_courses_importer',
'migrate',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function save(array $form, FormStateInterface $form_state) {
elseif ($status == SAVED_NEW) {
$message = $this->t('The HumSci entity type %name has been added.', $t_args);
}
$this->messenger()->addStatus($message);
if ($message) {
$this->messenger()->addStatus($message);
}

$form_state->setRedirectUrl($entity_type->toUrl('collection'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ protected function getFullUrl(array $choices) {
}
return $url;
}
return '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,6 @@ function hs_field_helpers_field_storage_config_presave(FieldStorageConfigInterfa
}
}

/**
* Implements hook_audio_embed_field_provider_info_alter().
*/
function hs_field_helpers_audio_embed_field_provider_info_alter(&$definitions) {
$definitions['soundcloud']['class'] = '\Drupal\hs_field_helpers\Plugin\audio_embed_field\Provider\StanfordSoundCloud';
}

/**
* Implements hook_preprocess_HOOK().
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function onLayoutBuilderRender(SectionComponentBuildRenderArrayEvent $eve
* Rendered and clean markup.
*/
protected function getCleanRender(array $render_array) {
return trim(strip_tags($this->renderer->renderPlain($render_array), '<img><iframe>'));
return trim(strip_tags($this->renderer->renderInIsolation($render_array), '<img><iframe>'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ protected function getFieldValues(FieldItemListInterface $items) {
* @return bool
* If the view has results or an empty result display.
*/
protected function viewHasResults(ViewExecutable $view) {
protected function viewHasResults(ViewExecutable $view): bool {
if ($view->result || $view->empty) {
return TRUE;
}
return FALSE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function renderClean($elements, $tags = '<drupal-render-placeholder>') {
}

// Renderer service only accepts arrays.
$rendered = is_array($elements) ? $this->renderer->renderPlain($elements) : $elements;
$rendered = is_array($elements) ? $this->renderer->renderInIsolation($elements) : $elements;

if (strpos($tags, '<drupal-render-placeholder>') === FALSE) {
$tags .= '<drupal-render-placeholder>';
Expand Down
Loading

0 comments on commit 801be24

Please sign in to comment.