How to add config entities?!

Created on 6 August 2024, 8 months ago

Problem/Motivation

On the module page it's stated we can create collections of config entities but it seems we actually can't?! Is this a buf?

I tried with Drupal 10.3.1 and collection 3.0.0

💬 Support request
Status

Active

Version

3.0

Component

Documentation

Created by

🇮🇹Italy kopeboy Milan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kopeboy
  • 🇺🇸United States jeffam

    At the moment, you can only add config entities programmatically. This is a limitation of dynamic entity reference, and it looks like there hasn't been much movement on a solution: https://www.drupal.org/project/dynamic_entity_reference/issues/2997727

    Here's an example snippet that adds a taxonomy vocabulary config entity to a collection:

    $vocab = $this->entityTypeManager->getStorage('taxonomy_vocabulary')->create([
      'langcode' => 'en',
      'status' => TRUE,
      'name' => 'My taxonomy vocabulary',
      'vid' => 'my_taxonomy',
    ]);
    $vocab->save();
    
    if ($vocab) {
      // Add the vocab to this new collection.
      $collection_item_vocab = $this->entityTypeManager->getStorage('collection_item')->create([
        'type' => 'default',
        'collection' => 1,
        'canonical' => TRUE,
        'weight' => 10,
      ]);
    
      $collection_item_vocab->item = $vocab;
      $collection_item_vocab->save();
    }
    
  • Status changed to Closed: works as designed 9 days ago
  • 🇺🇸United States jeffam
Production build 0.71.5 2024