Skip to content

Commit

Permalink
Issue #13. Make Profile Rules-ready
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
argiepiano committed Oct 4, 2022
1 parent 447945c commit 57f683b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions profile.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ description = Supports configurable user profiles.
backdrop = 1.x
configure = admin/structure/profiles
type = module
dependencies[] = entity_plus
81 changes: 81 additions & 0 deletions profile.info.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* @file
* Provides Entity metadata integration.
*/

/**
* Extend the defaults.
*/
class ProfileMetadataController extends EntityDefaultMetadataController {

public function entityPropertyInfo() {
$info = parent::entityPropertyInfo();
$properties = &$info[$this->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,
);
}
}
2 changes: 2 additions & 0 deletions profile.module
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function profile_entity_info() {
'uri callback' => 'entity_class_uri',
'access callback' => 'profile_access',
'module' => 'profile',
'metadata controller class' => 'ProfileMetadataController',
),
);

Expand Down Expand Up @@ -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',
);
}

Expand Down

0 comments on commit 57f683b

Please sign in to comment.