diff --git a/lib/Drupal/profile2/Profile.php b/lib/Drupal/profile2/Profile.php index bc8d6c9..a32f8aa 100644 --- a/lib/Drupal/profile2/Profile.php +++ b/lib/Drupal/profile2/Profile.php @@ -64,7 +64,7 @@ class Profile extends Entity { 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'])) { + if (!isset($values['label']) && isset($values['type']) && $type = entity_load('profile2_type', $values['type'])) { // Initialize the label with the type label, so newly created profiles // have that as interim label. $values['label'] = $type->label; @@ -95,7 +95,7 @@ class Profile extends Entity { * @return ProfileType */ public function type() { - return profile2_type_load($this->type); + return entity_load('profile2_type', $this->type); } /** diff --git a/lib/Drupal/profile2/ProfileTypeFormController.php b/lib/Drupal/profile2/ProfileTypeFormController.php index 2ef062e..df2f4d7 100644 --- a/lib/Drupal/profile2/ProfileTypeFormController.php +++ b/lib/Drupal/profile2/ProfileTypeFormController.php @@ -32,7 +32,7 @@ class ProfileTypeFormController extends EntityFormController { '#default_value' => $type->id(), '#maxlength' => 32, '#machine_name' => array( - 'exists' => 'profile2_type_load', + 'exists' => 'profile2_type_exists', ), ); $form['registration'] = array( @@ -66,5 +66,5 @@ class ProfileTypeFormController extends EntityFormController { $type = $this->getEntity($form_state); $form_state['redirect'] = 'admin/structure/profiles/manage/' . $type->id() . '/delete'; } - + } diff --git a/lib/Drupal/profile2/Tests/ProfileEditTest.php b/lib/Drupal/profile2/Tests/ProfileEditTest.php index 181b3ca..02358f7 100644 --- a/lib/Drupal/profile2/Tests/ProfileEditTest.php +++ b/lib/Drupal/profile2/Tests/ProfileEditTest.php @@ -93,7 +93,7 @@ class ProfileEditTest extends WebTestBase { $this->assertEqual($profiles['test2']->pid, $profiles2['test2']->pid, 'Profile successfully updated.'); // Delete a profile type. - profile2_type_load('test')->delete(); + entity_load('profile2_type', 'test')->delete(); // Try deleting multiple profiles by deleting all existing profiles. $pids = array_keys(entity_load_multiple('profile2')); diff --git a/profile2.module b/profile2.module index 9f16819..af6e562 100644 --- a/profile2.module +++ b/profile2.module @@ -214,7 +214,7 @@ function profile2_menu_local_tasks_alter(&$data, $router_item, $root_path) { } } // Expand the dynamic %profile_menu argument into a tab for each type. - $types = profile2_get_types(); + $types = entity_load_multiple('profile2_type'); foreach ($types as $type) { // If the current page is the active tab registered in hook_menu(), then // the menu router item with the dynamic argument will be exposed already. @@ -251,16 +251,16 @@ function profile2_type_list_page() { } /** - * Menu argument loader; Load a profile type by string. + * Checks if a profile type already exists. * - * @param string $id - * The machine-readable name of a profile type to load. + * @param string $type + * The machine-readable name of a profile type. * - * @return Drupal\profile2\ProfileType|false - * A profile type array or FALSE if $type does not exist. + * @return bool + * TRUE if the given profile type already exists, FALSE otherwise. */ -function profile2_type_load($id) { - return entity_load('profile2_type', $id); +function profile2_type_exists($type) { + return entity_load('profile2_type', $type) ? TRUE : FALSE; } /** @@ -278,7 +278,7 @@ function profile2_permission() { ), ); // Generate per profile type permissions. - foreach (profile2_get_types() as $type) { + foreach (entity_load_multiple('profile2_type') as $type) { $type_name = $type->id(); $permissions += array( "edit own $type_name profile" => array( @@ -299,16 +299,6 @@ function profile2_permission() { } /** - * Gets an array of all profile types, keyed by the machine name. - * - * @return array - * An array of profile type objects. - */ -function profile2_get_types() { - return entity_load_multiple('profile2_type'); -} - -/** * Implements hook_user_predelete(). */ function profile2_user_predelete($account) { @@ -321,7 +311,7 @@ function profile2_user_predelete($account) { * Implements hook_user_view(). */ function profile2_user_view($account, $view_mode, $langcode) { - foreach (profile2_get_types() as $id => $type) { + foreach (entity_load_multiple('profile2_type') as $id => $type) { if ($type->userView && $profile = entity_load_multiple_by_properties('profile2', array('uid' => $account->uid, 'type' => $id))) { if (profile2_access('view', $profile)) { $account->content['profile_' . $id] = array( @@ -340,7 +330,7 @@ function profile2_user_view($account, $view_mode, $langcode) { * Implements hook_form_FORM_ID_alter() for the registration form. */ function profile2_form_user_register_form_alter(&$form, &$form_state) { - foreach (profile2_get_types() as $id => $type) { + foreach (entity_load_multiple('profile2_type') as $id => $type) { if ($type->get('registration')) { if (empty($form_state['profiles'][$id])) { $form_state['profiles'][$id] = entity_create('profile2', array('type' => $id));