문제

How to assign an entity to a group programmatically? I have referred to this question however it doesn't seems to work:

$values = array(
    'type' => 'my_type',
    'uid' => $user->uid,
    'status' => 1,
    'comment' => 1,
    'promote' => 0,
);
$entity = entity_create('node', $values);
$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper->body->set(array('value' => $form_state['values']['body']));
$ewrapper->save();
$result = og_group('node', $form_state['values']['group_id'], ['entity type' => 'node', 'entity' => $ewrapper, 'state' => OG_STATE_ACTIVE]);
$ewrapper->save();
도움이 되었습니까?

해결책

According to the API documentation, my code was missing an underscore character, and I should pass in the entity. So instead of

$result = og_group('node', $form_state['values']['group_id'], ['entity type' => 'node', 'entity' => $ewrapper, 'state' => OG_STATE_ACTIVE]);

it should be

$result = og_group('node', $form_state['values']['group_id'], ['entity_type' => 'node', 'entity' => $entity->nid, 'state' => OG_STATE_ACTIVE]);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 drupal.stackexchange
scroll top