Commit 1c92546e authored by catch's avatar catch

Issue #1826602 by damiankloip, xjm, sun, dawehner, EclipseGc: Allow all...

Issue #1826602 by damiankloip, xjm, sun, dawehner, EclipseGc: Allow all configuration entities to be enabled/disabled.
parent b726e434
......@@ -26,6 +26,13 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
*/
protected $originalID;
/**
* The enabled/disabled status of the configuration entity.
*
* @var bool
*/
public $status;
/**
* Overrides Entity::__construct().
*/
......@@ -88,6 +95,29 @@ public function set($property_name, $value, $langcode = NULL) {
$this->{$property_name} = $value;
}
/**
* Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::enable().
*/
public function enable() {
$this->status = TRUE;
return $this;
}
/**
* Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::disable().
*/
public function disable() {
$this->status = FALSE;
return $this;
}
/**
* Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::status().
*/
public function status() {
return !empty($this->status);
}
/**
* Overrides Entity::createDuplicate().
*/
......
......@@ -32,4 +32,27 @@ public function getOriginalID();
*/
public function setOriginalID($id);
/**
* Enables the configuration entity.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityInterface
* The configuration entity.
*/
public function enable();
/**
* Disables the configuration entity.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityInterface
* The configuration entity.
*/
public function disable();
/**
* Returns whether the configuration entity is enabled.
*
* @return bool
*/
public function status();
}
......@@ -7,6 +7,7 @@
namespace Drupal\Core\Config\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListController;
/**
......@@ -23,4 +24,31 @@ public function load() {
return $entities;
}
/**
* Overrides \Drupal\Core\Entity\EntityListController::getOperations();
*/
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
$uri = $entity->uri();
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;
}
}
......@@ -57,6 +57,13 @@ class ConfigStorageController implements EntityStorageControllerInterface {
*/
protected $uuidKey = 'uuid';
/**
* Name of the entity's status key or FALSE if a status is not supported.
*
* @var string|bool
*/
protected $statusKey = 'status';
/**
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::__construct().
*
......@@ -67,6 +74,13 @@ public function __construct($entityType) {
$this->entityInfo = entity_get_info($entityType);
$this->hookLoadArguments = array();
$this->idKey = $this->entityInfo['entity_keys']['id'];
if (isset($this->entityInfo['entity_keys']['status'])) {
$this->statusKey = $this->entityInfo['entity_keys']['status'];
}
else {
$this->statusKey = FALSE;
}
}
/**
......@@ -248,6 +262,11 @@ public function create(array $values) {
// entity object, for instance to fill-in default values.
$this->invokeHook('create', $entity);
// Default status to enabled.
if (!empty($this->statusKey) && !isset($entity->{$this->statusKey})) {
$entity->{$this->statusKey} = TRUE;
}
return $entity;
}
......
......@@ -147,6 +147,6 @@ display:
display_options:
path: test_bulk_form
base_field: nid
disabled: '0'
status: '1'
module: views
langcode: und
......@@ -365,19 +365,17 @@ function _block_rehash($theme = NULL) {
$blocks = entity_load_multiple_by_properties('block', array('theme' => $theme));
foreach ($blocks as $block_id => $block) {
$region = $block->get('region');
$status = $block->get('status');
$status = $block->status();
// Disable blocks in invalid regions.
if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status == 1) {
if (!empty($region) && $region != BLOCK_REGION_NONE && !isset($regions[$region]) && $status) {
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block_id, '%region' => $region)), 'warning');
// Disabled modules are moved into the BLOCK_REGION_NONE later so no
// need to move the block to another region.
$block->set('status', 0);
$block->save();
$block->disable()->save();
}
// Set region to none if not enabled and make sure status is set.
if (empty($status)) {
// Set region to none if not enabled.
if (!$status) {
$block->set('region', BLOCK_REGION_NONE);
$block->set('status', 0);
$block->save();
}
}
......
......@@ -31,7 +31,8 @@
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* "uuid" = "uuid",
* "status" = "status"
* }
* )
*/
......@@ -100,13 +101,6 @@ class Block extends ConfigEntityBase {
*/
protected $module;
/**
* The status of this block.
*
* @var bool
*/
protected $status = TRUE;
/**
* The plugin instance ID.
*
......
......@@ -2,7 +2,7 @@ base_field: id
base_table: views_test_data
core: 8.x
description: ''
disabled: '0'
status: '1'
display:
default:
display_plugin: default
......
......@@ -2,7 +2,7 @@ base_field: id
base_table: views_test_data
core: 8.x
description: ''
disabled: '0'
status: '1'
display:
default:
display_plugin: default
......
......@@ -2,7 +2,7 @@ base_field: cid
base_table: comment
core: 8.x
description: ''
disabled: '0'
status: '1'
display:
default:
display_plugin: default
......
base_table: node
core: '8'
description: ''
disabled: '0'
status: '1'
display:
default:
display_options:
......
......@@ -54,20 +54,29 @@ function testList() {
$uri = $entity->uri();
$expected_operations = array(
'edit' => array (
'title' => 'Edit',
'href' => 'admin/structure/config_test/manage/default/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',
'href' => 'admin/structure/config_test/manage/default/delete',
'title' => t('Delete'),
'href' => $uri['path'] . '/delete',
'options' => $uri['options'],
'weight' => 100,
),
);
$actual_operations = $controller->getOperations($entity);
$this->assertIdentical($expected_operations, $actual_operations, 'Return value from getOperations matches expected.');
// Sort the operations to normalize link order.
uasort($actual_operations, 'drupal_sort_weight');
$this->assertIdentical($expected_operations, $actual_operations);
// Test buildHeader() method.
$expected_items = array(
......
<?php
/**
* @file
* Contains \Drupal\config\Tests\ConfigEntityStatusTest.
*/
namespace Drupal\config\Tests;
use Drupal\simpletest\DrupalUnitTestBase;
/**
* Tests configuration entity status functionality.
*/
class ConfigEntityStatusTest extends DrupalUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('config_test');
public static function getInfo() {
return array(
'name' => 'Configuration entity status',
'description' => 'Tests configuration entity status functionality.',
'group' => 'Configuration',
);
}
/**
* Tests the enabling/disabling of entities.
*/
function testCRUD() {
$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.');
$entity->disable()->save();
$this->assertFalse($entity->status(), 'Entity is disabled after disabling.');
$entity->enable()->save();
$this->assertTrue($entity->status(), 'Entity is enabled after enabling.');
$entity = entity_load('config_test', $entity->id());
$this->assertTrue($entity->status(), 'Status is enabled after reload.');
}
}
<?php
/**
* @file
* Contains \Drupal\config\Tests\ConfigEntityStatusUITest.
*/
namespace Drupal\config\Tests;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\simpletest\WebTestBase;
/**
* Tests configuration entity status UI functionality.
*/
class ConfigEntityStatusUITest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('config_test');
public static function getInfo() {
return array(
'name' => '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');
$uri = entity_load('config_test', $id)->uri();
// Disable an entity.
$disable_path = "{$uri['path']}/disable";
$this->assertLinkByHref($disable_path);
$this->drupalGet($disable_path);
$this->assertResponse(200);
$this->assertNoLinkByHref($disable_path);
// Enable an entity.
$enable_path = "{$uri['path']}/enable";
$this->assertLinkByHref($enable_path);
$this->drupalGet($enable_path);
$this->assertResponse(200);
$this->assertNoLinkByHref($enable_path);
}
}
......@@ -107,6 +107,7 @@ function testNew() {
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'label' => 'New',
'style' => '',
'status' => '1',
'langcode' => 'und',
'protected_property' => '',
);
......
......@@ -59,6 +59,7 @@ function testImport() {
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'label' => 'New',
'style' => '',
'status' => '1',
'langcode' => 'und',
'protected_property' => '',
);
......
id: default
label: Default
protected_property: Default
# Intentionally commented out to verify default status behavior.
# status: 1
......@@ -6,6 +6,7 @@
*/
use Drupal\config_test\Plugin\Core\Entity\ConfigTest;
use Symfony\Component\HttpFoundation\RedirectResponse;
require_once dirname(__FILE__) . '/config_test.hooks.inc';
......@@ -54,6 +55,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;
}
......@@ -146,3 +159,29 @@ function config_test_config_test_create(ConfigTest $config_test) {
$config_test->set('foo', 'baz');
}
}
/**
* Enables a ConfigTest object.
*
* @param Drupal\config_test\ConfigTest $config_test
* The ConfigTest object to enable.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse.
*/
function config_test_entity_enable(ConfigTest $config_test) {
$config_test->enable()->save();
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.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse.
*/
function config_test_entity_disable(ConfigTest $config_test) {
$config_test->disable()->save();
return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE)));
}
......@@ -28,7 +28,8 @@
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* "uuid" = "uuid",
* "status" = "status"
* }
* )
*/
......
base_table: node
core: '8'
description: ''
disabled: '0'
status: '1'
display:
default:
display_options:
......
......@@ -217,8 +217,7 @@ function filter_format_load($format_id) {
* The text format object to be disabled.
*/
function filter_format_disable($format) {
$format->status = 0;
$format->save();
$format->disable()->save();
// Allow modules to react on text format deletion.
module_invoke_all('filter_format_disable', $format);
......@@ -351,7 +350,7 @@ function filter_formats($account = NULL) {
$filter_formats = entity_load_multiple('filter_format');
$formats['all'] = array();
foreach ($filter_formats as $format_name => $filter_format) {
if (!empty($filter_format->status)) {
if ($filter_format->status()) {
$formats['all'][$format_name] = $filter_format;
}
}
......@@ -776,7 +775,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
if (in_array($filter_info[$name]['type'], $filter_types_to_skip)) {
continue;
}
if ($filter->status && isset($filter_info[$name]['prepare callback'])) {
if (!empty($filter->status) && isset($filter_info[$name]['prepare callback'])) {
$function = $filter_info[$name]['prepare callback'];
$text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
}
......@@ -788,7 +787,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE,
if (in_array($filter_info[$name]['type'], $filter_types_to_skip)) {
continue;
}
if ($filter->status && isset($filter_info[$name]['process callback'])) {
if (!empty($filter->status) && isset($filter_info[$name]['process callback'])) {
$function = $filter_info[$name]['process callback'];
$text = $function($text, $filter, $format, $langcode, $cache, $cache_id);
}
......@@ -1062,7 +1061,7 @@ function _filter_tips($format_id, $long = FALSE) {
$filters = filter_list_format($format->format);
$tips[$format->name] = array();
foreach ($filters as $name => $filter) {
if ($filter->status && isset($filter_info[$name]['tips callback'])) {
if (!empty($filter->status) && isset($filter_info[$name]['tips callback'])) {
$tip = $filter_info[$name]['tips callback']($filter, $format, $long);
if (isset($tip)) {
$tips[$format->name][$name] = array('tip' => $tip, 'id' => $name);
......
......@@ -23,7 +23,8 @@
* entity_keys = {
* "id" = "format",
* "label" = "name",
* "uuid" = "uuid"
* "uuid" = "uuid",
* "status" = "status"
* }
* )
*/
......@@ -58,13 +59,6 @@ class FilterFormat extends ConfigEntityBase {
*/
public $uuid;
/**
* Whether the text format is enabled or disabled.
*
* @var bool
*/
public $status = 1;
/**
* Weight of this format in the text format selector.
*
......
......@@ -33,9 +33,6 @@ public static function getInfo() {
* Tests the status extra filter.
*/
public function testStatusExtra() {
// @todo For whatever reason the menu has to be rebuilt or drupalGet will
// fail.
state()->set('menu_rebuild_needed', TRUE);
$column_map = array('nid' => 'nid');
$node_author = $this->drupalCreateUser(array('view own unpublished content'));
$node_author_not_unpublished = $this->drupalCreateUser();
......
base_table: node
core: '8'
description: ''
disabled: '0'
status: '1'
display:
default:
display_options:
......
base_table: node
core: 8.0-dev
description: ''
disabled: '0'
status: '1'
display:
default:
display_options:
......
......@@ -132,6 +132,6 @@ display:
id: page
position: '0'
base_field: nid
disabled: '0'
status: '1'
module: views
langcode: und
......@@ -44,6 +44,6 @@ display:
access: false
path: test/serialize/entity
base_field: id
disabled: '0'
status: '1'
module: rest
langcode: und
......@@ -91,6 +91,6 @@ display:
row:
type: data_field
base_field: id
disabled: '0'
status: '1'
module: rest
langcode: und
......@@ -2,7 +2,7 @@ base_field: tid
base_table: taxonomy_term_data
core: 8.0-dev
description: ''
disabled: '0'
status: '1'
display:
default:
display_options:
......
base_table: node
core: '8'
description: ''
disabled: '0'
status: '1'
display:
default:
display_options:
......