Skip to content
Snippets Groups Projects
Commit 2655876a authored by Klaus Purer's avatar Klaus Purer
Browse files

Issue #2566063: rules_entity_view() has wrong signature

parent 6a221467
No related branches found
Tags 7.x-2.10
No related merge requests found
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\rules\Event\EntityEvent;
use Drupal\rules\Event\UserLoginEvent;
......@@ -36,7 +37,7 @@ function rules_user_logout($account) {
/**
* Implements hook_entity_view().
*/
function rules_entity_view(EntityInterface $entity) {
function rules_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode) {
// Only handle content entities and ignore config entities.
if ($entity instanceof ContentEntityInterface) {
$entity_type_id = $entity->getEntityTypeId();
......
<?php
/**
* @file
* Contains \Drupal\rules\Tests\EntityViewTest.
*/
namespace Drupal\Tests\rules\Kernel;
/**
* Tests that rules_entity_view() does not throw fatal errors.
*
* @group rules
*/
class EntityViewTest extends RulesDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['field', 'node', 'text', 'user'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->installConfig(['system']);
$this->installConfig(['field']);
$this->installConfig(['node']);
$this->installSchema('system', ['router', 'sequences']);
$this->installEntitySchema('user');
$this->installEntitySchema('node');
// Make sure that the node routes get picked when used during rendering.
$this->container->get('router.builder')->rebuild();
}
/**
* Tests that rules_entity_view() can be invoked correctly.
*/
public function testEntityViewHook() {
// Create a node.
$entity_manager = $this->container->get('entity.manager');
$entity_manager->getStorage('node_type')
->create([
'type' => 'page',
'display_submitted' => FALSE,
])
->save();
$node = $entity_manager->getStorage('node')
->create([
'title' => 'test',
'type' => 'page',
]);
$node->save();
// Build the node render array and render it, so that hook_entity_view() is
// invoked.
$view_builder = $entity_manager->getViewBuilder('node');
$build = $view_builder->view($node);
$this->container->get('renderer')->renderPlain($build);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment