Skip to content

Commit

Permalink
Fixed Gizra#127 Property & token support for membership incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
geek-merlin committed Jun 6, 2016
2 parents c2147b5 + 75fcdaa commit 07101d2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
43 changes: 39 additions & 4 deletions og.info.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ class OgMembershipMetadataController extends EntityDefaultMetadataController {
'language' => array(),
);

// Group ID is provided in the "group" property.
unset($properties['gid']);
$properties['gid'] += array(
'setter callback' => 'entity_property_verbatim_set',
'required' => TRUE,
);

$properties['group'] = array(
'label' => t("OG group"),
'type' => 'entity',
Expand All @@ -35,8 +38,25 @@ class OgMembershipMetadataController extends EntityDefaultMetadataController {
'required' => TRUE,
);

// Entity id is provided via the "entity" property.
unset($properties['etid']);
// Add a property for all group entity types, in order to use tokens for
// these entities. See https://drupal.org/node/1973686
foreach (og_get_all_group_entity() as $entity_type => $entity_label) {
$properties['group__' . $entity_type] = array(
'label' => $entity_label,
'type' => $entity_type,
'description' => t('The OG group when the group is a !type.', array(
'!type' => $entity_label,
)),
'getter callback' => 'og_entity_getter',
'setter callback' => 'og_entity_setter',
'setter permission' => 'administer group',
);
}

$properties['etid'] += array(
'setter callback' => 'entity_property_verbatim_set',
'required' => TRUE,
);

$properties['entity'] = array(
'label' => t('Entity'),
Expand All @@ -48,6 +68,21 @@ class OgMembershipMetadataController extends EntityDefaultMetadataController {
'required' => TRUE,
);

// Add a property for all group content entity types, in order to use tokens
// for these entities. See https://drupal.org/node/1973686
foreach (og_get_all_group_content_entity() as $entity_type => $entity_label) {
$properties['entity__' . $entity_type] = array(
'label' => $entity_label,
'type' => $entity_type,
'description' => t('The OG entity that is a group content when it is a !type.', array(
'!type' => $entity_label,
)),
'getter callback' => 'og_entity_getter',
'setter callback' => 'og_entity_setter',
'setter permission' => 'administer group',
);
}

$properties['created']['type'] = 'date';
$properties['created'] += array(
'setter callback' => 'entity_property_verbatim_set',
Expand Down
30 changes: 26 additions & 4 deletions og.module
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,25 @@ function og_get_field_og_membership_properties($entity, array $options, $name, $
* We have to return the entity wrapped.
*/
function og_entity_getter($object, array $options, $property_name) {
switch ($property_name) {
// Check that property name contains double underscores, ignoring ones that
// start with a double underscore.
if (strpos($property_name, '__')) {
list($real_property, $sub_property) = explode('__', $property_name, 2);
}
else {
$real_property = $property_name;
}
switch ($real_property) {
case 'entity':
return entity_metadata_wrapper($object->entity_type, $object->etid);
if (empty($sub_property) || $sub_property == $object->entity_type) {
return entity_metadata_wrapper($object->entity_type, $object->etid);
}
break;
case 'group':
return entity_metadata_wrapper($object->group_type, $object->gid);
if (empty($sub_property) || $sub_property == $object->group_type) {
return entity_metadata_wrapper($object->group_type, $object->gid);
}
break;
}
}

Expand All @@ -393,7 +407,15 @@ function og_entity_getter($object, array $options, $property_name) {
* entity.
*/
function og_entity_setter($object, $property_name, $wrapper) {
switch ($property_name) {
// Check that property name contains double underscores, ignoring ones that
// start with a double underscore.
if (strpos($property_name, '__')) {
list($real_property, $sub_property) = explode('__', $property_name, 2);
}
else {
$real_property = $property_name;
}
switch ($real_property) {
case 'entity':
$object->entity_type = $wrapper->type();
$object->etid = $wrapper->getIdentifier();
Expand Down

0 comments on commit 07101d2

Please sign in to comment.