You are here

public static function ViewModesInventoryFactory::mapViewModeWithLayout in View Modes Inventory - Bootstrap Ready 8

Same name and namespace in other branches
  1. 8.2 src/ViewModesInventoryFactory.php \Drupal\vmi\ViewModesInventoryFactory::mapViewModeWithLayout()

Map a view mode with a layout and default configuration template.

Parameters

string $selected_view_mode: Selected view mode in the custom display settings form.

string $default_mapped_layout: Default mapped layout.

string $entity_type: Entity type like node, block, user.

string $bundle_name: Bundle name.

string $config_template_file: Config template file name.

string $config_name: Config name to map to.

1 call to ViewModesInventoryFactory::mapViewModeWithLayout()
_vmi_form_entity_view_display_edit_form_submit in ./vmi.module
Apply mapped view modes inventory form entity view display edit form submit.

File

src/ViewModesInventoryFactory.php, line 75

Class

ViewModesInventoryFactory
View Modes Inventory Factory.

Namespace

Drupal\vmi

Code

public static function mapViewModeWithLayout($selected_view_mode, $default_mapped_layout, $entity_type, $bundle_name, $config_template_file, $config_name) {

  // Replace CONTENT_TYPE_NAME with the bundle name for the config name.
  $real_config_name = str_replace('CONTENT_TYPE_NAME', $bundle_name, $config_name);
  $view_mode_config = \Drupal::service('config.factory')
    ->getEditable($real_config_name);

  // Load the config template.
  $full_config_template_file = \Drupal::root() . '/' . drupal_get_path('module', 'vmi') . $config_template_file;
  $config_template_content = file_get_contents($full_config_template_file);

  // Replace CONTENT_TYPE_NAME with the bundle name in the config template.
  $real_config_template_content = str_replace('CONTENT_TYPE_NAME', $bundle_name, $config_template_content);

  // Parse real config template conten to data.
  $real_config_template_content_data = (array) Yaml::parse($real_config_template_content);

  // Set and save new message value.
  $view_mode_config
    ->setData($real_config_template_content_data)
    ->save();
}