Skip to content

Commit

Permalink
Merge pull request #14 from argiepiano/1.x-1.x-issue-13
Browse files Browse the repository at this point in the history
Issue #13. Make Profile Rules-ready
  • Loading branch information
bugfolder authored Oct 15, 2022
2 parents 447945c + 81f3f36 commit a3c3601
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
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,
);
}
}
13 changes: 13 additions & 0 deletions profile.module
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function profile_entity_info() {
'uri callback' => 'entity_class_uri',
'access callback' => 'profile_access',
'module' => 'profile',
'metadata controller class' => 'ProfileMetadataController',
'token type' => 'profile',
),
);

Expand All @@ -80,6 +82,16 @@ function profile_entity_info() {
return $return;
}

/**
* Implements hook_entity_info_alter().
*/
function profile_entity_info_alter(&$entity_info) {
// Switch to the controller provided by Entity Plus if available.
if (module_exists('entity_plus')) {
$entity_info['profile']['controller class'] = 'EntityPlusController';
}
}

/**
* Menu argument loader; Load a profile type by string.
*
Expand Down Expand Up @@ -1051,6 +1063,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 a3c3601

Please sign in to comment.