Skip to content
Snippets Groups Projects
Commit 00b12b3e authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1803586 by linclark: Added Give all entities their own URI.

parent 986d2973
No related branches found
No related tags found
No related merge requests found
......@@ -161,19 +161,22 @@ public function uri() {
elseif (isset($entity_info['uri_callback'])) {
$uri_callback = $entity_info['uri_callback'];
}
else {
return NULL;
}
// Invoke the callback to get the URI. If there is no callback, return NULL.
// Invoke the callback to get the URI. If there is no callback, use the
// default URI format.
if (isset($uri_callback) && function_exists($uri_callback)) {
$uri = $uri_callback($this);
// Pass the entity data to url() so that alter functions do not need to
// look up this entity again.
$uri['options']['entity_type'] = $this->entityType;
$uri['options']['entity'] = $this;
return $uri;
}
else {
$uri = array(
'path' => 'entity/' . $this->entityType . '/' . $this->id(),
);
}
// Pass the entity data to url() so that alter functions do not need to
// look up this entity again.
$uri['options']['entity_type'] = $this->entityType;
$uri['options']['entity'] = $this;
return $uri;
}
/**
......
......@@ -132,8 +132,7 @@ public function label($langcode = NULL);
*
* @return
* An array containing the 'path' and 'options' keys used to build the URI
* of the entity, and matching the signature of url(). NULL if the entity
* has no URI of its own.
* of the entity, and matching the signature of url().
*/
public function uri();
......
<?php
/**
* @file
* Contains \Drupal\system\Tests\Entity\EntityUriTest.
*/
namespace Drupal\system\Tests\Entity;
use Drupal\simpletest\DrupalUnitTestBase;
/**
* Tests the basic Entity API.
*/
class EntityUriTest extends DrupalUnitTestBase {
/**
* Modules to load.
*
* @var array
*/
public static $modules = array('field', 'field_sql_storage', 'system', 'text');
public static function getInfo() {
return array(
'name' => 'Entity URI',
'description' => 'Tests default URI functionality.',
'group' => 'Entity API',
);
}
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'variable');
$this->installSchema('system', 'url_alias');
$this->installSchema('field', 'field_config');
$this->installSchema('field', 'field_config_instance');
$this->enableModules(array('entity_test'));
}
/**
* Tests that an entity without a URI callback uses the default URI.
*/
function testDefaultUri() {
// Create a test entity.
$entity = entity_create('entity_test', array('name' => 'test', 'user_id' => 1));
$entity->save();
$uri = $entity->uri();
$expected_path = 'entity/entity_test/' . $entity->id();
$this->assertEqual(url($uri['path'], $uri['options']), url($expected_path), 'Entity without URI callback returns expected URI.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment