diff --git a/core/modules/shortcut/shortcut.admin.inc b/core/modules/shortcut/shortcut.admin.inc index f2f938d..2444eec 100644 --- a/core/modules/shortcut/shortcut.admin.inc +++ b/core/modules/shortcut/shortcut.admin.inc @@ -137,8 +137,7 @@ function shortcut_set_switch_submit($form, &$form_state) { if ($form_state['values']['set'] == 'new') { // Save a new shortcut set with links copied from the user's default set. - $default_set = shortcut_default_set($account); - $set = entity_create('shortcut_set', array( + $set = ShortcutSet::create(array( 'id' => $form_state['values']['id'], 'label' => $form_state['values']['label'], )); diff --git a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php index 6a9c78a..a221b0e 100644 --- a/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutCacheTagsTest.php @@ -7,6 +7,7 @@ namespace Drupal\shortcut\Tests; +use Drupal\shortcut\Entity\Shortcut; use Drupal\system\Tests\Entity\EntityCacheTagsTestBase; /** @@ -44,7 +45,7 @@ public function setUp() { */ protected function createEntity() { // Create a "Llama" shortcut. - $shortcut = entity_create('shortcut', array( + $shortcut = Shortcut::create(array( 'set' => 'default', 'title' => t('Llama'), 'weight' => 0, diff --git a/core/modules/shortcut/src/Tests/ShortcutTestBase.php b/core/modules/shortcut/src/Tests/ShortcutTestBase.php index 461a40c..6d9e240 100644 --- a/core/modules/shortcut/src/Tests/ShortcutTestBase.php +++ b/core/modules/shortcut/src/Tests/ShortcutTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\shortcut\Tests; +use Drupal\shortcut\Entity\Shortcut; use Drupal\shortcut\Entity\ShortcutSet; use Drupal\shortcut\ShortcutSetInterface; use Drupal\simpletest\WebTestBase; @@ -54,7 +55,7 @@ function setUp() { $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); // Populate the default shortcut set. - $shortcut = entity_create('shortcut', array( + $shortcut = Shortcut::create(array( 'set' => 'default', 'title' => t('Add content'), 'weight' => -20, @@ -62,7 +63,7 @@ function setUp() { )); $shortcut->save(); - $shortcut = entity_create('shortcut', array( + $shortcut = Shortcut::create(array( 'set' => 'default', 'title' => t('All content'), 'weight' => -19, @@ -88,7 +89,7 @@ function setUp() { * Creates a generic shortcut set. */ function generateShortcutSet($label = '', $id = NULL) { - $set = entity_create('shortcut_set', array( + $set = ShortcutSet::create(array( 'id' => isset($id) ? $id : strtolower($this->randomName()), 'label' => empty($label) ? $this->randomString() : $label, )); diff --git a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php index e1e6680..52d99b2 100644 --- a/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -904,6 +904,13 @@ public static function loadMultiple(array $ids = NULL) { } /** + * {@inheritdoc} + */ + public static function create(array $values = array()) { + return View::create($values); + } + + /** * Implements \Drupal\Core\Entity\EntityInterface::delete(). */ public function delete() { diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php index 9e600c6..3ecc8de 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php @@ -262,6 +262,7 @@ function setupTestLoad() { $methods = get_class_methods('Drupal\entity_test\Entity\EntityTestMul'); unset($methods[array_search('load', $methods)]); unset($methods[array_search('loadMultiple', $methods)]); + unset($methods[array_search('create', $methods)]); $this->entity = $this->getMockBuilder('Drupal\entity_test\Entity\EntityTestMul') ->disableOriginalConstructor() ->setMethods($methods) @@ -475,6 +476,29 @@ public function testLoadMultipleSubClass() { } /** + * @covers ::create + * @covers ::getEntityTypeFromStaticClass + */ + public function testCreate() { + $this->setupTestLoad(); + + $storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface'); + $storage->expects($this->once()) + ->method('create') + ->with(array()) + ->will($this->returnValue($this->entity)); + $this->entityManager->expects($this->once()) + ->method('getStorage') + ->with($this->entityTypeId) + ->will($this->returnValue($storage)); + + // Call Entity::create() statically and check that it returns the mock + // entity. + $class = get_class($this->entity); + $this->assertSame($this->entity, $class::create(array())); + } + + /** * @covers ::save */ public function testSave() {