We have a specific use case (which I'm seeing a lot of people looking for solutions for) that I'm wondering if this module can solve: we want to load default Custom Block Content in to a site so when we add a new Block via configuration, it's not empty/broken.

So, looking at our `block.block.mybanner.yml` config export, the Block saves a reference to the Block Content via UUID like this:
"block_content:867753c9-655b-4e34-969b-47ea4b2077bc"

So to populate it, we need to create new "block_content" that has a specific ID and UUID.

I'm playing around with it, I do appear to be able to create new block content like this:

- entity: "block_content"
  type: "navigation_banner"
  info: "Test Default Banner Update"
  id: 2
  uuid: "867753c9-655b-4e34-969b-47ea4b2077bc"
  field_banner_link: "http://google.com"
  field_banner_text: "test default banner"

But then I can't update it getting a primary key error for ID = 2 when I try. It would be nice to update content by ID when running this import again.

I looks like the way the module is loading the entity in the "entityExists()" method by searching on ALL properties and not just the primary key (ID), it's not updating the existing record, but is instead inserting a new one with the same ID, giving an error.

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

thaddeusmt created an issue. See original summary.

slucero’s picture

The current iteration of the entityExists() method was definitely a first pass at this issue. #2894614: Allow configuration of properties used to match existing entities actually highlights another issue present in the current logic and raises the question of what the desired logic should be.

As a temporary workaround for your issue you may try implementing the list structure solution I described in #2894614-5: Allow configuration of properties used to match existing entities for both the field_banner_link and field_banner_text fields. If both of those are defined using an array structure they should be excluded from the existence checking and your other properties may match correctly. So based on your example, this is the structure I would suggest trying:

- entity: "block_content"
  type: "navigation_banner"
  info: "Test Default Banner Update"
  id: 2
  uuid: "867753c9-655b-4e34-969b-47ea4b2077bc"
  field_banner_link:
    - value: "http://google.com"
  field_banner_text:
    - value: "test default banner"
Xingda’s picture

FileSize
1.13 KB

I also have the same issue, which prompt me uuid about “ Integrity constraint violation, Duplicate entry, for key 'node_field__uuid__value'”, when I debug it, I found actually it is "entity", "uuid" field. If the value is changed, the changed value should be loaded.

I also made patch for convenience.

jasonawant’s picture

Status: Active » Closed (works as designed)

Marking as closed, works as designed since it's been 4 months and I assume the op got the info they were looking for b/c they have not replied.

mgalalm’s picture

FileSize
18.52 KB

Another patch for addressing loading uuid in a different way

mgalalm’s picture

FileSize
803 bytes

last one was wrong

ressa’s picture

I couldn't find any documentation on how to import a basic custom block, but this issue got me started. For others finding this page after searching, this is a config for a custom block import:

- entity: "block_content"
  type: "basic"
  info: "Block title"
  body: "Some text"
  uuid: "81d4ec1f-2c71-4f89-ac15-c12a16eee6f2"

... where my block.block.my_block_name.yml contains this part, containing entity, type and uuid:

dependencies:
  content:
    - 'block_content:basic:81d4ec1f-2c71-4f89-ac15-c12a16eee6f2'