diff --git a/contrib/profile2_page.module b/contrib/profile2_page.module
index 41e330e..215075b 100644
--- a/contrib/profile2_page.module
+++ b/contrib/profile2_page.module
@@ -195,7 +195,7 @@ function profile2_page_entity_info_alter(&$entity_info) {
* @see profile2_pages_entity_info_alter()
*/
function profile2_page_uri_callback($profile) {
- $type = $profile->type();
+ $type = entity_load('profile2_type', $profile->type);
if (!empty($type->data['use_page'])) {
return array('path' => profile2_page_get_base_path($type) . '/' . $profile->uid);
}
diff --git a/lib/Drupal/profile2/Profile.php b/lib/Drupal/profile2/Profile.php
index bc8d6c9..e94c371 100644
--- a/lib/Drupal/profile2/Profile.php
+++ b/lib/Drupal/profile2/Profile.php
@@ -56,93 +56,30 @@ class Profile extends Entity {
*/
public $changed;
- public function __construct(array $values = array(), $entity_type) {
- if (isset($values['user'])) {
- $this->setUser($values['user']);
- unset($values['user']);
- }
- if (isset($values['type']) && is_object($values['type'])) {
- $values['type'] = $values['type']->type;
- }
- if (!isset($values['label']) && isset($values['type']) && $type = profile2_type_load($values['type'])) {
- // Initialize the label with the type label, so newly created profiles
- // have that as interim label.
- $values['label'] = $type->label;
- }
- parent::__construct($values, $entity_type);
- }
-
/**
- * Returns the user owning this profile.
- */
- public function user() {
- return user_load($this->uid);
- }
-
- /**
- * Sets a new user owning this profile.
- *
- * @param $account
- * The user account object or the user account id (uid).
- */
- public function setUser($account) {
- $this->uid = is_object($account) ? $account->uid : $account;
- }
-
- /**
- * Gets the associated profile type object.
- *
- * @return ProfileType
- */
- public function type() {
- return profile2_type_load($this->type);
- }
-
- /**
- * Overwrites EntityInterface::id().
+ * Overrides Drupal\Core\Entity\Entity::id().
*/
public function id() {
return isset($this->pid) ? $this->pid : NULL;
}
/**
- * Overwrites EntityInterface::bundle().
+ * Overrides Drupal\Core\Entity\Entity::bundle().
*/
public function bundle() {
return $this->type;
}
/**
- * Returns the full url() for the profile.
- */
- public function url() {
- $uri = $this->uri();
- return url($uri['path'], $uri);
- }
-
- /**
- * Returns the drupal path to this profile.
+ * Overrides Drupal\Core\Entity\Entity::label().
*/
- public function path() {
- $uri = $this->uri();
- return $uri['path'];
- }
-
- public function defaultUri() {
- return array(
- 'path' => 'user/' . $this->uid,
- 'options' => array('fragment' => 'profile-' . $this->type),
- );
- }
-
- public function defaultLabel() {
- if (module_exists('profile2_i18n')) {
- // Run the label through i18n_string() using the profile2_type label
- // context, so the default label (= the type's label) gets translated.
- return entity_i18n_string('profile2:profile2_type:' . $this->type . ':label', $this->label);
+ public function label($langcode = NULL) {
+ if (isset($this->label) && $this->label !== '') {
+ return $this->label;
+ }
+ else {
+ return entity_load('profile2_type', $this->type)->label($langcode);
}
- return $this->label;
}
}
-
diff --git a/lib/Drupal/profile2/Tests/ProfileCRUDTest.php b/lib/Drupal/profile2/Tests/ProfileCRUDTest.php
index bf29da1..1894b77 100644
--- a/lib/Drupal/profile2/Tests/ProfileCRUDTest.php
+++ b/lib/Drupal/profile2/Tests/ProfileCRUDTest.php
@@ -46,7 +46,7 @@ class ProfileCRUDTest extends WebTestBase {
));
$this->assertIdentical($profile->id(), NULL);
$this->assertIdentical($profile->type, $expected['type']);
- $this->assertIdentical($profile->label, $types[0]->label());
+ $this->assertIdentical($profile->label(), $types[0]->label());
$this->assertIdentical($profile->uid, $this->user1->id());
$this->assertIdentical($profile->created, REQUEST_TIME);
$this->assertIdentical($profile->changed, NULL);
diff --git a/profile2.admin.inc b/profile2.admin.inc
index 6cf7111..7fbe835 100644
--- a/profile2.admin.inc
+++ b/profile2.admin.inc
@@ -28,7 +28,7 @@ function profile2_type_add() {
* A form array as expected by drupal_render().
*/
function profile2_type_edit(ProfileType $type) {
- drupal_set_title(t('Edit %label profile type', array('%label' => $type->label)), PASS_THROUGH);
+ drupal_set_title(t('Edit %label profile type', array('%label' => $type->label())), PASS_THROUGH);
return entity_get_form($type);
}
diff --git a/profile2.module b/profile2.module
index 52bbcca..8b8d658 100644
--- a/profile2.module
+++ b/profile2.module
@@ -82,13 +82,12 @@ function profile2_entity_info() {
* Entity URI callback for profiles.
*
* @param Drupal\profile2\Profile $profile
- * A Profile entity.
+ * A profile entity.
*/
function profile2_profile_uri(Profile $profile) {
- // @todo Call into user_uri() to ensure consistent URIs?
- return array(
- 'path' => 'user/' . $profile->uid,
- );
+ $uri = entity_load('user', $profile->uid)->uri();
+ $uri['options']['fragment'] = 'profile-' . $profile->bundle();
+ return $uri;
}
/**
@@ -359,8 +358,8 @@ function profile2_user_view($account, $view_mode, $langcode) {
if (profile2_access('view', $profile)) {
$account->content['profile_' . $id] = array(
'#type' => 'user_profile_category',
- '#title' => $profile->label,
- '#prefix' => '',
+ '#title' => $profile->label(),
+ '#prefix' => '',
);
entity_render_controller('profile2')->buildContent(array($profile), 'account');
$account->content['profile_' . $id]['view'] = $profile->content;