diff --git a/contrib/profile2_page.module b/contrib/profile2_page.module index 215075b..798925a 100644 --- a/contrib/profile2_page.module +++ b/contrib/profile2_page.module @@ -160,19 +160,6 @@ function profile2_page_forms($form_id, $args) { } /** - * Implements hook_profile2_type_load(). - */ -function profile2_page_profile2_type_load($types) { - foreach ($types as $type) { - if (!empty($type->data['use_page'])) { - // Disable user categories and the user account view. - $type->userCategory = FALSE; - $type->userView = FALSE; - } - } -} - -/** * Implements hook_entity_info_alter(). */ function profile2_page_entity_info_alter(&$entity_info) { diff --git a/lib/Drupal/profile2/MetadataController.php b/lib/Drupal/profile2/MetadataController.php deleted file mode 100644 index 4ad55f6..0000000 --- a/lib/Drupal/profile2/MetadataController.php +++ /dev/null @@ -1,69 +0,0 @@ -type]['properties']; - - $properties['label'] = array( - 'label' => t('Label'), - 'description' => t('The profile label.'), - 'setter callback' => 'entity_property_verbatim_set', - 'setter permission' => 'administer profiles', - 'schema field' => 'label', - ); - - $properties['type'] = array( - 'type' => 'profile2_type', - 'getter callback' => 'entity_property_getter_method', - 'setter callback' => 'entity_property_verbatim_set', - 'setter permission' => 'administer profiles', - 'required' => TRUE, - 'description' => t('The profile type.'), - ) + $properties['type']; - - unset($properties['uid']); - - $properties['user'] = array( - 'label' => t("User"), - 'type' => 'user', - 'description' => t("The owner of the profile."), - 'getter callback' => 'entity_property_getter_method', - 'setter callback' => 'entity_property_setter_method', - 'setter permission' => 'administer profiles', - 'required' => TRUE, - 'schema field' => 'uid', - ); - - $properties['created'] = array( - 'label' => t("Date created"), - 'type' => 'date', - 'description' => t("The date the profile was created."), - 'setter callback' => 'entity_property_verbatim_set', - 'setter permission' => 'administer profiles', - 'schema field' => 'created', - ); - $properties['changed'] = array( - 'label' => t("Date changed"), - 'type' => 'date', - 'schema field' => 'changed', - 'description' => t("The date the profile was most recently updated."), - ); - - return $info; - } -} - diff --git a/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php b/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php index 294e7e8..fd569b8 100644 --- a/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php +++ b/lib/Drupal/profile2/Plugin/Core/Entity/Profile.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\profile2\Plugin\Core\Entity\Profile. + * Contains Drupal\profile2\Plugin\Core\Entity\Profile. */ namespace Drupal\profile2\Plugin\Core\Entity; @@ -96,21 +96,21 @@ class Profile extends Entity implements ContentEntityInterface { public $changed; /** - * Overrides Drupal\Core\Entity\Entity::id(). + * Overrides Entity::id(). */ public function id() { return isset($this->pid) ? $this->pid : NULL; } /** - * Overrides Drupal\Core\Entity\Entity::bundle(). + * Overrides Entity::bundle(). */ public function bundle() { return $this->type; } /** - * Overrides Drupal\Core\Entity\Entity::label(). + * Overrides Entity::label(). */ public function label($langcode = NULL) { if (isset($this->label) && $this->label !== '') { diff --git a/lib/Drupal/profile2/Plugin/Core/Entity/ProfileType.php b/lib/Drupal/profile2/Plugin/Core/Entity/ProfileType.php index 2a6236c..da869ab 100644 --- a/lib/Drupal/profile2/Plugin/Core/Entity/ProfileType.php +++ b/lib/Drupal/profile2/Plugin/Core/Entity/ProfileType.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\profile2\Plugin\Core\Entity\ProfileType. + * Contains Drupal\profile2\Plugin\Core\Entity\ProfileType. */ namespace Drupal\profile2\Plugin\Core\Entity; @@ -33,27 +33,39 @@ use Drupal\Core\Config\Entity\ConfigEntityBase; */ class ProfileType extends ConfigEntityBase { + /** + * The primary identifier of the profile type. + * + * @var integer + */ public $id; - public $uuid; - public $label; - public $weight = 0; + /** + * The universally unique identifier of the profile type. + * + * @var string + */ + public $uuid; /** - * Whether profile type is shown during registration. + * The human-readable name of the profile type. * - * @var boolean + * @var string */ - public $registration = FALSE; + public $label; /** - * Whether the profile type appears in the user categories. + * Whether the profile type is shown during registration. + * + * @var boolean */ - public $userCategory = TRUE; + public $registration = FALSE; /** - * Whether the profile is displayed on the user account page. + * The weight of the profile type compared to others. + * + * @var integer */ - public $userView = TRUE; + public $weight = 0; } diff --git a/lib/Drupal/profile2/ProfileFormController.php b/lib/Drupal/profile2/ProfileFormController.php index 41681ad..ccc4bb0 100644 --- a/lib/Drupal/profile2/ProfileFormController.php +++ b/lib/Drupal/profile2/ProfileFormController.php @@ -15,7 +15,7 @@ use Drupal\Core\Entity\EntityFormController; class ProfileFormController extends EntityFormController { /** - * Overrides Drupal\Core\Entity\EntityFormController::actionsElement(). + * Overrides EntityFormController::actionsElement(). */ protected function actionsElement(array $form, array &$form_state) { $element = parent::actionsElement($form, $form_state); @@ -28,7 +28,7 @@ class ProfileFormController extends EntityFormController { } /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). + * Overrides EntityFormController::save(). */ public function save(array $form, array &$form_state) { $profile = $this->getEntity($form_state); @@ -43,7 +43,7 @@ class ProfileFormController extends EntityFormController { } /** - * Overrides Drupal\Core\Entity\EntityFormController::delete(). + * Overrides EntityFormController::delete(). */ public function delete(array $form, array &$form_state) { $profile = $this->getEntity($form_state); diff --git a/lib/Drupal/profile2/ProfileStorageController.php b/lib/Drupal/profile2/ProfileStorageController.php index 808986e..b96959b 100644 --- a/lib/Drupal/profile2/ProfileStorageController.php +++ b/lib/Drupal/profile2/ProfileStorageController.php @@ -16,7 +16,7 @@ use Drupal\Core\Entity\EntityInterface; class ProfileStorageController extends DatabaseStorageController { /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::create(). + * Overrides DatabaseStorageController::create(). */ public function create(array $values) { $entity = parent::create($values); @@ -30,7 +30,7 @@ class ProfileStorageController extends DatabaseStorageController { } /** - * Overrides Drupal\Core\Entity\DatabaseStorageController::preSave(). + * Overrides DatabaseStorageController::preSave(). */ protected function preSave(EntityInterface $entity) { // Before saving the profile set the 'changed' timestamp. diff --git a/lib/Drupal/profile2/ProfileTypeFormController.php b/lib/Drupal/profile2/ProfileTypeFormController.php index 007aca3..10a0cd1 100644 --- a/lib/Drupal/profile2/ProfileTypeFormController.php +++ b/lib/Drupal/profile2/ProfileTypeFormController.php @@ -16,7 +16,7 @@ use Drupal\Core\Entity\EntityFormController; class ProfileTypeFormController extends EntityFormController { /** - * Overrides Drupal\Core\Entity\EntityFormController::form(). + * Overrides EntityFormController::form(). */ function form(array $form, array &$form_state, EntityInterface $type) { $form['label'] = array( @@ -44,7 +44,7 @@ class ProfileTypeFormController extends EntityFormController { } /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). + * Overrides EntityFormController::save(). */ public function save(array $form, array &$form_state) { $type = $this->getEntity($form_state); @@ -60,7 +60,7 @@ class ProfileTypeFormController extends EntityFormController { } /** - * Overrides Drupal\Core\Entity\EntityFormController::delete(). + * Overrides EntityFormController::delete(). */ public function delete(array $form, array &$form_state) { $type = $this->getEntity($form_state); diff --git a/lib/Drupal/profile2/ProfileTypeListController.php b/lib/Drupal/profile2/ProfileTypeListController.php index 982ee19..7012079 100644 --- a/lib/Drupal/profile2/ProfileTypeListController.php +++ b/lib/Drupal/profile2/ProfileTypeListController.php @@ -16,7 +16,7 @@ use Drupal\Core\Entity\EntityListController; class ProfileTypeListController extends EntityListController { /** - * Overrides Drupal\Core\Entity\EntityListController::getOperations(). + * Overrides EntityListController::getOperations(). */ public function getOperations(EntityInterface $entity) { $operations = parent::getOperations($entity); diff --git a/lib/Drupal/profile2/ProfileTypeStorageController.php b/lib/Drupal/profile2/ProfileTypeStorageController.php index cfe5a4e..90b4ac8 100644 --- a/lib/Drupal/profile2/ProfileTypeStorageController.php +++ b/lib/Drupal/profile2/ProfileTypeStorageController.php @@ -16,7 +16,7 @@ use Drupal\Core\Entity\EntityInterface; class ProfileTypeStorageController extends ConfigStorageController { /** - * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::postSave(). + * Overrides ConfigStorageController::postSave(). */ protected function postSave(EntityInterface $entity, $update) { parent::postSave($entity, $update); @@ -30,7 +30,7 @@ class ProfileTypeStorageController extends ConfigStorageController { } /** - * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::preDelete(). + * Overrides ConfigStorageController::preDelete(). */ protected function preDelete($entities) { // Delete all profiles of this type. @@ -40,7 +40,7 @@ class ProfileTypeStorageController extends ConfigStorageController { } /** - * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::postDelete(). + * Overrides ConfigStorageController::postDelete(). */ protected function postDelete($entities) { parent::postDelete($entities); diff --git a/lib/Drupal/profile2/TypeUIController.php b/lib/Drupal/profile2/TypeUIController.php deleted file mode 100644 index 1b3c526..0000000 --- a/lib/Drupal/profile2/TypeUIController.php +++ /dev/null @@ -1,26 +0,0 @@ -path]['description'] = 'Manage profiles, including fields.'; - return $items; - } -} - diff --git a/profile2.api.php b/profile2.api.php index 02cdffb..ffe8a85 100644 --- a/profile2.api.php +++ b/profile2.api.php @@ -7,271 +7,15 @@ * Drupal manner. */ +use Drupal\profile2\Plugin\Core\Entity\Profile; +use Drupal\user\Plugin\Core\Entity\User; + /** * @addtogroup hooks * @{ */ /** -* Act on profiles being loaded from the database. -* -* This hook is invoked during profile loading, which is handled by -* entity_load(), via the EntityCRUDController. -* -* @param $entities -* An array of profile2 entities being loaded, keyed by id. -* -* @see hook_entity_load() -*/ -function hook_profile2_load($entities) { - $result = db_query('SELECT pid, foo FROM {mytable} WHERE pid IN(:ids)', array(':ids' => array_keys($entities))); - foreach ($result as $record) { - $entities[$record->pid]->foo = $record->foo; - } -} - -/** -* Respond when a profile is inserted. -* -* This hook is invoked after the profile is inserted into the database. -* -* @param profile -* The profile that is being inserted. -* -* @see hook_entity_insert() -*/ -function hook_profile2_insert($profile) { - db_insert('mytable') - ->fields(array( - 'pid' => $profile->pid, - 'extra' => $profile->extra, - )) - ->execute(); -} - -/** -* Act on a profile being inserted or updated. -* -* This hook is invoked before the profile is saved to the database. -* -* @param $profile -* The profile that is being inserted or updated. -* -* @see hook_entity_presave() -*/ -function hook_profile2_presave($profile) { - $profile->extra = 'foo'; -} - -/** -* Respond to a profile being updated. -* -* This hook is invoked after the profile has been updated in the database. -* -* @param $profile -* The $profile that is being updated. -* -* @see hook_entity_update() -*/ -function hook_profile2_update($profile) { - db_update('mytable') - ->fields(array('extra' => $profile->extra)) - ->condition('pid', $profile->pid) - ->execute(); -} - -/** -* Respond to profile deletion. -* -* This hook is invoked after the profile has been removed from the database. -* -* @param $profile -* The profile that is being deleted. -* -* @see hook_entity_delete() -*/ -function hook_profile2_delete($profile) { - db_delete('mytable') - ->condition('pid', $profile->pid) - ->execute(); -} - -/** -* Act on a profile that is being assembled before rendering. -* -* @param $profile -* The profile entity. -* @param $view_mode -* The view mode the profile is rendered in. -* @param $langcode -* The language code used for rendering. -* -* The module may add elements to $profile->content prior to rendering. The -* structure of $profile->content is a renderable array as expected by -* drupal_render(). -* -* @see hook_entity_prepare_view() -* @see hook_entity_view() -*/ -function hook_profile2_view($profile, $view_mode, $langcode) { - $profile->content['my_additional_field'] = array( - '#markup' => $additional_field, - '#weight' => 10, - '#theme' => 'mymodule_my_additional_field', - ); -} - -/** -* Alter the results of entity_view() for profiles. -* -* @param $build -* A renderable array representing the profile content. -* -* This hook is called after the content has been assembled in a structured -* array and may be used for doing processing which requires that the complete -* profile content structure has been built. -* -* If the module wishes to act on the rendered HTML of the profile rather than -* the structured content array, it may use this hook to add a #post_render -* callback. Alternatively, it could also implement hook_preprocess_profile2(). -* See drupal_render() and theme() documentation respectively for details. -* -* @see hook_entity_view_alter() -*/ -function hook_profile2_view_alter($build) { - if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) { - // Change its weight. - $build['an_additional_field']['#weight'] = -10; - - // Add a #post_render callback to act on the rendered HTML of the entity. - $build['#post_render'][] = 'my_module_post_render'; - } -} - -/** - * Act on profile type being loaded from the database. - * - * This hook is invoked during profile type loading, which is handled by - * entity_load(), via the EntityCRUDController. - * - * @param $types - * An array of profiles being loaded, keyed by profile type names. - */ -function hook_profile2_type_load($types) { - if (isset($types['main'])) { - $types['main']->userCategory = FALSE; - $types['main']->userView = FALSE; - } -} - -/** - * Respond when a profile type is inserted. - * - * This hook is invoked after the profile type is inserted into the database. - * - * @param $type - * The profile type that is being inserted. - */ -function hook_profile2_type_insert($type) { - db_insert('mytable') - ->fields(array( - 'id' => $type->id, - 'extra' => $type->extra, - )) - ->execute(); -} - -/** - * Act on a profile type being inserted or updated. - * - * This hook is invoked before the profile type is saved to the database. - * - * @param $type - * The profile type that is being inserted or updated. - */ -function hook_profile2_type_presave($type) { - $type->extra = 'foo'; -} - -/** - * Respond to updates to a profile. - * - * This hook is invoked after the profile type has been updated in the database. - * - * @param $type - * The profile type that is being updated. - */ -function hook_profile2_type_update($type) { - db_update('mytable') - ->fields(array('extra' => $type->extra)) - ->condition('id', $type->id) - ->execute(); -} - -/** - * Respond to profile type deletion. - * - * This hook is invoked after the profile type has been removed from the - * database. - * - * @param $type - * The profile type that is being deleted. - */ -function hook_profile2_type_delete($type) { - db_delete('mytable') - ->condition('id', $type->id) - ->execute(); -} - -/** - * Define default profile type configurations. - * - * @return - * An array of default profile types, keyed by profile type names. - */ -function hook_default_profile2_type() { - $types['main'] = new ProfileType(array( - 'type' => 'main', - 'label' => t('Profile'), - 'weight' => 0, - 'locked' => TRUE, - )); - return $types; -} - -/** -* Alter default profile type configurations. -* -* @param $defaults -* An array of default profile types, keyed by type names. -* -* @see hook_default_profile2_type() -*/ -function hook_default_profile2_type_alter(&$defaults) { - $defaults['main']->label = 'custom label'; -} - -/** - * Alter profile2 forms. - * - * Modules may alter the profile2 entity form regardless to which form it is - * attached by making use of this hook or the profile type specifiy - * hook_form_profile2_edit_PROFILE_TYPE_form_alter(). #entity_builders may be - * used in order to copy the values of added form elements to the entity, just - * as described by entity_form_submit_build_entity(). - * - * @param $form - * Nested array of form elements that comprise the form. - * @param $form_state - * A keyed array containing the current state of the form. - * - * @see profile2_attach_form() - */ -function hook_form_profile2_form_alter(&$form, &$form_state) { - // Your alterations. -} - -/** * Control access to profiles. * * Modules may implement this hook if they want to have a say in whether or not @@ -281,31 +25,25 @@ function hook_form_profile2_form_alter(&$form, &$form_state) { * The operation being performed. One of 'view', 'edit' (being the same as * 'create' or 'update') and 'delete'. * @param $profile - * (optional) A profile to check access for. If nothing is given, access for - * all profiles is determined. + * A profile to check access for. * @param $account - * (optional) The user to check for. If no account is passed, access is - * determined for the global user. + * (optional) The user to check for. Defaults to the currently logged in user. * @return boolean * Return TRUE to grant access, FALSE to explicitly deny access. Return NULL * or nothing to not affect the operation. * Access is granted as soon as a module grants access and no one denies * access. Thus if no module explicitly grants access, access will be denied. - * - * @see profile2_access() */ -function hook_profile2_access($op, $profile = NULL, $account = NULL) { - if (isset($profile)) { - // Explicitly deny access for a 'secret' profile type. - if ($profile->type == 'secret' && !user_access('custom permission')) { - return FALSE; - } - // For profiles other than the default profile grant access. - if ($profile->type != 'main' && user_access('custom permission')) { - return TRUE; - } - // In other cases do not alter access. +function hook_profile2_access($op, Profile $profile, User $account = NULL) { + // Explicitly deny access for a 'secret' profile type. + if ($profile->type == 'secret' && !user_access('custom permission')) { + return FALSE; + } + // For profiles other than the default profile grant access. + if ($profile->type != 'main' && user_access('custom permission')) { + return TRUE; } + // In other cases do not alter access. } /** diff --git a/profile2.info.inc b/profile2.info.inc deleted file mode 100644 index e786084..0000000 --- a/profile2.info.inc +++ /dev/null @@ -1,23 +0,0 @@ - $type) { - $properties['profile_' . $type_name] = array( - 'type' => 'profile2', - 'label' => t('@type_name profile', array('@type_name' => drupal_ucfirst($type->label))), - 'description' => t("The users's @type_name profile.", array('@type_name' => $type->label)), - 'getter callback' => 'profile2_user_get_properties', - 'bundle' => $type_name, - ); - } -} diff --git a/profile2.module b/profile2.module index 2e2333e..59574d1 100644 --- a/profile2.module +++ b/profile2.module @@ -568,13 +568,3 @@ function profile2_field_access($op, $field, $entity_type, $profile = NULL, $acco } } } - -/** - * Entity metadata callback to load profiles for the given user account. - */ -function profile2_user_get_properties($account, array $options, $name) { - // Remove the leading 'profile_' from the property name to get the type name. - $profile = profile2_load_by_user($account, substr($name, 8)); - return $profile ? $profile : NULL; -} -