From 4db83784d330d35fee22af668f3e94cb48923f6b Mon Sep 17 00:00:00 2001 From: Casper Date: Wed, 5 Jan 2022 14:37:27 +0200 Subject: [PATCH] Fixed deprecated code. --- src/Tests/ViewFieldTest.php | 26 +++++++++++++++++--------- viewfield.info.yml | 1 + viewfield.module | 3 ++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Tests/ViewFieldTest.php b/src/Tests/ViewFieldTest.php index 7a83ecd..2b0f4a3 100644 --- a/src/Tests/ViewFieldTest.php +++ b/src/Tests/ViewFieldTest.php @@ -7,15 +7,19 @@ namespace Drupal\viewfield\Tests; -use Drupal\Component\Utility\Unicode; -use Drupal\simpletest\WebTestBase; +use Drupal\Tests\BrowserTestBase; /** * Tests viewfield field. * * @group viewfield */ -class ViewFieldTest extends WebTestBase { +class ViewFieldTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'stark'; /** * Modules to enable. @@ -53,9 +57,10 @@ protected function setUp() { * Test field creation and attachment to an article. */ function testFieldCreation() { - $field_name = Unicode::strtolower($this->randomMachineName()); + $field_name = mb_strtolower($this->randomMachineName()); // Create a field with settings to validate. - $this->fieldStorage = entity_create('field_storage_config', array( + $field_storage_config_storage = \Drupal::entityTypeManager()->getStorage('field_storage_config'); + $this->fieldStorage = $field_storage_config_storage->create(array( 'field_name' => $field_name, 'entity_type' => 'node', 'translatable' => FALSE, @@ -63,19 +68,22 @@ function testFieldCreation() { 'cardinality' => '1', )); $this->fieldStorage->save(); - $this->field = entity_create('field_config', array( + $field_config_storage = \Drupal::entityTypeManager()->getStorage('field_config'); + $this->field = $field_config_storage->create(array( 'field_storage' => $this->fieldStorage, 'bundle' => 'article', 'title' => DRUPAL_DISABLED, )); $this->field->save(); - entity_get_form_display('node', 'article', 'default') + \Drupal::service('entity_display.repository') + ->getFormDisplay('node', 'article', 'default') ->setComponent($field_name, array( 'type' => 'viewfield_select', 'settings' => array(), )) ->save(); - entity_get_display('node', 'article', 'full') + \Drupal::service('entity_display.repository') + ->getViewDisplay('node', 'article', 'full') ->setComponent($field_name, array( 'type' => 'viewfield_default', )) @@ -119,7 +127,7 @@ protected function assertViewDisplays($field_name) { $view_select_name => 'user_admin_people|default', ); $this->drupalPostForm(NULL, $edit, t('Save and publish')); - + // test that the view displays on the node $elements = $this->xpath("//div[contains(@class,:class) and contains(@class,:class1)]", array(':class' => 'view-user-admin-people',':class1' => 'view-display-id-default')); diff --git a/viewfield.info.yml b/viewfield.info.yml index 5f25a88..4006316 100644 --- a/viewfield.info.yml +++ b/viewfield.info.yml @@ -3,6 +3,7 @@ type: module description: 'Defines a field type to display a view.' version: VERSION core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - views - field diff --git a/viewfield.module b/viewfield.module index 3646dc7..ea08bf5 100644 --- a/viewfield.module +++ b/viewfield.module @@ -123,7 +123,8 @@ function _viewfield_get_view_args($vargs, $entity_type, $entity) { } list($entity_id) = $entity->id(); - $entity = entity_load($entity_type, $entity_id); + $entity_storage = \Drupal::entityTypeManager()->getStorage($entity_type); + $entity = $entity_storage->load($entity_id); $token_data = array($entity_type => $entity); $token = Drupal::token();