protected function OgMenuTrait::createOgMenuInstance in Organic Groups Menu (OG Menu) 8
Created an OG Menu instance for a given group.
Parameters
string $group_id: The id of the group that this menu will belong to.
string $type: The OG Menu bundle.
Return value
\Drupal\Core\Entity\EntityInterface The newly created menu instance.
Throws
\Exception If the saving was unsuccessful.
File
- src/
Tests/ Traits/ OgMenuTrait.php, line 52
Class
- OgMenuTrait
- Helper methods to use in OG Menu tests.
Namespace
Drupal\og_menu\Tests\TraitsCode
protected function createOgMenuInstance($group_id, $type) {
$values = [
'type' => $type,
OgGroupAudienceHelperInterface::DEFAULT_FIELD => $group_id,
];
$og_menu_instance = OgMenuInstance::create($values);
$og_menu_instance
->save();
if ($og_menu_instance
->id()) {
return $og_menu_instance;
}
throw new \Exception('Unable to save menu instance.');
}