Commit 5cd540a5 authored by webchick's avatar webchick

Issue #2286681 by alexpott, tim.plunkett: Fixed Make public properties on...

Issue #2286681 by alexpott, tim.plunkett: Fixed Make public properties on ConfigEntityBase protected.
parent d7efdaa9
......@@ -55,14 +55,14 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
*
* @var bool
*/
public $status = TRUE;
protected $status = TRUE;
/**
* The UUID for this entity.
*
* @var string
*/
public $uuid;
protected $uuid;
/**
* Whether the config is being created, updated or deleted through the
......@@ -84,7 +84,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
*
* @var string
*/
public $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
protected $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
/**
* Overrides Entity::__construct().
......
......@@ -58,13 +58,6 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
*/
protected $uuidKey = 'uuid';
/**
* Name of the entity's status key or FALSE if a status is not supported.
*
* @var string|bool
*/
protected $statusKey = 'status';
/**
* The config factory service.
*
......@@ -103,8 +96,6 @@ class ConfigEntityStorage extends EntityStorageBase implements ConfigEntityStora
public function __construct(EntityTypeInterface $entity_type, ConfigFactoryInterface $config_factory, StorageInterface $config_storage, UuidInterface $uuid_service, LanguageManagerInterface $language_manager) {
parent::__construct($entity_type);
$this->statusKey = $this->entityType->getKey('status');
$this->configFactory = $config_factory;
$this->configStorage = $config_storage;
$this->uuidService = $uuid_service;
......@@ -186,10 +177,6 @@ protected function doCreate(array $values) {
$values += array('langcode' => $this->languageManager->getDefaultLanguage()->id);
$entity = new $this->entityClass($values, $this->entityTypeId);
// Default status to enabled.
if (!empty($this->statusKey) && !isset($entity->{$this->statusKey})) {
$entity->{$this->statusKey} = TRUE;
}
return $entity;
}
......
......@@ -1594,7 +1594,7 @@ static protected function _generateFieldTableName(FieldConfigInterface $field, $
$separator = $revision ? '_r__' : '__';
// Truncate to the same length for the current and revision tables.
$entity_type = substr($field->entity_type, 0, 34);
$field_hash = substr(hash('sha256', $field->uuid), 0, 10);
$field_hash = substr(hash('sha256', $field->uuid()), 0, 10);
$table_name = $entity_type . $separator . $field_hash;
}
return $table_name;
......
......@@ -295,7 +295,8 @@ public function language() {
$language = $this->languageManager()->getLanguage($this->langcode);
if (!$language) {
// Make sure we return a proper language object.
$language = new Language(array('id' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$langcode = $this->langcode ?: LanguageInterface::LANGCODE_NOT_SPECIFIED;
$language = new Language(array('id' => $langcode));
}
return $language;
}
......
......@@ -813,7 +813,7 @@ protected function getAllDisplayModesByEntityType($display_type) {
$this->displayModeInfo[$display_type] = array();
foreach ($this->getStorage($display_type)->loadMultiple() as $display_mode) {
list($display_mode_entity_type, $display_mode_name) = explode('.', $display_mode->id(), 2);
$this->displayModeInfo[$display_type][$display_mode_entity_type][$display_mode_name] = (array) $display_mode;
$this->displayModeInfo[$display_type][$display_mode_entity_type][$display_mode_name] = $display_mode->toArray();
}
$this->moduleHandler->alter($key, $this->displayModeInfo[$display_type]);
$this->cacheBackend->set("$key:$langcode", $this->displayModeInfo[$display_type], CacheBackendInterface::CACHE_PERMANENT, array('entity_types' => TRUE, 'entity_field_info' => TRUE));
......
......@@ -85,7 +85,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la
'entity_view',
'block',
$entity->id(),
$entity->langcode,
$entity->language()->getId(),
// Blocks are always rendered in a "per theme" cache context.
'cache_context.theme',
);
......
......@@ -67,7 +67,7 @@ public function testBlockContentTypeCreation() {
// Check that the block type was created in site default language.
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id;
$this->assertEqual($block_type->langcode, $default_langcode);
$this->assertEqual($block_type->language()->getId(), $default_langcode);
}
/**
......
......@@ -84,7 +84,7 @@ public function testCommentTypeCreation() {
// Check that the comment type was created in site default language.
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id;
$this->assertEqual($comment_type->langcode, $default_langcode);
$this->assertEqual($comment_type->language()->getId(), $default_langcode);
}
/**
......
......@@ -46,10 +46,10 @@ function testCRUD() {
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->id;
// Verify default properties on a newly created empty entity.
$empty = entity_create('config_test');
$this->assertTrue($empty->uuid);
$this->assertTrue($empty->uuid());
$this->assertIdentical($empty->label, NULL);
$this->assertIdentical($empty->style, NULL);
$this->assertIdentical($empty->langcode, $default_langcode);
$this->assertIdentical($empty->language()->getId(), $default_langcode);
// Verify ConfigEntity properties/methods on the newly created empty entity.
$this->assertIdentical($empty->isNew(), TRUE);
......@@ -63,7 +63,7 @@ function testCRUD() {
$this->assertTrue($empty->get('uuid'));
$this->assertIdentical($empty->get('label'), NULL);
$this->assertIdentical($empty->get('style'), NULL);
$this->assertIdentical($empty->get('langcode'), $default_langcode);
$this->assertIdentical($empty->language()->getId(), $default_langcode);
// Verify Entity properties/methods on the newly created empty entity.
$this->assertIdentical($empty->getEntityTypeId(), 'config_test');
......@@ -104,11 +104,11 @@ function testCRUD() {
'label' => $this->randomString(),
'style' => $this->randomName(),
));
$this->assertTrue($config_test->uuid);
$this->assertNotEqual($config_test->uuid, $empty->uuid);
$this->assertTrue($config_test->uuid());
$this->assertNotEqual($config_test->uuid(), $empty->uuid());
$this->assertIdentical($config_test->label, $expected['label']);
$this->assertIdentical($config_test->style, $expected['style']);
$this->assertIdentical($config_test->langcode, $default_langcode);
$this->assertIdentical($config_test->language()->getId(), $default_langcode);
// Verify methods on the newly created entity.
$this->assertIdentical($config_test->isNew(), TRUE);
......
......@@ -59,7 +59,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
*
* @var boolean
*/
public $status;
protected $status;
/**
* List of component display options, keyed by component name.
......
......@@ -50,7 +50,7 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
*
* @var bool
*/
public $status = TRUE;
protected $status = TRUE;
/**
* Whether or not the rendered output of this view mode is cached by default.
......
......@@ -394,7 +394,7 @@ public static function preDelete(EntityStorageInterface $storage, array $fields)
$config = $field->toArray();
$config['deleted'] = TRUE;
$config['bundles'] = $field->getBundles();
$deleted_fields[$field->uuid] = $config;
$deleted_fields[$field->uuid()] = $config;
}
}
......
......@@ -405,7 +405,7 @@ public static function preDelete(EntityStorageInterface $storage, array $instanc
if (!$instance->deleted) {
$config = $instance->toArray();
$config['deleted'] = TRUE;
$deleted_instances[$instance->uuid] = $config;
$deleted_instances[$instance->uuid()] = $config;
}
}
$state->set('field.instance.deleted', $deleted_instances);
......
......@@ -126,6 +126,10 @@ public function loadByProperties(array $conditions = array()) {
$checked_value = $field->name;
break;
case 'uuid';
$checked_value = $field->uuid();
break;
default:
$checked_value = $field->$key;
break;
......
......@@ -146,6 +146,10 @@ public function loadByProperties(array $conditions = array()) {
$checked_value = $instance->field_uuid;
break;
case 'uuid';
$checked_value = $instance->uuid();
break;
default:
$checked_value = $instance->$key;
break;
......
......@@ -180,7 +180,7 @@ function testDeleteFieldInstance() {
$instance->delete();
// The instance still exists, deleted.
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE));
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE));
$this->assertEqual(count($instances), 1, 'There is one deleted instance');
$instance = $instances[0];
$this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle');
......@@ -258,19 +258,19 @@ function testPurgeInstance() {
$this->checkHooksInvocations($hooks, $actual_hooks);
// The instance still exists, deleted.
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE));
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE));
$this->assertEqual(count($instances), 1, 'There is one deleted instance');
// Purge the instance.
field_purge_batch($batch_size);
// The instance is gone.
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE));
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE));
$this->assertEqual(count($instances), 0, 'The instance is gone');
// The field still exists, not deleted, because it has a second instance.
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid]), 'The field exists and is not deleted');
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid()]), 'The field exists and is not deleted');
}
/**
......@@ -310,8 +310,8 @@ function testPurgeField() {
field_purge_batch(0);
// The field still exists, not deleted.
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid]) && !$fields[$field->uuid]->deleted, 'The field exists and is not deleted');
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid()]) && !$fields[$field->uuid()]->deleted, 'The field exists and is not deleted');
// Delete the second instance.
$bundle = next($this->bundles);
......@@ -335,14 +335,14 @@ function testPurgeField() {
$this->checkHooksInvocations($hooks, $actual_hooks);
// The field still exists, deleted.
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid]) && $fields[$field->uuid]->deleted, 'The field exists and is deleted');
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->deleted, 'The field exists and is deleted');
// Purge again to purge the instance and the field.
field_purge_batch(0);
// The field is gone.
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE));
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE));
$this->assertEqual(count($fields), 0, 'The field is purged.');
}
......
......@@ -92,7 +92,7 @@ function verifyTextFormat($format) {
$this->assertEqual($filter_format->name, $format->name, format_string('filter_format_load: Proper title for text format %format.', $t_args));
$this->assertEqual($filter_format->weight, $format->weight, format_string('filter_format_load: Proper weight for text format %format.', $t_args));
// Check that the filter was created in site default language.
$this->assertEqual($format->langcode, $default_langcode, format_string('filter_format_load: Proper language code for text format %format.', $t_args));
$this->assertEqual($format->language()->getId(), $default_langcode, format_string('filter_format_load: Proper language code for text format %format.', $t_args));
}
}
......@@ -419,12 +419,12 @@ function image_field_config_update(FieldConfigInterface $field) {
if ($file_new) {
$file_new->status = FILE_STATUS_PERMANENT;
$file_new->save();
\Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field->uuid);
\Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field->uuid());
}
// Is there an old file?
if ($fid_old && ($file_old = file_load($fid_old))) {
\Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field->uuid);
\Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field->uuid());
}
}
......@@ -458,11 +458,11 @@ function image_field_instance_config_update(FieldInstanceConfigInterface $field_
if ($file_new) {
$file_new->status = FILE_STATUS_PERMANENT;
$file_new->save();
\Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field_instance->uuid);
\Drupal::service('file.usage')->add($file_new, 'image', 'default_image', $field_instance->uuid());
}
// Delete the old file, if present.
if ($fid_old && ($file_old = file_load($fid_old))) {
\Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field_instance->uuid);
\Drupal::service('file.usage')->delete($file_old, 'image', 'default_image', $field_instance->uuid());
}
}
......@@ -486,7 +486,7 @@ function image_field_config_delete(FieldConfigInterface $field) {
// The value of a managed_file element can be an array if #extended == TRUE.
$fid = $field->settings['default_image']['fid'];
if ($fid && ($file = file_load($fid))) {
\Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid);
\Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid());
}
}
......@@ -505,6 +505,6 @@ function image_field_instance_config_delete(FieldInstanceConfigInterface $field_
// Remove the default image when the instance is deleted.
if ($fid && ($file = file_load($fid))) {
\Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field_instance->uuid);
\Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field_instance->uuid());
}
}
......@@ -174,7 +174,7 @@ public function form(array $form, array &$form_state) {
// Without Language module menu links inherit the menu language and no
// language selector is shown.
else {
$default_langcode = ($menu_link->isNew() ? entity_load('menu', $menu_link->menu_name)->langcode : $menu_link->langcode);
$default_langcode = ($menu_link->isNew() ? entity_load('menu', $menu_link->menu_name)->language()->getId() : $menu_link->langcode);
$language_show = FALSE;
}
......
......@@ -118,7 +118,7 @@ public function form(array $form, array &$form_state) {
'#type' => 'language_select',
'#title' => t('Menu language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $menu->langcode,
'#default_value' => $menu->language()->getId(),
);
// Unlike the menu langcode, the default language configuration for menu
// links only works with language module installed.
......
......@@ -70,7 +70,7 @@ function testMenuLanguage() {
$this->drupalPostForm('admin/structure/menu/add', $edit, t('Save'));
// Check that the language settings were saved.
$this->assertEqual(entity_load('menu', $menu_name)->langcode, $edit['langcode']);
$this->assertEqual(entity_load('menu', $menu_name)->language()->getId(), $edit['langcode']);
$language_settings = language_get_default_configuration('menu_link', $menu_name);
$this->assertEqual($language_settings['langcode'], 'bb');
$this->assertEqual($language_settings['language_show'], TRUE);
......@@ -176,7 +176,7 @@ function testMenuLanguageRemovedEnglish() {
// Check that the language settings were saved.
$menu = Menu::load($menu_name);
$this->assertEqual($menu->langcode, 'en');
$this->assertEqual($menu->language()->getId(), 'en');
// Remove English language. To do that another language has to be set as
// default.
......@@ -188,7 +188,7 @@ function testMenuLanguageRemovedEnglish() {
// Save the menu again and check if the language is still the same.
$this->drupalPostForm("admin/structure/menu/manage/$menu_name", array(), t('Save'));
$menu = Menu::load($menu_name);
$this->assertEqual($menu->langcode, 'en');
$this->assertEqual($menu->language()->getId(), 'en');
}
}
......@@ -56,7 +56,7 @@ public function testFields() {
$field = entity_load('field_config', 'node.field_test');
$expected = array('max_length' => 255);
$this->assertEqual($field->type, "text", "Field type is text.");
$this->assertEqual($field->status, TRUE, "Status is TRUE");
$this->assertEqual($field->status(), TRUE, "Status is TRUE");
$this->assertEqual($field->settings, $expected, "Field type text settings are correct");
// Integer field.
......@@ -93,7 +93,7 @@ public function testFields() {
// Date field.
$field = entity_load('field_config', 'node.field_test_datetime');
$this->assertEqual($field->type, "datetime", "Field type is datetime.");
$this->assertEqual($field->status, FALSE, "Status is FALSE");
$this->assertEqual($field->status(), FALSE, "Status is FALSE");
}
}
......@@ -147,7 +147,7 @@ public function form(array $form, array &$form_state) {
'#type' => 'language_select',
'#title' => t('Language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $this->entity->langcode,
'#default_value' => $this->entity->language()->getId(),
);
return parent::form($form, $form_state);
......
......@@ -513,9 +513,9 @@ public function testTableNames() {
'name' => $field_name,
'type' => 'test_field',
));
$expected = 'short_entity_type__' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'short_entity_type__' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field), $expected);
$expected = 'short_entity_type_r__' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'short_entity_type_r__' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field), $expected);
// Long entity type, short field name
......@@ -526,9 +526,9 @@ public function testTableNames() {
'name' => $field_name,
'type' => 'test_field',
));
$expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field), $expected);
$expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field), $expected);
// Long entity type and field name.
......@@ -539,9 +539,9 @@ public function testTableNames() {
'name' => $field_name,
'type' => 'test_field',
));
$expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'long_entity_type_abcdefghijklmnopq__' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field), $expected);
$expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'long_entity_type_abcdefghijklmnopq_r__' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field), $expected);
// Try creating a second field and check there are no clashes.
$field2 = entity_create('field_config', array(
......@@ -559,9 +559,9 @@ public function testTableNames() {
'type' => 'test_field',
'deleted' => TRUE,
));
$expected = 'field_deleted_data_' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'field_deleted_data_' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldTableName($field), $expected);
$expected = 'field_deleted_revision_' . substr(hash('sha256', $field->uuid), 0, 10);
$expected = 'field_deleted_revision_' . substr(hash('sha256', $field->uuid()), 0, 10);
$this->assertEqual(ContentEntityDatabaseStorage::_fieldRevisionTableName($field), $expected);
}
......
......@@ -58,7 +58,7 @@ public function form(array $form, array &$form_state) {
'#type' => 'language_select',
'#title' => $this->t('Vocabulary language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $vocabulary->langcode,
'#default_value' => $vocabulary->language()->getId(),
);
if ($this->moduleHandler->moduleExists('language')) {
$form['default_terms_language'] = array(
......
......@@ -52,7 +52,7 @@ function testRoleAdministration() {
$this->assertTrue(is_object($role), 'The role was successfully retrieved from the database.');
// Check that the role was created in site default language.
$this->assertEqual($role->langcode, $default_langcode);
$this->assertEqual($role->language()->getId(), $default_langcode);
// Try adding a duplicate role.
$this->drupalPostForm('admin/people/roles/add', $edit, t('Save'));
......
......@@ -103,7 +103,7 @@ public function testEntityArea() {
// Mark entity_test test view_mode as customizable.
$view_mode = \Drupal::entityManager()->getStorage('view_mode')->load('entity_test.test');
$view_mode->status = TRUE;
$view_mode->enable();
$view_mode->save();
// Change the view mode of the area handler.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment