@@ -301,6 +301,70 @@ function acquia_cms_site_studio_editor_insert(EditorInterface $editor) {
301
301
if (!$editor->isSyncing()) {
302
302
// Add text format permission to a developer role.
303
303
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load('developer');
304
- $role->grantPermission('use text format ' . $editor->id())->save(TRUE);
304
+ if ($role instanceof Role) {
305
+ $role->grantPermission('use text format ' . $editor->id())->save(TRUE);
306
+ }
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Helper function to update configuration for specified key.
312
+ *
313
+ * This is being used for updating page CT configurations.
314
+ *
315
+ * @param string $config_name
316
+ * The configuration name which needs to be updated.
317
+ * @param array $configurations
318
+ * An array of drupal configurations.
319
+ */
320
+ function _acquia_cms_site_studio_update_page_configurations(string $config_name, array $configurations) {
321
+ $configFactory = \Drupal::service('config.factory');
322
+ $config = $configFactory->getEditable($config_name);
323
+ $need_save = FALSE;
324
+ if ($config) {
325
+ foreach ($configurations as $key => $value) {
326
+ if ($config->get($key) != $value) {
327
+ $config->set($key, $value);
328
+ $need_save = TRUE;
329
+ }
330
+ }
331
+ // Only save if there's changes in value.
332
+ if ($need_save) {
333
+ $config->save();
334
+ }
335
+ }
336
+ }
337
+
338
+ /**
339
+ * Helper function to update views display_options's style.
340
+ *
341
+ * @param string $view_name
342
+ * The view names.
343
+ * @param string $display_id
344
+ * The view display_id.
345
+ * @param string|null $views_template
346
+ * The view template name.
347
+ *
348
+ * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
349
+ * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
350
+ * @throws \Drupal\Core\Entity\EntityStorageException
351
+ */
352
+ function _acquia_cms_site_studio_update_view_display_options_style(string $view_name, string $display_id = 'default', string $views_template = NULL) {
353
+ /** @var \Drupal\Core\Entity\EntityStorageInterface $view_storage */
354
+ $view_storage = \Drupal::entityTypeManager()->getStorage('view');
355
+ /** @var \Drupal\views\ViewEntityInterface $view */
356
+ $view = $view_storage->load($view_name);
357
+ if (!$view) {
358
+ return;
359
+ }
360
+ $display = &$view->getDisplay($display_id);
361
+ $style_type = $display['display_options']['style']['type'] ?? NULL;
362
+ if ($style_type && $style_type !== 'cohesion_layout') {
363
+ $display['display_options']['style']['type'] = 'cohesion_layout';
364
+ $display['display_options']['style']['options'] = [
365
+ 'views_template' => $views_template ?? 'view_tpl_' . $view_name,
366
+ 'master_template' => 'master_template_boxed',
367
+ ];
368
+ $view_storage->save($view);
305
369
}
306
370
}
0 commit comments