Commit 9b6ddcff authored by webchick's avatar webchick

Issue #1945680 by dawehner: Provide a method that checks whether a certain...

Issue #1945680 by dawehner: Provide a method that checks whether a certain entity type provides a certain controller.
parent 257ae98f
......@@ -199,6 +199,22 @@ public function processDefinition(&$definition, $plugin_id) {
}
}
/**
* Checks whether a certain entity type has a certain controller.
*
* @param string $entity_type
* The name of the entity type.
* @param string $controller_type
* The name of the controller.
*
* @return bool
* Returns TRUE if the entity type has the controller, else FALSE.
*/
public function hasController($entity_type, $controller_type) {
$definition = $this->getDefinition($entity_type);
return !empty($definition[$controller_type]);
}
/**
* Returns an entity controller class.
*
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Entity\EntityManagerTest.
*/
namespace Drupal\system\Tests\Entity;
/**
* Tests methods on the entity manager.
*
* @see \Drupal\Core\Entity\EntityManager
*/
class EntityManagerTest extends EntityUnitTestBase {
public static function getInfo() {
return array(
'name' => 'Entity Manager',
'description' => 'Tests methods on the entity manager.',
'group' => 'Entity API',
);
}
/**
* Tests some methods on the manager.
*/
public function testMethods() {
// Tests the has controller method.
$entity_manager = $this->container->get('plugin.manager.entity');
$this->assertFalse($entity_manager->hasController('non_existent', 'controller_class'), 'A non existent entity type has no controller.');
$this->assertFalse($entity_manager->hasController('non_existent', 'non_existent_controller_class'), 'A non existent entity type has no controller.');
$this->assertFalse($entity_manager->hasController('entity_test', 'non_existent_controller_class'), 'An existent entity type does not have a non existent controller.');
$this->assertFalse($entity_manager->hasController('entity_test', 'render_controller_class'), 'The test entity does not have specified the render controller.');
$this->assertTrue($entity_manager->hasController('entity_test', 'controller_class'), 'The test entity has specified the controller class');
}
}
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