From 57f683b7cdcadd4eabb5620b426c4d3453943c62 Mon Sep 17 00:00:00 2001 From: argiepiano Date: Mon, 3 Oct 2022 20:59:51 -0600 Subject: [PATCH] Issue #13. Make Profile Rules-ready Fixes #13 --- profile.info | 1 + profile.info.inc | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ profile.module | 2 ++ 3 files changed, 84 insertions(+) create mode 100644 profile.info.inc diff --git a/profile.info b/profile.info index ada65b5..8f0c4b2 100644 --- a/profile.info +++ b/profile.info @@ -3,3 +3,4 @@ description = Supports configurable user profiles. backdrop = 1.x configure = admin/structure/profiles type = module +dependencies[] = entity_plus diff --git a/profile.info.inc b/profile.info.inc new file mode 100644 index 0000000..298ac02 --- /dev/null +++ b/profile.info.inc @@ -0,0 +1,81 @@ +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' => 'profile_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; + } +} + +/** + * Implements hook_entity_property_info_alter(). + */ +function profile_entity_property_info_alter(&$info) { + // Add related profiles to the user object. + $properties = &$info['user']['properties']; + foreach (profile_get_types() as $type_name => $type) { + $properties['profile_' . $type_name] = array( + 'type' => 'profile', + 'label' => t('@type_name profile', array('@type_name' => backdrop_ucfirst($type->label))), + 'description' => t("The users's @type_name profile.", array('@type_name' => $type->label)), + 'getter callback' => 'profile_user_get_properties', + 'bundle' => $type_name, + ); + } +} diff --git a/profile.module b/profile.module index 35da698..c8bccd8 100644 --- a/profile.module +++ b/profile.module @@ -60,6 +60,7 @@ function profile_entity_info() { 'uri callback' => 'entity_class_uri', 'access callback' => 'profile_access', 'module' => 'profile', + 'metadata controller class' => 'ProfileMetadataController', ), ); @@ -1051,6 +1052,7 @@ function profile_user_get_properties($account, array $options, $name) { function profile_autoload_info() { return array( 'Profile' => 'profile.entity.inc', + 'ProfileMetadataController' => 'profile.info.inc', ); }