Commit 189108a1 authored by catch's avatar catch

Issue #1833334 by das-peter, plach, Berdir, fago: EntityNG: integrate a...

Issue #1833334 by das-peter, plach, Berdir, fago: EntityNG: integrate a dynamic property data table handling.
parent db1122d6
......@@ -187,6 +187,7 @@ public function submit(array $form, array &$form_state) {
// Remove button and internal Form API values from submitted values.
form_state_values_clean($form_state);
$this->updateFormLangcode($form_state);
$this->submitEntityLanguage($form, $form_state);
$entity = $this->buildEntity($form, $form_state);
$this->setEntity($entity, $form_state);
......@@ -246,24 +247,32 @@ public function getFormLangcode(array $form_state) {
/**
* Implements EntityFormControllerInterface::isDefaultFormLangcode().
*/
public function isDefaultFormLangcode($form_state) {
public function isDefaultFormLangcode(array $form_state) {
return $this->getFormLangcode($form_state) == $this->getEntity($form_state)->language()->langcode;
}
/**
* Handle possible entity language changes.
* Updates the form language to reflect any change to the entity language.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* A reference to a keyed array containing the current state of the form.
* A keyed array containing the current state of the form.
*/
protected function submitEntityLanguage(array $form, array &$form_state) {
protected function updateFormLangcode(array $form_state) {
// Update the form language as it might have changed.
if (isset($form_state['values']['langcode']) && $this->isDefaultFormLangcode($form_state)) {
$form_state['langcode'] = $form_state['values']['langcode'];
}
}
/**
* Handle possible entity language changes.
*
* @param array $form
* An associative array containing the structure of the form.
* @param array $form_state
* A reference to a keyed array containing the current state of the form.
*/
protected function submitEntityLanguage(array $form, array &$form_state) {
$entity = $this->getEntity($form_state);
$entity_type = $entity->entityType();
......
......@@ -47,12 +47,12 @@ public function getFormLangcode(array $form_state);
* Checks whether the current form language matches the entity one.
*
* @param array $form_state
* A reference to a keyed array containing the current state of the form.
* A keyed array containing the current state of the form.
*
* @return boolean
* Returns TRUE if the entity form language matches the entity one.
*/
public function isDefaultFormLangcode($form_state);
public function isDefaultFormLangcode(array $form_state);
/**
* Returns the operation identifying the form controller.
......
......@@ -47,6 +47,16 @@ public function validate(array $form, array &$form_state) {
form_execute_handlers('validate', $form, $form_state);
}
/**
* Overrides EntityFormController::submitEntityLanguage().
*/
protected function submitEntityLanguage(array $form, array &$form_state) {
// Nothing to do here, as original field values are always stored with
// LANGUAGE_DEFAULT language.
// @todo Delete this method when merging EntityFormControllerNG with
// EntityFormController.
}
/**
* Overrides EntityFormController::buildEntity().
*/
......
......@@ -294,6 +294,9 @@ public function processDefinition(&$definition, $plugin_id) {
// Drupal\Core\Entity\DatabaseStorageControllerInterface::buildQuery().
if (isset($definition['base_table'])) {
$definition['schema_fields_sql']['base_table'] = drupal_schema_fields_sql($definition['base_table']);
if (isset($definition['data_table'])) {
$definition['schema_fields_sql']['data_table'] = drupal_schema_fields_sql($definition['data_table']);
}
if (isset($definition['revision_table'])) {
$definition['schema_fields_sql']['revision_table'] = drupal_schema_fields_sql($definition['revision_table']);
}
......
......@@ -102,7 +102,7 @@ protected function init() {
}
/**
* Magic __wakeup() implemenation.
* Magic __wakeup() implementation.
*/
public function __wakeup() {
$this->init();
......
......@@ -32,43 +32,58 @@ public static function getInfo() {
/**
* Tests basic CRUD functionality of the Entity API.
*/
function testCRUD() {
public function testCRUD() {
$user1 = $this->drupalCreateUser();
// All entity variations have to have the same results.
foreach (entity_test_entity_types() as $entity_type) {
$this->assertCRUD($entity_type, $user1);
}
}
/**
* Executes a test set for a defined entity type and user.
*
* @param string $entity_type
* The entity type to run the tests with.
* @param \Drupal\user\Plugin\Core\Entity\User $user1
* The user to run the tests with.
*/
protected function assertCRUD($entity_type, \Drupal\user\Plugin\Core\Entity\User $user1) {
// Create some test entities.
$entity = entity_create('entity_test', array('name' => 'test', 'user_id' => $user1->uid));
$entity = entity_create($entity_type, array('name' => 'test', 'user_id' => $user1->uid));
$entity->save();
$entity = entity_create('entity_test', array('name' => 'test2', 'user_id' => $user1->uid));
$entity = entity_create($entity_type, array('name' => 'test2', 'user_id' => $user1->uid));
$entity->save();
$entity = entity_create('entity_test', array('name' => 'test', 'user_id' => NULL));
$entity = entity_create($entity_type, array('name' => 'test', 'user_id' => NULL));
$entity->save();
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test')));
$this->assertEqual($entities[0]->name->value, 'test', 'Created and loaded entity.');
$this->assertEqual($entities[1]->name->value, 'test', 'Created and loaded entity.');
$entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
$this->assertEqual($entities[0]->name->value, 'test', format_string('%entity_type: Created and loaded entity', array('%entity_type' => $entity_type)));
$this->assertEqual($entities[1]->name->value, 'test', format_string('%entity_type: Created and loaded entity', array('%entity_type' => $entity_type)));
// Test loading a single entity.
$loaded_entity = entity_test_load($entity->id());
$this->assertEqual($loaded_entity->id(), $entity->id(), 'Loaded a single entity by id.');
$loaded_entity = entity_load($entity_type, $entity->id());
$this->assertEqual($loaded_entity->id(), $entity->id(), format_string('%entity_type: Loaded a single entity by id.', array('%entity_type' => $entity_type)));
// Test deleting an entity.
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test2')));
$entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test2')));
$entities[0]->delete();
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test2')));
$this->assertEqual($entities, array(), 'Entity deleted.');
$entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test2')));
$this->assertEqual($entities, array(), format_string('%entity_type: Entity deleted.', array('%entity_type' => $entity_type)));
// Test updating an entity.
$entities = array_values(entity_load_multiple_by_properties('entity_test', array('name' => 'test')));
$entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
$entities[0]->name->value = 'test3';
$entities[0]->save();
$entity = entity_test_load($entities[0]->id());
$this->assertEqual($entity->name->value, 'test3', 'Entity updated.');
$entity = entity_load($entity_type, $entities[0]->id());
$this->assertEqual($entity->name->value, 'test3', format_string('%entity_type: Entity updated.', array('%entity_type' => $entity_type)));
// Try deleting multiple test entities by deleting all.
$ids = array_keys(entity_test_load_multiple());
entity_test_delete_multiple($ids);
$ids = array_keys(entity_load_multiple($entity_type));
entity_delete_multiple($entity_type, $ids);
$all = entity_test_load_multiple();
$this->assertTrue(empty($all), 'Deleted all entities.');
$all = entity_load_multiple($entity_type);
$this->assertTrue(empty($all), format_string('%entity_type: Deleted all entities.', array('%entity_type' => $entity_type)));
}
}
......@@ -39,6 +39,19 @@ function setUp() {
* Tests basic form CRUD functionality.
*/
function testFormCRUD() {
// All entity variations have to have the same results.
foreach (entity_test_entity_types() as $entity_type) {
$this->assertFormCRUD($entity_type);
}
}
/**
* Executes the form CRUD tests for the given entity type.
*
* @param string $entity_type
* The entity type to run the tests with.
*/
protected function assertFormCRUD($entity_type) {
$langcode = LANGUAGE_NOT_SPECIFIED;
$name1 = $this->randomName(8);
$name2 = $this->randomName(10);
......@@ -49,28 +62,27 @@ function testFormCRUD() {
"field_test_text[$langcode][0][value]" => $this->randomName(16),
);
$this->drupalPost('entity-test/add', $edit, t('Save'));
$entity = $this->loadEntityByName($name1);
$this->assertTrue($entity, 'Entity found in the database.');
$this->drupalPost($entity_type . '/add', $edit, t('Save'));
$entity = $this->loadEntityByName($entity_type, $name1);
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $entity_type)));
$edit['name'] = $name2;
$this->drupalPost('entity-test/manage/' . $entity->id() . '/edit', $edit, t('Save'));
$entity = $this->loadEntityByName($name1);
$this->assertFalse($entity, 'The entity has been modified.');
$entity = $this->loadEntityByName($name2);
$this->assertTrue($entity, 'Modified entity found in the database.');
$this->assertNotEqual($entity->name->value, $name1, 'The entity name has been modified.');
$this->drupalPost($entity_type . '/manage/' . $entity->id() . '/edit', $edit, t('Save'));
$entity = $this->loadEntityByName($entity_type, $name1);
$this->assertFalse($entity, format_string('%entity_type: The entity has been modified.', array('%entity_type' => $entity_type)));
$entity = $this->loadEntityByName($entity_type, $name2);
$this->assertTrue($entity, format_string('%entity_type: Modified entity found in the database.', array('%entity_type' => $entity_type)));
$this->assertNotEqual($entity->name->value, $name1, format_string('%entity_type: The entity name has been modified.', array('%entity_type' => $entity_type)));
$this->drupalPost('entity-test/manage/' . $entity->id() . '/edit', array(), t('Delete'));
$entity = $this->loadEntityByName($name2);
$this->assertFalse($entity, 'Entity not found in the database.');
$this->drupalPost($entity_type . '/manage/' . $entity->id() . '/edit', array(), t('Delete'));
$entity = $this->loadEntityByName($entity_type, $name2);
$this->assertFalse($entity, format_string('%entity_type: Entity not found in the database.', array('%entity_type' => $entity_type)));
}
/**
* Loads a test entity by name always resetting the storage controller cache.
*/
protected function loadEntityByName($name) {
$entity_type = 'entity_test';
protected function loadEntityByName($entity_type, $name) {
// Always load the entity from the database to ensure that changes are
// correctly picked up.
entity_get_controller($entity_type)->resetCache();
......
......@@ -47,8 +47,22 @@ public function setUp() {
*/
public function testRevisions() {
// All revisable entity variations have to have the same results.
foreach (entity_test_entity_types(ENTITY_TEST_TYPES_REVISABLE) as $entity_type) {
$this->assertRevisions($entity_type);
}
}
/**
* Executes the revision tests for the given entity type.
*
* @param string $entity_type
* The entity type to run the tests with.
*/
protected function assertRevisions($entity_type) {
// Create initial entity.
$entity = entity_create('entity_test', array(
$entity = entity_create($entity_type, array(
'name' => 'foo',
'user_id' => $this->web_user->uid,
));
......@@ -67,7 +81,7 @@ public function testRevisions() {
$legacy_name = $entity->name->value;
$legacy_text = $entity->field_test_text->value;
$entity = entity_test_load($entity->id->value);
$entity = entity_load($entity_type, $entity->id->value);
$entity->setNewRevision(TRUE);
$names[] = $entity->name->value = $this->randomName(32);
$texts[] = $entity->field_test_text->value = $this->randomName(32);
......@@ -75,25 +89,25 @@ public function testRevisions() {
$revision_ids[] = $entity->revision_id->value;
// Check that the fields and properties contain new content.
$this->assertTrue($entity->revision_id->value > $legacy_revision_id, 'Revision ID changed.');
$this->assertNotEqual($entity->name->value, $legacy_name, 'Name changed.');
$this->assertNotEqual($entity->field_test_text->value, $legacy_text, 'Text changed.');
$this->assertTrue($entity->revision_id->value > $legacy_revision_id, format_string('%entity_type: Revision ID changed.', array('%entity_type' => $entity_type)));
$this->assertNotEqual($entity->name->value, $legacy_name, format_string('%entity_type: Name changed.', array('%entity_type' => $entity_type)));
$this->assertNotEqual($entity->field_test_text->value, $legacy_text, format_string('%entity_type: Text changed.', array('%entity_type' => $entity_type)));
}
for ($i = 0; $i < $revision_count; $i++) {
// Load specific revision.
$entity_revision = entity_revision_load('entity_test', $revision_ids[$i]);
$entity_revision = entity_revision_load($entity_type, $revision_ids[$i]);
// Check if properties and fields contain the revision specific content.
$this->assertEqual($entity_revision->revision_id->value, $revision_ids[$i], 'Revision ID matches.');
$this->assertEqual($entity_revision->name->value, $names[$i], 'Name matches.');
$this->assertEqual($entity_revision->field_test_text->value, $texts[$i], 'Text matches.');
$this->assertEqual($entity_revision->revision_id->value, $revision_ids[$i], format_string('%entity_type: Revision ID matches.', array('%entity_type' => $entity_type)));
$this->assertEqual($entity_revision->name->value, $names[$i], format_string('%entity_type: Name matches.', array('%entity_type' => $entity_type)));
$this->assertEqual($entity_revision->field_test_text->value, $texts[$i], format_string('%entity_type: Text matches.', array('%entity_type' => $entity_type)));
}
// Confirm the correct revision text appears in the edit form.
$entity = entity_load('entity_test', $entity->id->value);
$this->drupalGet('entity-test/manage/' . $entity->id->value);
$this->assertFieldById('edit-name', $entity->name->value, 'Name matches in UI.');
$this->assertFieldById('edit-field-test-text-und-0-value', $entity->field_test_text->value, 'Text matches in UI.');
$entity = entity_load($entity_type, $entity->id->value);
$this->drupalGet($entity_type . '/manage/' . $entity->id->value);
$this->assertFieldById('edit-name', $entity->name->value, format_string('%entity_type: Name matches in UI.', array('%entity_type' => $entity_type)));
$this->assertFieldById('edit-field-test-text-und-0-value', $entity->field_test_text->value, format_string('%entity_type: Text matches in UI.', array('%entity_type' => $entity_type)));
}
}
......@@ -34,10 +34,23 @@ public static function getInfo() {
* Tests UUID generation in entity CRUD operations.
*/
function testCRUD() {
// All entity variations have to have the same results.
foreach (entity_test_entity_types() as $entity_type) {
$this->assertCRUD($entity_type);
}
}
/**
* Executes the UUID CRUD tests for the given entity type.
*
* @param string $entity_type
* The entity type to run the tests with.
*/
protected function assertCRUD($entity_type) {
// Verify that no UUID is auto-generated when passing one for creation.
$uuid_service = new Uuid();
$uuid = $uuid_service->generate();
$custom_entity = entity_create('entity_test', array(
$custom_entity = entity_create($entity_type, array(
'name' => $this->randomName(),
'uuid' => $uuid,
));
......@@ -46,7 +59,7 @@ function testCRUD() {
$custom_entity->save();
// Verify that a new UUID is generated upon creating an entity.
$entity = entity_create('entity_test', array('name' => $this->randomName()));
$entity = entity_create($entity_type, array('name' => $this->randomName()));
$uuid = $entity->uuid();
$this->assertTrue($uuid);
......@@ -58,11 +71,11 @@ function testCRUD() {
$this->assertIdentical($entity->uuid(), $uuid);
// Verify that the UUID is retained upon loading.
$entity_loaded = entity_test_load($entity->id(), TRUE);
$entity_loaded = entity_load($entity_type, $entity->id(), TRUE);
$this->assertIdentical($entity_loaded->uuid(), $uuid);
// Verify that entity_load_by_uuid() loads the same entity.
$entity_loaded_by_uuid = entity_load_by_uuid('entity_test', $uuid, TRUE);
$entity_loaded_by_uuid = entity_load_by_uuid($entity_type, $uuid, TRUE);
$this->assertIdentical($entity_loaded_by_uuid->uuid(), $uuid);
$this->assertEqual($entity_loaded_by_uuid->id(), $entity_loaded->id());
......
......@@ -59,7 +59,7 @@ protected function setUp() {
'format' => 'full_html',
),
);
$this->entity = entity_create('entity_test', $this->values);
$this->entity = entity_create('entity_test_mulrev', $this->values);
$this->entity->save();
}
......@@ -105,7 +105,7 @@ public function testNormalize() {
foreach (array_keys($expected) as $fieldName) {
$this->assertEqual($expected[$fieldName], $normalized[$fieldName], "ComplexDataNormalizer produces expected array for $fieldName.");
}
$this->assertEqual(array_keys($expected), array_keys($normalized), 'No unexpected data is added to the normalized array.');
$this->assertEqual(array_diff_key($normalized, $expected), array(), 'No unexpected data is added to the normalized array.');
}
/**
......
......@@ -2,11 +2,54 @@
/**
* @file
* Test module for the entity API providing an entity type for testing.
* Test module for the entity API providing several entity types for testing.
*/
use Drupal\entity_test\Plugin\Core\Entity\EntityTest;
use Drupal\Core\Entity\EntityInterface;
/**
* Filter that limits test entity list to revisable ones.
*/
const ENTITY_TEST_TYPES_REVISABLE = 1;
/**
* Filter that limits test entity list to multilingual ones.
*/
const ENTITY_TEST_TYPES_MULTILINGUAL = 2;
/**
* Returns a list of test entity types.
*
* The returned entity types are one for each available entity storage type:
* - The plain entity_test type supports neither revisions nor multilingual
* properties.
* - The entity_test_mul type supports multilingual properties.
* - The entity_test_rev type supports revisions.
* - The entity_test_mulrev type supports both revisions and multilingual
* properties.
*
* @param int $filter
* Either ENTITY_TEST_TYPES_REVISABLE to only return revisable entity types or
* ENTITY_TEST_TYPES_MULTILINGUAL to only return multilingual ones. Defaults
* to NULL, which returns all.
*
* @return array
* List with entity_types.
*/
function entity_test_entity_types($filter = NULL) {
$types = array();
if ($filter == NULL) {
$types[] = 'entity_test';
}
if ($filter != ENTITY_TEST_TYPES_REVISABLE) {
$types[] = 'entity_test_mul';
}
if ($filter != ENTITY_TEST_TYPES_MULTILINGUAL) {
$types[] = 'entity_test_rev';
}
$types[] = 'entity_test_mulrev';
return drupal_map_assoc($types);
}
/**
* Implements hook_entity_info_alter().
......@@ -14,7 +57,9 @@
function entity_test_entity_info_alter(&$info) {
// Optionally specify a translation handler for testing translations.
if (state()->get('entity_test.translation')) {
$info['entity_test']['translation']['entity_test'] = TRUE;
foreach(entity_test_entity_types() as $entity_type) {
$info[$entity_type]['translation'][$entity_type] = TRUE;
}
}
}
......@@ -69,55 +114,71 @@ function entity_test_permission() {
function entity_test_menu() {
$items = array();
$items['entity-test/add'] = array(
'title' => 'Add an entity_test',
'page callback' => 'entity_test_add',
'access arguments' => array('administer entity_test content'),
'type' => MENU_NORMAL_ITEM,
);
$items['entity-test/manage/%entity_test'] = array(
'title' => 'Edit test entity',
'page callback' => 'entity_test_edit',
'page arguments' => array(2),
'access arguments' => array('administer entity_test content'),
'type' => MENU_NORMAL_ITEM,
);
$items['entity-test/manage/%entity_test/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
foreach(entity_test_entity_types() as $entity_type) {
$items[$entity_type . '/add'] = array(
'title' => 'Add an @type',
'title arguments' => array('@type' => $entity_type),
'page callback' => 'entity_test_add',
'page arguments' => array($entity_type),
'access arguments' => array('administer entity_test content'),
'type' => MENU_NORMAL_ITEM,
);
$items[$entity_type . '/manage/%' . $entity_type] = array(
'title' => 'Edit @type',
'title arguments' => array('@type' => $entity_type),
'page callback' => 'entity_test_edit',
'page arguments' => array(2),
'access arguments' => array('administer entity_test content'),
'type' => MENU_NORMAL_ITEM,
);
$items[$entity_type . '/manage/%' . $entity_type . '/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
}
return $items;
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) {
$langcode = $form_state['controller']->getFormLangcode($form_state);
variable_set('entity_form_langcode', $langcode);
}
/**
* Menu callback: displays the 'Add new entity_test' form.
*
* @param string $entity_type
* Name of the entity type for which a create form should be displayed.
*
* @return array
* The processed form for a new entity_test.
*
* @see entity_test_menu()
*/
function entity_test_add() {
drupal_set_title(t('Create an entity_test'));
$entity = entity_create('entity_test', array());
function entity_test_add($entity_type) {
drupal_set_title(t('Create an @type', array('@type' => $entity_type)));
$entity = entity_create($entity_type, array());
return entity_get_form($entity);
}
/**
* Menu callback: displays the 'Edit existing entity_test' form.
*
* @param array $entity
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be edited.
*
* @return array
* The processed form for the edited entity_test.
* The processed form for the edited entity.
*
* @see entity_test_menu()
*/
function entity_test_edit(EntityTest $entity) {
function entity_test_edit(EntityInterface $entity) {
drupal_set_title($entity->label(), PASS_THROUGH);
return entity_get_form($entity);
}
......@@ -130,7 +191,7 @@ function entity_test_edit(EntityTest $entity) {
* @param bool $reset
* A boolean indicating that the internal cache should be reset.
*
* @return Drupal\entity_test\Plugin\Core\Entity\EntityTest
* @return \Drupal\entity_test\Plugin\Core\Entity\EntityTest
* The loaded entity object, or FALSE if the entity cannot be loaded.
*/
function entity_test_load($id, $reset = FALSE) {
......@@ -138,36 +199,48 @@ function entity_test_load($id, $reset = FALSE) {
}
/**
* Loads multiple test entities based on certain conditions.
* Loads a test entity.
*
* @param array $ids
* (optional) An array of entity IDs. If omitted, all entities are loaded.
* @param int $id
* A test entity ID.
* @param bool $reset
* A boolean indicating that the internal cache should be reset.
*
* @return array
* An array of test entity objects, indexed by ID.
* @return \Drupal\entity_test\Plugin\Core\Entity\EntityTestRev
* The loaded entity object, or FALSE if the entity cannot be loaded.
*/
function entity_test_load_multiple(array $ids = NULL, $reset = FALSE) {
return entity_load_multiple('entity_test', $ids, $reset);
function entity_test_rev_load($id, $reset = FALSE) {
return entity_load('entity_test_rev', $id, $reset);
}
/**
* Deletes multiple test entities.
* Loads a test entity.
*
* @param int $id
* A test entity ID.
* @param bool $reset
* A boolean indicating that the internal cache should be reset.
*
* @param $ids
* An array of test entity IDs.
* @return \Drupal\entity_test\Plugin\Core\Entity\EntityTestMul
* The loaded entity object, or FALSE if the entity cannot be loaded.
*/
function entity_test_delete_multiple(array $ids) {
entity_delete_multiple('entity_test', $ids);
function entity_test_mul_load($id, $reset = FALSE) {
return entity_load('entity_test_mul', $id, $reset);
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
* Loads a test entity.
*
* @param int $id
* A test entity ID.
* @param bool $reset
* A boolean indicating that the internal cache should be reset.
*
* @return \Drupal\entity_test\Plugin\Core\Entity\EntityTestMulRev
* The loaded entity object, or FALSE if the entity cannot be loaded.
*/
function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) {
$langcode = $form_state['controller']->getFormLangcode($form_state);
variable_set('entity_form_langcode', $langcode);
function entity_test_mulrev_load($id, $reset = FALSE) {
return entity_load('entity_test_mulrev', $id, $reset);
}
/**
......
......@@ -61,11 +61,16 @@ public function save(array $form, array &$form_state) {
$is_new = $entity->isNew();
$entity->save();
$message = $is_new ? t('entity_test @id has been created.', array('@id' => $entity->id())) : t('entity_test @id has been updated.', array('@id' => $entity->id()));
if ($is_new) {
$message = t('%entity_type @id has been created.', array('@id' => $entity->id(), '%entity_type' => $entity->entityType()));
}
else {
$message = t('%entity_type @id has been updated.', array('@id' => $entity->id(), '%entity_type' => $entity->entityType()));
}
drupal_set_message($message);
if ($entity->id()) {
$form_state['redirect'] = 'entity-test/manage/' . $entity->id() . '/edit';
$form_state['redirect'] = $entity->entityType() . '/manage/' . $entity->id() . '/edit';
}
else {
// Error on save.
......@@ -80,7 +85,7 @@ public function save(array $form, array &$form_state) {
public function delete(array $form, array &$form_state) {
$entity = $this->getEntity($form_state);
$entity->delete();
drupal_set_message(t('entity_test @id has been deleted.', array('@id' => $entity->id())));
drupal_set_message(t('%entity_type @id has been deleted.', array('@id' => $entity->id(), '%entity_type' => $entity->entityType())));
$form_state['redirect'] = '<front>';
}
}
<?php
/**
* @file
* Definition of Drupal\entity_test\EntityTestMulRevStorageController.
*/
namespace Drupal\entity_test;
use Drupal\entity_test\EntityTestStorageController;
/**
* Defines the controller class for the test entity.
*
* This extends the Drupal\entity_test\EntityTestStorageController class, adding
* required special handling for test entities with multilingual property and