Skip to content

Commit a091ed9

Browse files
ACMS-4237: Remove Dependency of acquia_cms_common from Site Studio. (#1917)
ACMS-4237: Remove Dependency of acquia_cms_common from Site Studio.
1 parent 8157f16 commit a091ed9

20 files changed

+895
-27
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Drupal\Tests\acquia_cms_common\Functional;
4+
5+
use Drupal\Tests\BrowserTestBase;
6+
7+
/**
8+
* Tests the filter filter_html.
9+
*
10+
* @group acquia_cms
11+
* @group acquia_cms_common
12+
*/
13+
class FilterFormatTest extends BrowserTestBase {
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected $defaultTheme = 'stark';
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
protected static $modules = [
24+
'acquia_cms_common',
25+
];
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function setUp(): void {
31+
parent::setUp();
32+
33+
$account = $this->drupalCreateUser(['administer filters']);
34+
$this->drupalLogin($account);
35+
}
36+
37+
/**
38+
* Tests the filter filter_html.
39+
*
40+
* @param string $filter_format
41+
* The filter format name.
42+
* @param bool $status
43+
* Status of the field.
44+
*
45+
* @dataProvider providerFilterFormat
46+
*/
47+
public function testFilterBlackListHtmlTags(string $filter_format, bool $status) {
48+
$assert_session = $this->assertSession();
49+
50+
// Visit the filter page.
51+
$this->drupalGet('/admin/config/content/formats/manage/' . $filter_format);
52+
$assert_session->statusCodeEquals(200);
53+
$filter_element = $assert_session->elementExists('css', '#edit-filters-filter-html-status');
54+
$this->assertSame($status, $filter_element->isChecked(), 'Expect checked, but found uncheck.');
55+
56+
}
57+
58+
/**
59+
* Defines an array of modules & permissions to roles.
60+
*/
61+
public static function providerFilterFormat(): array {
62+
return [
63+
[
64+
'full_html',
65+
TRUE,
66+
],
67+
[
68+
'filtered_html',
69+
TRUE,
70+
],
71+
];
72+
}
73+
74+
}

modules/acquia_cms_site_studio/acquia_cms_site_studio.info.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: 'Module for Site Studio Installation Code.'
44
core_version_requirement: ^9.5 || ^10 || ^11
55
type: module
66
dependencies:
7-
- acquia_cms_common:acquia_cms_common
7+
- drupal:media
88
- cohesion_base_styles # phpcs:ignore
99
- cohesion_custom_styles # phpcs:ignore
1010
- cohesion_elements # phpcs:ignore

modules/acquia_cms_site_studio/acquia_cms_site_studio.install

+12-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Contains install-time code for the Acquia CMS profile.
66
*/
77

8-
use Drupal\acquia_cms_common\Facade\ConfigHandlerFacade;
8+
use Drupal\acquia_cms_site_studio\Facade\ConfigHandlerFacade;
99
use Drupal\cohesion\Controller\AdministrationController;
1010
use Drupal\cohesion_sync\Event\SiteStudioSyncFilesEvent;
1111
use Drupal\cohesion_sync\EventSubscriber\Import\SiteStudioSyncFilesSubscriber;
@@ -129,14 +129,18 @@ function acquia_cms_site_studio_install($is_syncing) {
129129
'sitestudio_config_management',
130130
];
131131
$module_installer->install($modules_to_install);
132-
}
133-
}
134132

135-
/**
136-
* Implements hook_module_preinstall().
137-
*/
138-
function acquia_cms_site_studio_module_preinstall($module) {
139-
\Drupal::service('acquia_cms_common.utility')->setModulePreinstallTriggered($module);
133+
// Add text format permission to a developer role.
134+
$role = $entity_type_manager->getStorage('user_role')->load('developer');
135+
$editors = $entity_type_manager->getStorage('editor')->loadMultiple([
136+
'cohesion',
137+
'filtered_html',
138+
'full_html',
139+
]);
140+
foreach($editors as $editor) {
141+
$role->grantPermission('use text format ' . $editor->id())->save(TRUE);
142+
}
143+
}
140144
}
141145

142146
/**

modules/acquia_cms_site_studio/acquia_cms_site_studio.module

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
* File for the Site Studio Installation Code.
66
*/
77

8-
use Drupal\acquia_cms_common\Facade\ConfigHandlerFacade;
98
use Drupal\acquia_cms_site_studio\Facade\CohesionFacade;
9+
use Drupal\acquia_cms_site_studio\Facade\ConfigHandlerFacade;
1010
use Drupal\acquia_cms_site_studio\Form\AcquiaCmsSiteStudioSiteConfigureForm;
1111
use Drupal\acquia_cms_site_studio\Helper\SiteStudioPermissionHelper;
1212
use Drupal\cohesion\Controller\AdministrationController;
1313
use Drupal\Core\Entity\EntityInterface;
1414
use Drupal\Core\Form\FormStateInterface;
15+
use Drupal\editor\EditorInterface;
1516
use Drupal\user\Entity\Role;
1617
use Drupal\user\RoleInterface;
1718

@@ -279,9 +280,27 @@ function acquia_cms_site_studio_modules_installed($modules, $is_syncing) {
279280
* Implements hook_library_info_alter().
280281
*/
281282
function acquia_cms_site_studio_library_info_alter(array &$libraries, string $module): void {
282-
// Remove the default css provided by module: `collapsiblock` module.
283+
// Remove the default CSS provided by module: `collapsiblock` module.
283284
// It causes issue with site studio template.
284285
if ($module == "collapsiblock" && isset($libraries['core']['css'])) {
285286
unset($libraries['core']['css']);
286287
}
287288
}
289+
290+
/**
291+
* Implements hook_ENTITY_TYPE_insert().
292+
*
293+
* The permission to developer role to use a newly added text format.
294+
*
295+
* @param \Drupal\editor\EditorInterface $editor
296+
* The filter format entity.
297+
*/
298+
function acquia_cms_site_studio_editor_insert(EditorInterface $editor) {
299+
// If the filter format entity isn't syncing, then update it.
300+
// Otherwise, no action is needed.
301+
if (!$editor->isSyncing()) {
302+
// Add text format permission to a developer role.
303+
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load('developer');
304+
$role->grantPermission('use text format ' . $editor->id())->save(TRUE);
305+
}
306+
}

modules/acquia_cms_site_studio/config/install/user.role.developer.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ dependencies: { }
44
id: developer
55
label: 'Low Code Site Builder'
66
weight: -9
7-
is_admin: null
7+
is_admin: false
88
permissions:
99
# The above comment is only applicable till here.
10-
- 'use text format filtered_html'
11-
- 'use text format full_html'
12-
- 'view the administration theme'
1310
- 'access animate on view'
1411
- 'access component builder elements group'
1512
- 'access component content'
@@ -28,7 +25,6 @@ permissions:
2825
- 'access media elements group'
2926
- 'access menu elements group'
3027
- 'access view elements group'
31-
- 'use text format cohesion'
3228
- 'access analytics'
3329
- 'access cohesion sync'
3430
- 'access color_picker'
@@ -53,3 +49,4 @@ permissions:
5349
- 'administer style helpers'
5450
- 'administer view templates'
5551
- 'administer website settings'
52+
- 'view the administration theme'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
namespace Drupal\acquia_cms_site_studio\Facade;
4+
5+
use Drupal\Core\Config\ConfigFactoryInterface;
6+
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
7+
use Drupal\Core\Entity\EntityTypeManagerInterface;
8+
use Symfony\Component\DependencyInjection\ContainerInterface;
9+
10+
/**
11+
* Handles the configuration and settings for Acquia Starter Kit Site Studio.
12+
*
13+
* @internal
14+
* This is a totally internal part of Acquia Starter Kits and may be changed
15+
* in any way, or removed outright, at any time without warning. External
16+
* code should not use this class!
17+
*/
18+
final class ConfigHandlerFacade implements ContainerInjectionInterface {
19+
20+
/**
21+
* The config factory.
22+
*
23+
* @var \Drupal\Core\Config\ConfigFactoryInterface
24+
*/
25+
protected $configFactory;
26+
27+
/**
28+
* The EntityTypeManager service.
29+
*
30+
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
31+
*/
32+
protected $entityTypeManager;
33+
34+
/**
35+
* The Module name.
36+
*
37+
* @var string
38+
*/
39+
protected string $moduleName;
40+
41+
/**
42+
* ConfigHandlerFacade constructor.
43+
*
44+
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
45+
* The config factory.
46+
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
47+
* Used to obtain data from various entity types.
48+
*/
49+
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
50+
$this->configFactory = $config_factory;
51+
$this->entityTypeManager = $entity_type_manager;
52+
}
53+
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public static function create(ContainerInterface $container) {
58+
return new static(
59+
$container->get('config.factory'),
60+
$container->get('entity_type.manager')
61+
);
62+
}
63+
64+
/**
65+
* Set module name.
66+
*
67+
* @param string $name
68+
* Module name.
69+
*
70+
* @return void
71+
* Setting the module name.
72+
*/
73+
public function setModuleName(string $name): void {
74+
$this->moduleName = $name;
75+
}
76+
77+
/**
78+
* Function to add default settings of node revision delete.
79+
*
80+
* @param array $settings
81+
* Config settings data.
82+
*
83+
* @return void
84+
* Saving the default settings.
85+
*/
86+
public function processConfigSettings(array $settings): void {
87+
$config = $this->configFactory->getEditable("$this->moduleName.settings");
88+
foreach ($settings as $key => $value) {
89+
$config->set($key, $value);
90+
}
91+
$config->save();
92+
}
93+
94+
/**
95+
* Set third party settings for entity.
96+
*
97+
* @param array $entity
98+
* Entity data.
99+
* @param array $settings
100+
* Third party setting data.
101+
*
102+
* @return void
103+
* Saving the third party settings.
104+
*/
105+
public function processThirdPartySettings(array $entity, array $settings): void {
106+
if ($entity) {
107+
// Get the entity storage with respective entity_type.
108+
$type = $this->entityTypeManager->getStorage($entity['entity_type']);
109+
$entityLoad = $type->load($entity['bundle']);
110+
// @phpstan-ignore-next-line
111+
$getThirdPartySettings = $entityLoad ? $entityLoad->get('third_party_settings') : NULL;
112+
// Set the third party settings.
113+
if (!empty($entityLoad) && !isset($getThirdPartySettings[$this->moduleName])) {
114+
foreach ($settings as $key => $value) {
115+
// @phpstan-ignore-next-line
116+
$entityLoad->setThirdPartySetting($this->moduleName, $key, $value);
117+
}
118+
$entityLoad->save();
119+
}
120+
}
121+
}
122+
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: "Acquia CMS Site Studio Testing"
2+
type: module
3+
package: Testing
4+
description: "Testing for Media: Acquia CMS Site Studio module."
5+
hidden: true
6+
dependencies:
7+
- acquia_cms_site_studio:acquia_cms_site_studio
8+
- drupal:editor
9+
- drupal:filter
10+
- drupal:media_library
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
langcode: en
2+
status: true
3+
dependencies:
4+
module:
5+
- media
6+
id: media.embedded
7+
label: Embedded
8+
targetEntityType: media
9+
cache: true

0 commit comments

Comments
 (0)