diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 330f39c..bad7ca5 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -26,6 +26,13 @@ protected $originalID; /** + * Returns whether the configuration entity's status is disabled or not. + * + * @var bool + */ + public $disabled; + + /** * Overrides Entity::__construct(). */ public function __construct(array $values, $entity_type) { @@ -37,6 +44,8 @@ public function __construct(array $values, $entity_type) { if ($original_id !== NULL && $original_id !== '') { $this->setOriginalID($original_id); } + + $this->disabled = !$this->isEnabled(); } /** @@ -53,6 +62,28 @@ public function setOriginalID($id) { $this->originalID = $id; } + /* + * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::enable(). + */ + public function enable() { + return entity_get_controller($this->entityType)->enable($this); + } + + /** + * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::disable(). + */ + public function disable() { + return entity_get_controller($this->entityType)->disable($this); + } + + /** + * Implements Drupal\Core\Config\Entity\ConfigEntityInterface::isEnabled(). + */ + public function isEnabled() { + $disabled = entity_get_controller($this->entityType)->getStatus($this); + return ($disabled !== NULL) ? !$disabled : !$this->disabled; + } + /** * Overrides Entity::isNew(). * diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php index 15ef4dd..9321404 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityInterface.php @@ -32,4 +32,21 @@ public function getOriginalID(); */ public function setOriginalID($id); + /* + * Sets the configuration entity status to enabled. + */ + public function enable(); + + /** + * Sets the configuration entity status to disabled. + */ + public function disable(); + + /** + * Returns whether the configuration entity is enabled. + * + * @return bool + */ + public function isEnabled(); + } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php index 3977310..0c7afa9 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityListController.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Config\Entity; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListController; /** @@ -23,4 +24,34 @@ public function load() { return $entities; } + /** + * Overrides Drupal\Core\Entity\EntityListController::getOperations(); + */ + public function getOperations(EntityInterface $entity) { + $operations = parent::getOperations($entity); + $uri = $entity->uri(); + $path = $uri['path']; + + 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, + ); + } + + return $operations; + } + } diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index f37acd3..7cecfdc 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -322,6 +322,45 @@ public function save(EntityInterface $entity) { } /** + * Enables a configuration entity. + * + * @param Drupal\Core\Entity\EntityInterface $entity + */ + public function enable(EntityInterface $entity) { + return $this->setStatus($entity, FALSE); + } + + /** + * Disables a configuration entity. + * + * @param Drupal\Core\Entity\EntityInterface $entity + */ + public function disable(EntityInterface $entity) { + return $this->setStatus($entity, TRUE); + } + + /** + * [getStatus description] + * @param Drupal\Core\Entity\EntityInterface $entity + */ + public function getStatus(EntityInterface $entity) { + $config = config($this->entityInfo['config status name']); + return $config->get($entity->id()); + } + + /** + * [setStatus description] + * + * @param Drupal\Core\Entity\EntityInterface $entity + * @param bool $status + */ + protected function setStatus(EntityInterface $entity, $status) { + $config = config($this->entityInfo['config status name']); + $config->set($entity->id(), $status); + return $config->save(); + } + + /** * Retrieves the exportable properties of an entity. * * @param \Drupal\Core\Entity\EntityInterface $entity diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index bb98ac0..e87d51d 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -252,6 +252,27 @@ function testCRUDUI() { $this->assertNoLinkByHref("admin/structure/config_test/manage/$id/edit"); $id = $edit['id']; $this->assertLinkByHref("admin/structure/config_test/manage/$id/edit"); + + $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); } } diff --git a/core/modules/config/tests/config_test/config_test.module b/core/modules/config/tests/config_test/config_test.module index d73f64a..7179beb 100644 --- a/core/modules/config/tests/config_test/config_test.module +++ b/core/modules/config/tests/config_test/config_test.module @@ -6,6 +6,7 @@ */ use Drupal\config_test\ConfigTest; +use Symfony\Component\HttpFoundation\RedirectResponse; require_once dirname(__FILE__) . '/config_test.hooks.inc'; @@ -85,6 +86,7 @@ function config_test_entity_info() { ), 'uri callback' => 'config_test_uri', 'config prefix' => 'config_test.dynamic', + 'config status name' => 'entity_status.config_test.config_test', 'entity keys' => array( 'id' => 'id', 'label' => 'label', @@ -139,6 +141,18 @@ function config_test_menu() { 'access callback' => TRUE, 'type' => MENU_LOCAL_TASK, ); + $items['admin/structure/config_test/manage/%config_test/enable'] = array( + 'title' => 'Enable', + 'page callback' => 'config_test_entity_enable', + 'page arguments' => array(4), + 'access callback' => TRUE, + ); + $items['admin/structure/config_test/manage/%config_test/disable'] = array( + 'title' => 'Disable', + 'page callback' => 'config_test_entity_disable', + 'page arguments' => array(4), + 'access callback' => TRUE, + ); return $items; } @@ -211,3 +225,25 @@ function config_test_delete_form_submit($form, &$form_state) { drupal_set_message(format_string('%label configuration has been deleted.', array('%label' => $form_state['config_test']->label()))); $form_state['redirect'] = 'admin/structure/config_test'; } + +/** + * Enables a ConfigTest object. + * + * @param Drupal\config_test\ConfigTest $config_test + * The ConfigTest object to enable. + */ +function config_test_entity_enable(ConfigTest $config_test) { + $config_test->enable(); + return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE))); +} + +/** + * Disables a ConfigTest object. + * + * @param Drupal\config_test\ConfigTest $config_test + * The ConfigTest object to disable. + */ +function config_test_entity_disable(ConfigTest $config_test) { + $config_test->disable(); + return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE))); +} diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 5dab988..47f3a96 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -1174,6 +1174,7 @@ function image_entity_info() { 'controller class' => 'Drupal\Core\Config\Entity\ConfigStorageController', 'uri callback' => 'image_style_uri', 'config prefix' => 'image.style', + 'config status name' => 'entity_status.image.image_style', 'entity keys' => array( 'id' => 'name', 'label' => 'label', diff --git a/core/modules/views/lib/Drupal/views/ViewStorage.php b/core/modules/views/lib/Drupal/views/ViewStorage.php index 5b06a41..0584f45 100644 --- a/core/modules/views/lib/Drupal/views/ViewStorage.php +++ b/core/modules/views/lib/Drupal/views/ViewStorage.php @@ -85,16 +85,6 @@ class ViewStorage extends ConfigEntityBase implements ViewStorageInterface { public $base_field = 'nid'; /** - * Returns whether the view's status is disabled or not. - * - * This value is used for exported view, to provide some default views which - * aren't enabled. - * - * @var bool - */ - public $disabled = FALSE; - - /** * The UUID for this entity. * * @var string @@ -185,29 +175,6 @@ public function id() { } /** - * Implements Drupal\views\ViewStorageInterface::enable(). - */ - public function enable() { - $this->disabled = FALSE; - $this->save(); - } - - /** - * Implements Drupal\views\ViewStorageInterface::disable(). - */ - public function disable() { - $this->disabled = TRUE; - $this->save(); - } - - /** - * Implements Drupal\views\ViewStorageInterface::isEnabled(). - */ - public function isEnabled() { - return !$this->disabled; - } - - /** * Return the human readable name for a view. * * When a certain view doesn't have a human readable name return the machine readable name. diff --git a/core/modules/views/lib/Drupal/views/ViewStorageInterface.php b/core/modules/views/lib/Drupal/views/ViewStorageInterface.php index b29fa03..94d79cd 100644 --- a/core/modules/views/lib/Drupal/views/ViewStorageInterface.php +++ b/core/modules/views/lib/Drupal/views/ViewStorageInterface.php @@ -13,22 +13,4 @@ * Defines an interface for View storage classes. */ interface ViewStorageInterface extends ConfigEntityInterface { - - /** - * Sets the configuration entity status to enabled. - */ - public function enable(); - - /** - * Sets the configuration entity status to disabled. - */ - public function disable(); - - /** - * Returns whether the configuration entity is enabled. - * - * @return bool - */ - public function isEnabled(); - } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 52de65c..a7b4bea 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -34,6 +34,7 @@ function views_entity_info() { 'default' => 'Drupal\node\NodeFormController', ), 'config prefix' => 'views.view', + 'config status name' => 'entity_status.views.view', 'fieldable' => FALSE, 'entity keys' => array( 'id' => 'name',