diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 29be304..8272675 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -30,7 +30,7 @@ * * @var string */ - public $status = '1'; + public $status; /** * Overrides Entity::__construct(). @@ -98,22 +98,21 @@ public function set($property_name, $value, $langcode = NULL) { * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::enable(). */ public function enable() { - $this->status = '1'; + $this->status = TRUE; } /** * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::disable(). */ public function disable() { - $this->status = '0'; + $this->status = FALSE; } /** - * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::isEnabled(). + * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::status(). */ - public function isEnabled() { - $status_key = entity_get_controller($this->entityType)->statusKey(); - return isset($status_key) ? $this->status : TRUE; + public function status() { + return !empty($this->status); } /** diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index 9321404..3c42b1c 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -32,7 +32,7 @@ public function getOriginalID(); */ public function setOriginalID($id); - /* + /** * Sets the configuration entity status to enabled. */ public function enable(); @@ -43,10 +43,10 @@ public function enable(); public function disable(); /** - * Returns whether the configuration entity is enabled. + * Returns the status of the configuration entity. * * @return bool */ - public function isEnabled(); + public function status(); } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php index 5c94696..4cc4084 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -32,25 +32,23 @@ public function getOperations(EntityInterface $entity) { $uri = $entity->uri(); $path = $uri['path']; - if ($this->getStorageController()->statusKey()) { - if (!$entity->isEnabled()) { - $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 (!$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, + ); } return $operations; diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index 0fd7998..cf215fb 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -74,6 +74,7 @@ public function __construct($entityType) { $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']; } @@ -247,14 +248,12 @@ public function create(array $values) { $entity->{$this->uuidKey} = $uuid->generate(); } - return $entity; - } + // Assign a status. + if ($this->statusKey) { + $entity->{$this->statusKey} = TRUE; + } - /** - * Returns the status key for this configuration entity type, if any. - */ - public function statusKey() { - return $this->statusKey; + return $entity; } /** diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php index 46f623b..f4950cd 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityListTest.php @@ -65,9 +65,8 @@ function testList() { 'weight' => 100, ), 'disable' => array( - 'title' => t('Disable'), - 'ajax' => TRUE, - 'token' => TRUE, + 'title' => 'Disable', + 'options' => $uri['options'], 'href' => $uri['path'] . '/disable', 'weight' => 10, ), diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigStatusEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusTest.php similarity index 89% rename from core/modules/config/lib/Drupal/config/Tests/ConfigStatusEntityTest.php rename to core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusTest.php index 3293be4..424f622 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigStatusEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityStatusTest.php @@ -37,13 +37,13 @@ function testCRUD() { $new = entity_create('config_test', array('id' => strtolower($this->randomName()))); $new->save(); - $this->assertTrue($new->isEnabled(), 'The entity is enabled.'); + $this->assertTrue($new->status(), 'The entity is enabled by default.'); $new->disable(); $new->save(); - $this->assertFalse($new->isEnabled(), 'The entity is disabled.'); + $this->assertFalse($new->status(), 'The entity is disabled.'); $new->enable(); $new->save(); - $this->assertTrue($new->isEnabled(), 'The entity is enabled.'); + $this->assertTrue($new->status(), 'The entity is enabled.'); } /** diff --git a/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 index 2ad95bd..45763e4 100644 --- a/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 @@ -1,3 +1,5 @@ id: default label: Default -status: 1 +# Intentionally commented out, as status should default to TRUE upon entity +# creation. +# status: 1 diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php index 62a4beb..6e2054f 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/Plugin/Core/Entity/ConfigTest.php @@ -63,11 +63,4 @@ class ConfigTest extends ConfigEntityBase { */ public $style; - /** - * The enabled/disabled status of the configuration entity. - * - * @var string - */ - public $status = '1'; - } diff --git a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php index 79a7c51..d998cd1 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Core/Entity/View.php @@ -325,7 +325,7 @@ public function getPaths() { foreach ($this->display as $display) { if (!empty($display['display_options']['path'])) { $path = $display['display_options']['path']; - if ($this->isEnabled() && strpos($path, '%') === FALSE) { + if ($this->status() && strpos($path, '%') === FALSE) { $all_paths[] = l('/' . $path, $path); } else { diff --git a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php index 0de18ac..81d3c70 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Handler/AreaTest.php @@ -131,6 +131,7 @@ public function testTitleArea() { $view->save(); $view->storage->enable(); + $view->storage->save(); // Force the rebuild of the menu. menu_router_rebuild(); diff --git a/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php b/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php index 67dfac6..5da3cb0 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ModuleTest.php @@ -181,15 +181,15 @@ public function testLoadFunctions() { function testStatusFunctions() { $view = views_get_view('test_view_status')->storage; - $this->assertFalse($view->isEnabled(), 'The view status is disabled.'); + $this->assertFalse($view->status(), '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.'); + $this->assertTrue($view->status(), 'A view has been enabled.'); + $this->assertEqual($view->status(), 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.'); + $this->assertFalse($view->status(), 'A view has been disabled.'); + $this->assertEqual(!$view->status(), views_view_is_disabled($view), 'views_view_is_disabled is correct.'); } /** diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php index b071b9e..08b3f46 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayTest.php @@ -102,9 +102,9 @@ function testDisplayPlugin() { // 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 --git a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php index d160acf..f6c0371 100644 --- a/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/ViewStorageTest.php @@ -214,7 +214,7 @@ protected function statusTests() { // The view should already be disabled. $view->enable(); - $this->assertTrue($view->isEnabled(), 'A view has been enabled.'); + $this->assertTrue($view->status(), 'A view has been enabled.'); // Check the saved values. $view->save(); @@ -223,7 +223,7 @@ protected function statusTests() { // Disable the view. $view->disable(); - $this->assertFalse($view->isEnabled(), 'A view has been disabled.'); + $this->assertFalse($view->status(), 'A view has been disabled.'); // Check the saved values. $view->save(); diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index 4ad1633..0da701e 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -1160,7 +1160,7 @@ public function execute($display_id = NULL) { } // Don't allow to use deactivated displays, but display them on the live preview. - if (!$this->display_handler->isEnabled() && empty($this->live_preview)) { + if (!$this->display_handler->status() && empty($this->live_preview)) { $this->build_info['fail'] = TRUE; return FALSE; } @@ -1511,7 +1511,7 @@ public function executeHookBlockList($display_id = NULL) { */ public function access($displays = NULL, $account = NULL) { // Noone should have access to disabled views. - if (!$this->storage->isEnabled()) { + if (!$this->storage->status()) { return FALSE; } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index cf10c1b..da4e038 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -640,7 +640,7 @@ function views_block_info() { $views = views_get_all_views(); foreach ($views as $view) { // disabled views get nothing. - if (!$view->isEnabled()) { + if (!$view->status()) { continue; } @@ -1378,7 +1378,7 @@ function views_get_applicable_views($type) { foreach ($views as $view) { // Skip disabled views. - if (!$view->isEnabled()) { + if (!$view->status()) { continue; } @@ -1396,7 +1396,7 @@ function views_get_applicable_views($type) { // 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->isEnabled()) { + if ($v->setDisplay($id) && $v->display_handler->status()) { $result[] = array($v, $id); } // In PHP 4.4.7 and presumably earlier, if we do not unset $v @@ -1523,7 +1523,7 @@ function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclu * Returns TRUE if a view is enabled, FALSE otherwise. */ function views_view_is_enabled(View $view) { - return $view->isEnabled(); + return $view->status(); } /** @@ -1536,7 +1536,7 @@ function views_view_is_enabled(View $view) { * Returns TRUE if a view is disabled, FALSE otherwise. */ function views_view_is_disabled(View $view) { - return !$view->isEnabled(); + return !$view->status(); } /** diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php index 853d5c9..06514ef 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewEditFormController.php @@ -139,7 +139,7 @@ public function form(array $form, array &$form_state, EntityInterface $view) { // 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 @@ public function form(array $form, array &$form_state, EntityInterface $view) { $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 @@ public function getDisplayDetails($view, $display) { // 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 --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php index ac8dc4e..7af6b94 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewListController.php @@ -21,8 +21,8 @@ class ViewListController extends EntityListController { public function load() { $entities = parent::load(); uasort($entities, function ($a, $b) { - $a_enabled = $a->isEnabled(); - $b_enabled = $b->isEnabled(); + $a_enabled = $a->status(); + $b_enabled = $b->status(); if ($a_enabled != $b_enabled) { return $a_enabled < $b_enabled; } @@ -46,7 +46,7 @@ public function buildRow(EntityInterface $view) { ), ), 'title' => t('Machine name: ') . $view->id(), - 'class' => array($view->isEnabled() ? 'views-ui-list-enabled' : 'views-ui-list-disabled'), + 'class' => array($view->status() ? 'views-ui-list-enabled' : 'views-ui-list-disabled'), ); } @@ -90,7 +90,7 @@ public function getOperations(EntityInterface $view) { 'href' => "$path/edit", 'weight' => -5, ); - if (!$view->isEnabled()) { + if (!$view->status()) { $definition['enable'] = array( 'title' => t('Enable'), 'ajax' => TRUE,