You are here

public function GroupContentTypeStorage::createFromPlugin in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Storage/GroupContentTypeStorage.php \Drupal\group\Entity\Storage\GroupContentTypeStorage::createFromPlugin()

Creates a group content type for a group type using a specific plugin.

Parameters

\Drupal\group\Entity\GroupTypeInterface $group_type: The group type to create the group content type for.

string $plugin_id: The ID of the content enabler plugin to use.

array $configuration: (optional) An array of content enabler plugin configuration.

Return value

\Drupal\group\Entity\GroupContentTypeInterface A new, unsaved GroupContentType entity.

Overrides GroupContentTypeStorageInterface::createFromPlugin

File

src/Entity/Storage/GroupContentTypeStorage.php, line 117

Class

GroupContentTypeStorage
Defines the storage handler class for group content type entities.

Namespace

Drupal\group\Entity\Storage

Code

public function createFromPlugin(GroupTypeInterface $group_type, $plugin_id, array $configuration = []) {

  // Add the group type ID to the configuration.
  $configuration['group_type_id'] = $group_type
    ->id();

  // Instantiate the plugin we are installing.

  /** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
  $plugin = $this->pluginManager
    ->createInstance($plugin_id, $configuration);

  // Create the group content type using plugin generated info.
  $values = [
    'id' => $plugin
      ->getContentTypeConfigId(),
    'label' => $plugin
      ->getContentTypeLabel(),
    'description' => $plugin
      ->getContentTypeDescription(),
    'group_type' => $group_type
      ->id(),
    'content_plugin' => $plugin_id,
    'plugin_config' => $plugin
      ->getConfiguration(),
  ];
  return $this
    ->create($values);
}