Skip to content
Snippets Groups Projects
Commit 9b6ddcff authored by Angie Byron's avatar Angie Byron
Browse files

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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment