Commit 0a1b1dc9 authored by damiankloip's avatar damiankloip Committed by tim.plunkett

Issue #1810788 by damiankloip: Added enable and disable procedural wrappers.

parent cc0a0cc1
......@@ -175,6 +175,23 @@ public function testLoadFunctions() {
$this->assertIdentical($expected_opt_groups, views_get_views_as_options(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
}
/**
* Tests view enable and disable procedural wrapper functions.
*/
function testStatusFunctions() {
$view = views_get_view('test_view_status')->storage;
$this->assertFalse($view->isEnabled(), 'The view status is disabled.');
views_enable_view($view);
$this->assertTrue($view->isEnabled(), 'A view has been enabled.');
$this->assertEqual($view->isEnabled(), views_view_is_enabled($view), 'views_view_is_enabled is correct.');
views_disable_view($view);
$this->assertFalse($view->isEnabled(), 'A view has been disabled.');
$this->assertEqual(!$view->isEnabled(), views_view_is_disabled($view), 'views_view_is_disabled is correct.');
}
/**
* Helper to return an expected views option array.
*
......
base_table: views_test_data
name: test_view_status
description: ''
tag: ''
human_name: test_view_status
core: 8.x
api_version: '3.0'
display:
default:
display_plugin: default
id: default
display_title: Master
position: ''
base_field: id
disabled: '1'
module: views
......@@ -12,6 +12,7 @@
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\views\ViewExecutable;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\views\ViewStorage;
/**
* Views API version string.
......@@ -1633,29 +1634,49 @@ function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclu
/**
* Returns whether the view is enabled.
*
* @param Drupal\views\ViewExecutable $view
* @param Drupal\views\ViewStorage $view
* The view object to check.
*
* @return bool
* Returns TRUE if a view is enabled, FALSE otherwise.
*/
function views_view_is_enabled($view) {
function views_view_is_enabled(ViewStorage $view) {
return $view->isEnabled();
}
/**
* Returns whether the view is disabled.
*
* @param Drupal\views\ViewExecutable $view
* @param Drupal\views\ViewStorage $view
* The view object to check.
*
* @return bool
* Returns TRUE if a view is disabled, FALSE otherwise.
*/
function views_view_is_disabled($view) {
function views_view_is_disabled(ViewStorage $view) {
return !$view->isEnabled();
}
/**
* Enables a view.
*
* @param Drupal\views\ViewStorage $view
* The ViewStorage object to disable.
*/
function views_enable_view(ViewStorage $view) {
$view->enable();
}
/**
* Disables a view.
*
* @param Drupal\views\ViewStorage $view
* The ViewStorage object to disable.
*/
function views_disable_view(ViewStorage $view) {
$view->disable();
}
/**
* Loads a view from configuration.
*
......
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