You are here

public function GroupContentEnablerManager::installEnforced in Group 8

Installs all plugins which are marked as enforced.

Parameters

\Drupal\group\Entity\GroupTypeInterface $group_type: (optional) The group type to install enforced plugins on. Leave blank to run the installation process for all group types.

Overrides GroupContentEnablerManagerInterface::installEnforced

File

src/Plugin/GroupContentEnablerManager.php, line 323

Class

GroupContentEnablerManager
Manages GroupContentEnabler plugin implementations.

Namespace

Drupal\group\Plugin

Code

public function installEnforced(GroupTypeInterface $group_type = NULL) {
  $enforced = [];

  // Gather the ID of all plugins that are marked as enforced.
  foreach ($this
    ->getDefinitions() as $plugin_id => $plugin_info) {
    if ($plugin_info['enforced']) {
      $enforced[] = $plugin_id;
    }
  }

  // If no group type was specified, we check all of them.

  /** @var \Drupal\group\Entity\GroupTypeInterface[] $group_types */
  $group_types = empty($group_type) ? $this
    ->getGroupTypeStorage()
    ->loadMultiple() : [
    $group_type,
  ];

  // Search through all of the enforced plugins and install new ones.
  foreach ($group_types as $group_type) {
    $installed = $this
      ->getInstalledIds($group_type);
    foreach ($enforced as $plugin_id) {
      if (!in_array($plugin_id, $installed)) {
        $this
          ->getGroupContentTypeStorage()
          ->createFromPlugin($group_type, $plugin_id)
          ->save();
      }
    }
  }
}