You are here

public function GroupMenuConfigOverrides::loadOverrides in Group Menu 8

Returns config overrides.

Parameters

array $names: A list of configuration names that are being loaded.

Return value

array An array keyed by configuration name of override data. Override data contains a nested array structure of overrides.

Overrides ConfigFactoryOverrideInterface::loadOverrides

File

src/GroupMenuConfigOverrides.php, line 89

Class

GroupMenuConfigOverrides
Group menu configuration overrides.

Namespace

Drupal\groupmenu

Code

public function loadOverrides($names) {
  $overrides = [];
  $node_type_names = array_filter($names, function ($name) {
    return strpos($name, 'node.type') === 0;
  });
  if (!empty($node_type_names)) {
    foreach ($node_type_names as $node_type_name) {
      if (isset($this->overrides[$node_type_name])) {
        $overrides[$node_type_name] = $this->overrides[$node_type_name];
      }
      else {
        $current_config = $this
          ->getConfig($node_type_name);

        // We first get a list of all group types where the node type plugin
        // has enabled the setting to show group menus. With those group
        // types we can get all the group menu content types to look for
        // actual group menu content. Once we have the group menu content, we
        // can check their groups to see if the user has permissions to edit
        // the menus.
        $group_types = $this
          ->getEnabledGroupMenuTypesByNodeType($current_config['type']);
        if ($group_types && ($menus = $this
          ->getUserGroupMenuIdsByGroupTypes($group_types))) {
          $overrides[$node_type_name] = [
            'third_party_settings' => [
              'menu_ui' => [
                'available_menus' => array_merge($current_config['third_party_settings']['menu_ui']['available_menus'], $menus),
              ],
            ],
          ];

          // Add result to static cache.
          $this->overrides[$node_type_name] = $overrides[$node_type_name];
        }
      }
    }
  }
  return $overrides;
}