Skip to content

Commit b31440c

Browse files
ACMS-4414: Move method from common to site studio and replace accordingly.
1 parent cbda2d6 commit b31440c

File tree

3 files changed

+76
-13
lines changed

3 files changed

+76
-13
lines changed

modules/acquia_cms_site_studio/acquia_cms_site_studio.install

+11-11
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function acquia_cms_site_studio_install($is_syncing) {
4747
$module_handler = \Drupal::service('module_handler');
4848
$entity_type_manager = \Drupal::entityTypeManager();
4949
if ($module_handler->moduleExists('acquia_cms_search')) {
50-
_acquia_cms_common_update_view_display_options_style('search');
51-
_acquia_cms_common_update_view_display_options_style('search_fallback');
50+
_acquia_cms_site_studio_update_view_display_options_style('search');
51+
_acquia_cms_site_studio_update_view_display_options_style('search_fallback');
5252

5353
// Disable acquia_search view provided by Acquia Search Solrmodule,
5454
// so that search view provided by acquia_cms_search module can be used
@@ -74,20 +74,20 @@ function acquia_cms_site_studio_install($is_syncing) {
7474
// Update content views on module install.
7575
if ($module_handler->moduleExists('acquia_cms_search')) {
7676
if ($module_handler->moduleExists('acquia_cms_article')) {
77-
_acquia_cms_common_update_view_display_options_style('articles');
78-
_acquia_cms_common_update_view_display_options_style('articles_fallback');
77+
_acquia_cms_site_studio_update_view_display_options_style('articles');
78+
_acquia_cms_site_studio_update_view_display_options_style('articles_fallback');
7979
}
8080
if ($module_handler->moduleExists('acquia_cms_event')) {
81-
_acquia_cms_common_update_view_display_options_style('events');
82-
_acquia_cms_common_update_view_display_options_style('events_fallback');
81+
_acquia_cms_site_studio_update_view_display_options_style('events');
82+
_acquia_cms_site_studio_update_view_display_options_style('events_fallback');
8383
}
8484
if ($module_handler->moduleExists('acquia_cms_place')) {
85-
_acquia_cms_common_update_view_display_options_style('places');
86-
_acquia_cms_common_update_view_display_options_style('places_fallback');
85+
_acquia_cms_site_studio_update_view_display_options_style('places');
86+
_acquia_cms_site_studio_update_view_display_options_style('places_fallback');
8787
}
8888
if ($module_handler->moduleExists('acquia_cms_person')) {
89-
_acquia_cms_common_update_view_display_options_style('people', 'default', 'view_tpl_people_grid');
90-
_acquia_cms_common_update_view_display_options_style('people_fallback');
89+
_acquia_cms_site_studio_update_view_display_options_style('people', 'default', 'view_tpl_people_grid');
90+
_acquia_cms_site_studio_update_view_display_options_style('people_fallback');
9191
}
9292
}
9393
}
@@ -469,5 +469,5 @@ function acquia_cms_site_studio_update_9001() {
469469
],
470470
];
471471

472-
_acquia_cms_common_update_page_configurations('editor.editor.cohesion', $config_data);
472+
_acquia_cms_site_studio_update_page_configurations('editor.editor.cohesion', $config_data);
473473
}

modules/acquia_cms_site_studio/acquia_cms_site_studio.module

+65-1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,70 @@ function acquia_cms_site_studio_editor_insert(EditorInterface $editor) {
301301
if (!$editor->isSyncing()) {
302302
// Add text format permission to a developer role.
303303
$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);
305369
}
306370
}

modules/acquia_cms_site_studio/composer.json

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"require": {
77
"acquia/cohesion": "~7.4.0 || ~7.5.0 || ~8.0.0 || ~8.1.0",
88
"acquia/cohesion-theme": "~7.4.0 || ~7.5.0 || ~8.0.0 || ~8.1.0",
9-
"drupal/acquia_cms_common": "^2.1.12 || ~3.2.12 || ^3.3.10",
109
"drupal/collapsiblock": "^4.0",
1110
"drupal/node_revision_delete": "^2.0",
1211
"drupal/responsive_preview": "^2.1",

0 commit comments

Comments
 (0)