Commit bebb3459 authored by webchick's avatar webchick

Issue #1848964 by tim.plunkett: EntityManager should process its definitions before altering them.

parent 031f6735
......@@ -64,7 +64,8 @@ public function getDefinitions() {
foreach ($definitions as $plugin_id => &$definition) {
call_user_func_array($this->processCallback, array(&$definition, $plugin_id));
}
return $definitions;
// Allow process callbacks to unset definitions.
return array_filter($definitions);
}
/**
......
......@@ -231,9 +231,8 @@ public function __construct() {
// Allow the plugin definition to be altered by hook_entity_info_alter().
$this->discovery = new AnnotatedClassDiscovery('Core', 'Entity');
$this->discovery = new InfoHookDecorator($this->discovery, 'entity_info');
$this->discovery = new AlterDecorator($this->discovery, 'entity_info');
// @todo Run process before altering, see http://drupal.org/node/1848964.
$this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition'));
$this->discovery = new AlterDecorator($this->discovery, 'entity_info');
$this->factory = new DefaultFactory($this);
// Entity type plugins includes translated strings, so each language is
......@@ -260,9 +259,7 @@ public function getDefinitions() {
return $cache->data;
}
else {
// @todo Remove array_filter() once http://drupal.org/node/1780396 is
// resolved.
$definitions = array_filter(parent::getDefinitions());
$definitions = parent::getDefinitions();
cache($this->cacheBin)->set($this->cacheKey, $definitions, $this->cacheExpire, $this->cacheTags);
return $definitions;
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\TypedData\AccessibleInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\user\Plugin\Core\Entity\User;
use Drupal\Core\Entity\EntityAccessController;
/**
* Tests the entity access controller.
......@@ -81,15 +82,12 @@ function testEntityAccess() {
* Ensures that the default controller is used as a fallback.
*/
function testEntityAccessDefaultController() {
// Remove the access controller definition from the test entity.
state()->set('entity_test.default_access_controller', TRUE);
// Check that the default access controller is used for entities that don't
// have a specific access controller defined.
$controller = entity_access_controller('entity_test');
$this->assertTrue($controller instanceof \Drupal\Core\Entity\EntityAccessController, 'The default entity controller is used for the entity_test entity type.');
$controller = entity_access_controller('entity_test_default_access');
$this->assertTrue($controller instanceof EntityAccessController, 'The default entity controller is used for the entity_test_default_access entity type.');
$entity = entity_create('entity_test', array());
$entity = entity_create('entity_test_default_access', array());
$this->assertEntityAccess(array(
'create' => FALSE,
'update' => FALSE,
......
......@@ -9,12 +9,14 @@
use Drupal\Core\Entity\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines the EntityCacheTest class.
*
* @Plugin(
* id = "entity_cache_test",
* label = @Translation("Entity cache test"),
* module = "entity_cache_test_dependency"
* )
*/
......
......@@ -16,10 +16,6 @@ function entity_test_entity_info_alter(&$info) {
if (state()->get('entity_test.translation')) {
$info['entity_test']['translation']['entity_test'] = TRUE;
}
// Optionally unset the access controller to test the fallback.
if (state()->get('entity_test.default_access_controller')) {
unset($info['entity_test']['access_controller_class']);
}
}
/**
......
<?php
/**
* @file
* Contains \Drupal\entity_test\Plugin\Core\Entity\EntityTestDefaultAccess.
*/
namespace Drupal\entity_test\Plugin\Core\Entity;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Defines a test entity class with no access controller.
*
* @Plugin(
* id = "entity_test_default_access",
* label = @Translation("Test entity with default access"),
* module = "entity_test",
* controller_class = "Drupal\entity_test\EntityTestStorageController",
* base_table = "entity_test",
* entity_keys = {
* "id" = "id"
* }
* )
*/
class EntityTestDefaultAccess extends EntityTest {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment