0
/**
 * Create Custom solutions blocks for Super Category and Category Pages.
 */
function custom_blocks_update_8008() {
 $values = [
      'uuid' => '7760fb2f-5235-4390-a91b-32568da6b001',
      'info' => 'Hero Blocks',
      'type' => 'hero_blocks',
    ];

    $block_content = \Drupal::entityTypeManager()->getStorage('block_content')->create($values);
    $block_content->setVisibilityConfig(
      'vocabulary_product_category',
       [
         'id' => 'vocabulary_product_category',
         'depth_levels' => [
            1 => 'Super Category',
            2 => 'Category',
         ],
         'negate' => FALSE,
         'context_mapping' => [],
       ]
    );   

    $block_content->save();
}

$block->set() is for setting field value but I need to set
1) ThirdPartysettings
2) VisibilityConfig
3) in custom_block.install

we have setVisibilityConfig method defined in the BlockInterface and
setThirdPartySetting method defined in ThirdPartySettingsInterface but I
am trying to set those values in the BlockContent which does not have any such method
BlockContent ->
https://api.drupal.org/api/drupal/core%21modules%21block_content%21src%21Entity%21BlockContent.php/class/BlockContent/8.6.x
BlockInterface ->
https://api.drupal.org/api/drupal/core%21modules%21block%21src%21BlockInterface.php/function/BlockInterface%3A%3AsetVisibilityConfig/8.2.x
and
ThirdPartySettings
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Config%21Entity%21ThirdPartySettingsInterface.php/function/ThirdPartySettingsInterface%3A%3AsetThirdPartySetting/8.2.x
Should I set it in preprocess or some other place ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.