Issue #1810788 by damiankloip: Added enable and disable procedural wrappers.
parent
cc0a0cc14e
commit
0a1b1dc9bb
|
@ -175,6 +175,23 @@ class ModuleTest extends ViewTestBase {
|
||||||
$this->assertIdentical($expected_opt_groups, views_get_views_as_options(FALSE, 'all', NULL, TRUE), 'Expected option array for an option group returned.');
|
$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.
|
* Helper to return an expected views option array.
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
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
|
29
views.module
29
views.module
|
@ -12,6 +12,7 @@
|
||||||
use Drupal\Core\Database\Query\AlterableInterface;
|
use Drupal\Core\Database\Query\AlterableInterface;
|
||||||
use Drupal\views\ViewExecutable;
|
use Drupal\views\ViewExecutable;
|
||||||
use Drupal\Component\Plugin\Exception\PluginException;
|
use Drupal\Component\Plugin\Exception\PluginException;
|
||||||
|
use Drupal\views\ViewStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Views API version string.
|
* 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.
|
* Returns whether the view is enabled.
|
||||||
*
|
*
|
||||||
* @param Drupal\views\ViewExecutable $view
|
* @param Drupal\views\ViewStorage $view
|
||||||
* The view object to check.
|
* The view object to check.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* Returns TRUE if a view is enabled, FALSE otherwise.
|
* 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();
|
return $view->isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the view is disabled.
|
* Returns whether the view is disabled.
|
||||||
*
|
*
|
||||||
* @param Drupal\views\ViewExecutable $view
|
* @param Drupal\views\ViewStorage $view
|
||||||
* The view object to check.
|
* The view object to check.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* Returns TRUE if a view is disabled, FALSE otherwise.
|
* 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();
|
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.
|
* Loads a view from configuration.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue