You are here

public function GlobalTemplateCollectionManager::createLocalCollectionForGlobalCollection in Courier 8

Same name and namespace in other branches
  1. 2.x src/Service/GlobalTemplateCollectionManager.php \Drupal\courier\Service\GlobalTemplateCollectionManager::createLocalCollectionForGlobalCollection()

Create a global template collection and associate it with a template collection.

Parameters

\Drupal\courier\Entity\GlobalTemplateCollectionInterface $global_template_collection: A global template collection entity.

Return value

\Drupal\courier\TemplateCollectionInterface A template collection entity.

Throws

\Drupal\courier\Exception\GlobalTemplateCollectionException Thrown if passed global template collection is unsaved.

Overrides GlobalTemplateCollectionManagerInterface::createLocalCollectionForGlobalCollection

1 call to GlobalTemplateCollectionManager::createLocalCollectionForGlobalCollection()
GlobalTemplateCollectionManager::getLocalCollection in src/Service/GlobalTemplateCollectionManager.php
Locate, and optionally instantiate, a local template collection to associate a global template collection.

File

src/Service/GlobalTemplateCollectionManager.php, line 94

Class

GlobalTemplateCollectionManager
The global template collection manager.

Namespace

Drupal\courier\Service

Code

public function createLocalCollectionForGlobalCollection(GlobalTemplateCollectionInterface $global_template_collection) {
  if ($global_template_collection
    ->isNew()) {
    throw new GlobalTemplateCollectionException('Global template collection must be saved to instantiate a new template collection.');
  }
  $template_collection = TemplateCollection::create();
  $this->courierManager
    ->addTemplates($template_collection);

  // Load in the configuration from this config.
  foreach ($global_template_collection
    ->getTemplates() as $template_config) {
    $template = $template_collection
      ->getTemplate($template_config['type']);
    if ($template) {
      $template
        ->importTemplate($template_config['content']);
    }
  }
  $template_collection
    ->save();
  $this->keyValueStore
    ->set($global_template_collection
    ->id(), $template_collection
    ->id());
  return $template_collection;
}