Skip to content

Commit

Permalink
Merge pull request #2 from kviatkovskyi/drupal_9_fixes
Browse files Browse the repository at this point in the history
Fixed deprecated code.
  • Loading branch information
kviatkovskyi authored Jan 5, 2022
2 parents fbff3b1 + 4db8378 commit aa188ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
26 changes: 17 additions & 9 deletions src/Tests/ViewFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -53,29 +57,33 @@ 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,
'type' => 'viewfield',
'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',
))
Expand Down Expand Up @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions viewfield.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion viewfield.module
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit aa188ee

Please sign in to comment.