You are here

public function OgMenuBlock::getOgMenuInstance in Organic Groups Menu (OG Menu) 8

Gets the ogmenu_instance for the current og group.

Return value

mixed The instance of the og menu or null if no instance is found.

2 calls to OgMenuBlock::getOgMenuInstance()
OgMenuBlock::build in src/Plugin/Block/OgMenuBlock.php
Builds and returns the renderable array for this block plugin.
OgMenuBlock::getMenuName in src/Plugin/Block/OgMenuBlock.php
Returns a name for the og menu.

File

src/Plugin/Block/OgMenuBlock.php, line 274

Class

OgMenuBlock
Provides a generic Menu block.

Namespace

Drupal\og_menu\Plugin\Block

Code

public function getOgMenuInstance() {
  $entity = $this
    ->getContext('og')
    ->getContextData()
    ->getValue();
  $entity_id = $entity
    ->id();
  $instances = $this->entityTypeManager
    ->getStorage('ogmenu_instance')
    ->loadByProperties([
    'type' => $this
      ->getDerivativeId(),
    OgGroupAudienceHelperInterface::DEFAULT_FIELD => $entity_id,
  ]);
  if ($instances) {
    return array_pop($instances);
  }
  return NULL;
}