I just figured out how to remove a block: https://forum.backdropcms.org/forum/how-remove-block-layout-during-install

Now, I'm trying to place a block. There are two things that must happen:

  1. I have to define the block in the layout.layout.dashboard.json file
  2. I have to place the block in the correct region in the same file. 

I can place the block with something like this:

config_set('layout.layout.dashboard','positions.half1', array('e44a8a0c-7179-4e1f-b505-5b9d32823a4f, 8ebebe78-4aa4-4d08-a79f-2463daf79863, f149b0ac-ff4c-46f5-8402-ee1aac572dfb'));

Right now, I am having trouble defining the block. I tried this, but it got an error: "syntax error, unexpected ‘$block’ (T_VARIABLE)"

$uuid = 'e44a8a0c-7179-4e1f-b505-5b9d32823a4f';
​
$block = array(
  'plugin' => 'dashboard_plus:manage_content',
  'data' => array(
    'module' => 'dashboard_plus',
    'delta' => 'manage_content',
    'settings' => array(
      'title_display' => 'default',
      'title' => '',
      'style' => 'default',
      'block_settings' => array(
      ),
      'contexts' => array(),
    ),
    'uuid' => $uuid,
    'style' => array(
      'plugin' => 'default',
      'data' => array(
        'settings' => array(
          'classes' => '',
        ),
      ),
    ),
  ),
);
​
config_set('layout.layout.dashboard', "content.$uuid", $block);

How can I fix this?

 

Accepted answer

I got it. The following adds a block from the dashboard plus module to the dashboard layout. 

$uuid = 'e44a8a0c-7179-4e1f-b505-5b9d32823a4f';

$block = array(
  'content.' . $uuid => array(
    'plugin' => 'dashboard_plus:manage_content',
    'data' => array(
      'module' => 'dashboard_plus',
      'delta' => 'manage_content',
      'settings' => array(
        'title_display' => 'default',
        'title' => '',
        'style' => 'default',
        'block_settings' => '',
        'contexts' => '',
        'types' => '',
      ),
      'uuid' => $uuid,
      'style' => array(
        'plugin' => 'default',
        'data' => array(
          'settings' => array(
            'classes' => '',
          ),
        ),
      ),
    ),
  ),
);

config_set_multiple('layout.layout.dashboard', $block );
config_set('layout.layout.dashboard','positions.half1', array('e44a8a0c-7179-4e1f-b505-5b9d32823a4f', '8ebebe78-4aa4-4d08-a79f-2463daf79863', 'f149b0ac-ff4c-46f5-8402-ee1aac572dfb'));

I believe that there were a couple of problems with the first iteration of the code.

  1. "content.$uuid" should have been 'content.' . $uuid
  2. I am not sure if it was necessary, but in the end I used config_set_multiple instead of config_set
  3. Also the $block array did not have all the values it needed. 

Comments

I got it. The following adds a block from the dashboard plus module to the dashboard layout. 

$uuid = 'e44a8a0c-7179-4e1f-b505-5b9d32823a4f';

$block = array(
  'content.' . $uuid => array(
    'plugin' => 'dashboard_plus:manage_content',
    'data' => array(
      'module' => 'dashboard_plus',
      'delta' => 'manage_content',
      'settings' => array(
        'title_display' => 'default',
        'title' => '',
        'style' => 'default',
        'block_settings' => '',
        'contexts' => '',
        'types' => '',
      ),
      'uuid' => $uuid,
      'style' => array(
        'plugin' => 'default',
        'data' => array(
          'settings' => array(
            'classes' => '',
          ),
        ),
      ),
    ),
  ),
);

config_set_multiple('layout.layout.dashboard', $block );
config_set('layout.layout.dashboard','positions.half1', array('e44a8a0c-7179-4e1f-b505-5b9d32823a4f', '8ebebe78-4aa4-4d08-a79f-2463daf79863', 'f149b0ac-ff4c-46f5-8402-ee1aac572dfb'));

I believe that there were a couple of problems with the first iteration of the code.

  1. "content.$uuid" should have been 'content.' . $uuid
  2. I am not sure if it was necessary, but in the end I used config_set_multiple instead of config_set
  3. Also the $block array did not have all the values it needed.