2

I have been using the Group module with D7 for a while, but I always regretted that there was no 'creation date' value for each group. I added a column in my database which fills in that value automatically, but I would like it to be part of the object group so that I can retrieve the value more easily. Ideally I want to be able to do this:

$group = group_load($gid);
$thedate = $group->creation_date;

How should I go about it? Thanks.

1

Groups are fieldable entities, so you could add a field with a fieldname of, say, creation_date.

And if you'd then use the Rules module, you could create a custom rule like so:

  • Rules Event: After saving a new group.
  • Rules Action: Set a data value, i.e. to set the value of your creation_date field.

Note: If the field (like such creation_date field) does not show up within the Rules Action to be added, you may have to first add a Rules Condition like "Entity has field".

  • Alternatively, you could implement hook_entity_info_alter and complimentary entity hooks to add creation_date as a property of the entity, – Kevin Sep 23 '16 at 13:22
  • I have created a field as suggested, but in the Rules, it does not show the field (or any other which I had created before for the group). I may need to specifiy that I have two different group types and I have added the field to only one of them. – Pierre_colin Sep 26 '16 at 16:07
  • @Pierre_colin Try adding a Rules Condition like "Entity has field" (for such "creation_date" field). That may help to have that field show up within Rules Actions. – Pierre.Vriens Sep 26 '16 at 16:10
  • Great! this did the trick, but I had to do what you suggested, Pierre, otherwise the Views would not have suggested the field in the first place. – Pierre_colin Sep 27 '16 at 8:10
  • Also, to be noted, I have a rule to set the data value, but actually you can set a default value for the date field to 'now', which would do the same thing as the rule! – Pierre_colin Sep 27 '16 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.