Commit d8e21f87 authored by alexpott's avatar alexpott
Browse files

Issue #2032031 by damiankloip: Deprecate use of views_get_view() function in...

Issue #2032031 by damiankloip: Deprecate use of views_get_view() function in favour of Views::getView() method.
parent 14708544
......@@ -75,4 +75,20 @@ public static function handlerManager($type) {
return Drupal::service('plugin.manager.views.' . $type);
}
/**
* Loads a view from configuration and returns its executable object.
*
* @param string $id
* The view ID to load.
*
* @return \Drupal\views\ViewExecutable
* A view executable instance, from the loaded entity.
*/
public static function getView($id) {
$view = Drupal::service('plugin.manager.entity')->getStorageController('view')->load($id);
if ($view) {
return static::executableFactory()->get($view);
}
}
}
<?php
/**
* @file
* Contains \Drupal\views\Tests\ViewsTest.
*/
namespace Drupal\views\Tests;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Views;
use Drupal\views\Plugin\Core\Entity\View;
use Drupal\views\ViewExecutableFactory;
use Drupal;
use Drupal\Core\DependencyInjection\ContainerBuilder;
class ViewsTest extends UnitTestCase {
public static function getInfo() {
return array(
'name' => 'Views test',
'description' => 'Tests the Drupal\views\Views class.',
'group' => 'Views',
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$container = new ContainerBuilder();
$container->set('views.executable', new ViewExecutableFactory());
$this->view = new View(array('id' => 'test_view'), 'view');
$view_storage_controller = $this->getMockBuilder('Drupal\views\ViewStorageController')
->disableOriginalConstructor()
->getMock();
$view_storage_controller->expects($this->once())
->method('load')
->with('test_view')
->will($this->returnValue($this->view));
$entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManager')
->disableOriginalConstructor()
->getMock();
$entity_manager->expects($this->once())
->method('getStorageController')
->with('view')
->will($this->returnValue($view_storage_controller));
$container->set('plugin.manager.entity', $entity_manager);
Drupal::setContainer($container);
}
/**
* Tests the getView() method.
*/
public function testGetView() {
$executable = Views::getView('test_view');
$this->assertInstanceOf('Drupal\views\ViewExecutable', $executable);
$this->assertEquals($this->view->id(), $executable->storage->id());
$this->assertEquals(spl_object_hash($this->view), spl_object_hash($executable->storage));
}
}
......@@ -1105,12 +1105,12 @@ function views_disable_view(View $view) {
*
* @return Drupal\views\ViewExecutable
* A reference to the $view object.
*
* @deprecated as of Drupal 8.0. Use \Drupal\views\Views::getView().
*
*/
function views_get_view($name) {
$view = entity_load('view', $name);
if ($view) {
return $view->get('executable');
}
return Views::getView($name);
}
/**
......
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