function _paragraphs_collection_demo_add_background_plugin_field

Adds the background plugin field in the container paragraph type.

1 call to _paragraphs_collection_demo_add_background_plugin_field()
paragraphs_collection_demo_install in paragraphs_collection/modules/paragraphs_collection_demo/paragraphs_collection_demo.install
Implements hook_install().

File

paragraphs_collection/modules/paragraphs_collection_demo/paragraphs_collection_demo.install, line 35
Installation hooks for paragraphs_collection_demo module.

Code

function _paragraphs_collection_demo_add_background_plugin_field() {

  // Add the background field to the container form display.
  $container_form_display = EntityFormDisplay::load('paragraph.container.default');
  $content = $container_form_display
    ->get('content');
  $content['paragraphs_background_image'] = [
    'weight' => 1,
    'settings' => [
      'progress_indicator' => 'throbber',
      'preview_image_style' => 'thumbnail',
    ],
    'third_party_settings' => [],
    'type' => 'image_image',
    'region' => 'content',
  ];
  $container_form_display
    ->set('content', $content);
  $dependencies = $container_form_display
    ->get('dependencies');
  $dependencies['config'][] = 'field.field.paragraph.container.paragraphs_background_image';
  $dependencies['config'][] = 'image.style.thumbnail';
  $dependencies['module'][] = 'image';
  $container_form_display
    ->set('dependencies', $dependencies);
  $container_form_display
    ->save();

  // Add the background field to the container view display.
  $container_view_display = EntityViewDisplay::load('paragraph.container.default');
  $content = $container_view_display
    ->get('content');
  $content['paragraphs_background_image'] = [
    'weight' => 1,
    'label' => 'visually_hidden',
    'settings' => [
      'image_style' => '',
      'image_link' => '',
    ],
    'third_party_settings' => [],
    'type' => 'image',
    'region' => 'content',
  ];
  $container_view_display
    ->set('content', $content);
  $dependencies = $container_form_display
    ->get('dependencies');
  $dependencies['config'][] = 'field.field.paragraph.container.paragraphs_background_image';
  $dependencies['module'][] = 'image';
  $container_form_display
    ->set('dependencies', $dependencies);
  $container_view_display
    ->save();
  $container = ParagraphsType::load('container');
  $container
    ->set('behavior_plugins', [
    'background' => [
      'enabled' => TRUE,
      'background_image_field' => 'paragraphs_background_image',
    ],
    'style' => [
      'enabled' => TRUE,
      'groups' => [
        'general_group' => [
          'default' => '',
        ],
      ],
    ],
  ]);
  $container
    ->save();
}