diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -28,7 +28,7 @@ /** * The enabled/disabled status of the configuration entity. * - * @var string + * @var bool */ public $status; @@ -99,6 +99,7 @@ */ public function enable() { $this->status = TRUE; + return $this; } /** @@ -106,13 +107,14 @@ */ public function disable() { $this->status = FALSE; + return $this; } /** * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::status(). */ public function status() { - return !empty($this->status); + return (bool) $this->status; } /** diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -33,17 +33,23 @@ public function setOriginalID($id); /** - * Sets the configuration entity status to enabled. + * Enables the configuration entity. + * + * @return \Drupal\Core\Config\Entity\ConfigEntityInterface + * The configuration entity. */ public function enable(); /** - * Sets the configuration entity status to disabled. + * Disables the configuration entity. + * + * @return \Drupal\Core\Config\Entity\ConfigEntityInterface + * The configuration entity. */ public function disable(); /** - * Returns the status of the configuration entity. + * Returns whether the configuration entity is enabled. * * @return bool */ diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -30,25 +30,24 @@ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); $uri = $entity->uri(); - $path = $uri['path']; - if (!$entity->status()) { - $operations['enable'] = array( - 'title' => t('Enable'), - 'ajax' => TRUE, - 'token' => TRUE, - 'href' => $uri['path'] . '/enable', - 'weight' => -10, - ); - } - else { - $operations['disable'] = array( - 'title' => t('Disable'), - 'ajax' => TRUE, - 'token' => TRUE, - 'href' => $uri['path'] . '/disable', - 'weight' => 10, - ); + if ($this->getStorageController()->statusKey()) { + if (!$entity->status()) { + $operations['enable'] = array( + 'title' => t('Enable'), + 'href' => $uri['path'] . '/enable', + 'options' => $uri['options'], + 'weight' => -10, + ); + } + else { + $operations['disable'] = array( + 'title' => t('Disable'), + 'href' => $uri['path'] . '/disable', + 'options' => $uri['options'], + 'weight' => 20, + ); + } } return $operations; diff -u b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php --- b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -57,7 +57,7 @@ protected $uuidKey = 'uuid'; /** - * Name of the entity's status key or FALSE if statuses are not supported. + * Name of the entity's status key or FALSE if a status is not supported. * * @var string|bool */ @@ -74,7 +74,6 @@ $this->hookLoadArguments = array(); $this->idKey = $this->entityInfo['entity_keys']['id']; - // @todo Enforce this and uuid keys on configuration entities. if (isset($this->entityInfo['entity_keys']['status'])) { $this->statusKey = $this->entityInfo['entity_keys']['status']; } @@ -248,8 +247,8 @@ $entity->{$this->uuidKey} = $uuid->generate(); } - // Assign a status. - if ($this->statusKey) { + // Default status to enabled. + if (!empty($this->statusKey) && !isset($entity->{$this->statusKey})) { $entity->{$this->statusKey} = TRUE; } diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php @@ -53,23 +53,23 @@ $uri = $entity->uri(); $expected_operations = array( 'edit' => array ( - 'title' => 'Edit', + 'title' => t('Edit'), 'href' => $uri['path'] . '/edit', 'options' => $uri['options'], 'weight' => 10, ), + 'disable' => array( + 'title' => t('Disable'), + 'href' => $uri['path'] . '/disable', + 'options' => $uri['options'], + 'weight' => 20, + ), 'delete' => array ( - 'title' => 'Delete', + 'title' => t('Delete'), 'href' => $uri['path'] . '/delete', 'options' => $uri['options'], 'weight' => 100, ), - 'disable' => array( - 'title' => 'Disable', - 'options' => $uri['options'], - 'href' => $uri['path'] . '/disable', - 'weight' => 10, - ), ); $actual_operations = $controller->getOperations($entity); diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusTest.php @@ -2,18 +2,18 @@ /** * @file - * Definition of Drupal\config\Tests\ConfigEntityStatusTest. + * Contains Drupal\config\Tests\ConfigEntityStatusTest. */ namespace Drupal\config\Tests; use Drupal\Core\Entity\EntityMalformedException; -use Drupal\simpletest\WebTestBase; +use Drupal\simpletest\DrupalUnitTestBase; /** - * Tests configuration entities. + * Tests configuration entity status functionality. */ -class ConfigEntityStatusTest extends WebTestBase { +class ConfigEntityStatusTest extends DrupalUnitTestBase { /** * Modules to enable. @@ -24,8 +24,8 @@ public static function getInfo() { return array( - 'name' => 'Configuration entity statuses', - 'description' => 'Tests configuration entity enabled/disabled status functionality.', + 'name' => 'Configuration entity status', + 'description' => 'Tests configuration entity status functionality.', 'group' => 'Configuration', ); } @@ -34,42 +34,21 @@ * Test the enabling/disabling of entities. */ function testCRUD() { - $new = entity_create('config_test', array('id' => strtolower($this->randomName()))); - $new->save(); + $entity = entity_create('config_test', array( + 'id' => strtolower($this->randomName()), + )); + $this->assertTrue($entity->status(), 'Default status is enabled.'); + $entity->save(); + $this->assertTrue($entity->status(), 'Status is enabled after saving.'); - $this->assertTrue($new->status(), 'The entity is enabled by default.'); - $new->disable(); - $new->save(); - $this->assertFalse($new->status(), 'The entity is disabled.'); - $new->enable(); - $new->save(); - $this->assertTrue($new->status(), 'The entity is enabled.'); - } + $entity->disable()->save(); + $this->assertFalse($entity->status(), 'Entity is disabled after disabling.'); - /** - * Tests Status operations through the UI. - */ - function testStatusUI() { - $id = strtolower($this->randomName()); - $edit = array( - 'id' => $id, - 'label' => $this->randomName(), - ); - $this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); + $entity->enable()->save(); + $this->assertTrue($entity->status(), 'Entity is enabled after enabling.'); - // Disable an entity. - $disable_path = "admin/structure/config_test/manage/$id/disable"; - $this->assertLinkByHref($disable_path); - $this->drupalGet($disable_path); - $this->assertResponse(200); - $this->assertNoLinkByHref($disable_path); - - // Enable an entity. - $enable_path = "admin/structure/config_test/manage/$id/enable"; - $this->assertLinkByHref($enable_path); - $this->drupalGet($enable_path); - $this->assertResponse(200); - $this->assertNoLinkByHref($enable_path); + $entity = entity_load('config_test', $entity->id()); + $this->assertTrue($entity->status(), 'Status is enabled after reload.'); } } diff -u b/core/modules/config/tests/config_test/config/config_test.dynamic.default.yml b/core/modules/config/tests/config_test/config/config_test.dynamic.default.yml --- b/core/modules/config/tests/config_test/config/config_test.dynamic.default.yml +++ b/core/modules/config/tests/config_test/config/config_test.dynamic.default.yml @@ -2,4 +2,3 @@ label: Default -# Intentionally commented out, as status should default to TRUE upon entity -# creation. +# Intentionally commented out to verify default status behavior. # status: 1 diff -u b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php --- b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php @@ -131,7 +131,6 @@ $view->save(); $view->storage->enable(); - $view->storage->save(); // Force the rebuild of the menu. menu_router_rebuild(); diff -u b/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php b/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php --- b/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php @@ -177,6 +177,8 @@ /** * Tests view enable and disable procedural wrapper functions. + * + * @todo This test is obsolete; remove it. */ function testStatusFunctions() { $view = views_get_view('test_view_status')->storage; reverted: --- b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -102,9 +102,9 @@ // Test the enable/disable status of a display. $view->display_handler->setOption('enabled', FALSE); + $this->assertFalse($view->display_handler->isEnabled(), 'Make sure that isEnabled returns FALSE on a disabled display.'); - $this->assertFalse($view->display_handler->status(), 'Make sure that isEnabled returns FALSE on a disabled display.'); $view->display_handler->setOption('enabled', TRUE); + $this->assertTrue($view->display_handler->isEnabled(), 'Make sure that isEnabled returns TRUE on a disabled display.'); - $this->assertTrue($view->display_handler->status(), 'Make sure that isEnabled returns TRUE on a disabled display.'); } /** diff -u b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php --- b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php @@ -207,6 +207,8 @@ /** * Tests statuses of configuration entities. + * + * @todo This test is obsolete; remove it. */ protected function statusTests() { // Test a View can be enabled and disabled again (with a new view). diff -u b/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php --- b/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -1160,7 +1160,7 @@ } // Don't allow to use deactivated displays, but display them on the live preview. - if (!$this->display_handler->status() && empty($this->live_preview)) { + if (!$this->display_handler->isEnabled() && empty($this->live_preview)) { $this->build_info['fail'] = TRUE; return FALSE; } diff -u b/core/modules/views/views.module b/core/modules/views/views.module --- b/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -1396,7 +1396,7 @@ // This view uses_hook_menu. Clone it so that different handlers // don't trip over each other, and add it to the list. $v = $view->get('executable')->cloneView(); - if ($v->setDisplay($id) && $v->display_handler->status()) { + if ($v->setDisplay($id) && $v->display_handler->isEnabled()) { $result[] = array($v, $id); } // In PHP 4.4.7 and presumably earlier, if we do not unset $v @@ -1521,6 +1521,8 @@ * * @return bool * Returns TRUE if a view is enabled, FALSE otherwise. + * + * @todo Obsolete helper function; remove in favor of ::status() method. */ function views_view_is_enabled(View $view) { return $view->status(); @@ -1534,6 +1536,8 @@ * * @return bool * Returns TRUE if a view is disabled, FALSE otherwise. + * + * @todo Obsolete helper function; remove in favor of ::status() method. */ function views_view_is_disabled(View $view) { return !$view->status(); @@ -1544,6 +1548,8 @@ * * @param Drupal\views\Plugin\Core\Entity\View $view * The View object to disable. + * + * @todo Obsolete helper function; remove in favor of ::enable() method. */ function views_enable_view(View $view) { $view->enable(); @@ -1554,6 +1560,8 @@ * * @param Drupal\views\Plugin\Core\Entity\View $view * The View object to disable. + * + * @todo Obsolete helper function; remove in favor of ::disable() method. */ function views_disable_view(View $view) { $view->disable(); reverted: --- b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -139,7 +139,7 @@ // Add a text that the display is disabled. if (!empty($view->get('executable')->displayHandlers[$display_id])) { + if (!$view->get('executable')->displayHandlers[$display_id]->isEnabled()) { - if (!$view->get('executable')->displayHandlers[$display_id]->status()) { $form['displays']['settings']['disabled']['#markup'] = t('This display is disabled.'); } } @@ -155,7 +155,7 @@ $tab_content['#attributes']['class'][] = 'views-display-deleted'; } // Mark disabled displays as such. + if (isset($view->get('executable')->displayHandlers[$display_id]) && !$view->get('executable')->displayHandlers[$display_id]->isEnabled()) { - if (isset($view->get('executable')->displayHandlers[$display_id]) && !$view->get('executable')->displayHandlers[$display_id]->status()) { $tab_content['#attributes']['class'][] = 'views-display-disabled'; } $form['displays']['settings']['settings_content'] = array( @@ -350,7 +350,7 @@ // The master display cannot be cloned. $is_default = $display['id'] == 'default'; // @todo: Figure out why getOption doesn't work here. + $is_enabled = $view->get('executable')->displayHandlers[$display['id']]->isEnabled(); - $is_enabled = $view->get('executable')->displayHandlers[$display['id']]->status(); if ($display['id'] != 'default') { $build['top']['#theme_wrappers'] = array('container'); diff -u b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php --- b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -79,7 +79,9 @@ } /** - * Implements Drupal\Core\Entity\EntityListController::getOperations(); + * Implements Drupal\Core\Entity\EntityListController::getOperations(). + * + * @todo Obsolete after extending from ConfigEntityListController. */ public function getOperations(EntityInterface $view) { $uri = $view->uri(); only in patch2: unchanged: --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusUITest.php @@ -0,0 +1,59 @@ + 'Configuration entity status UI', + 'description' => 'Tests configuration entity status UI functionality.', + 'group' => 'Configuration', + ); + } + + /** + * Tests status operations. + */ + function testCRUD() { + $id = strtolower($this->randomName()); + $edit = array( + 'id' => $id, + 'label' => $this->randomName(), + ); + $this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); + + // Disable an entity. + $disable_path = "admin/structure/config_test/manage/$id/disable"; + $this->assertLinkByHref($disable_path); + $this->drupalGet($disable_path); + $this->assertResponse(200); + $this->assertNoLinkByHref($disable_path); + + // Enable an entity. + $enable_path = "admin/structure/config_test/manage/$id/enable"; + $this->assertLinkByHref($enable_path); + $this->drupalGet($enable_path); + $this->assertResponse(200); + $this->assertNoLinkByHref($enable_path); + } + +} only in patch2: unchanged: --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -1055,7 +1055,7 @@ public function disable() { * Implements \Drupal\views\ViewStorageInterface::isEnabled(). */ public function isEnabled() { - return $this->__call(__FUNCTION__, func_get_args()); + return $this->__call('status', func_get_args()); } /**