Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACMS-4237: Remove Dependency of acquia_cms_common from Site Studio. #1917

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@
"drupal/core": "-p2"
},
"patches": {
"acquia/cohesion": {
"3340269 - Site Studio Drupal 11.1 compatibility": "https://www.drupal.org/files/issues/2025-01-09/3340269-site-studio-drupal-11-1-compatibility.patch"
},
"drupal/core": {
"3328187 - PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in docroot/core/lib/Drupal/Core/Mail/Plugin/Mail/PhpMail.php on line 112": "https://git.drupalcode.org/project/drupal/-/merge_requests/3142.patch",
"Fix failing test for site studio due to missing file": "https://gist.githubusercontent.com/chandan-singh7929/978c8c3c8b6f1e2de23492e7e562c0c3/raw/f0e7770d94be862e5495ca25662a0a0d5672b785/bypass-library-version-core.patch"
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Drupal\Tests\acquia_cms_common\Functional;

use Drupal\Tests\BrowserTestBase;

/**
* Tests the filter filter_html.
*
* @group acquia_cms
* @group acquia_cms_common
*/
class FilterFormatTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
protected static $modules = [
'acquia_cms_common',
];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$account = $this->drupalCreateUser(['administer filters']);
$this->drupalLogin($account);
}

/**
* Tests the filter filter_html.
*
* @param string $filter_format
* The filter format name.
* @param bool $status
* Status of the field.
*
* @dataProvider providerFilterFormat
*/
public function testFilterBlackListHtmlTags(string $filter_format, bool $status) {
$assert_session = $this->assertSession();

// Visit the filter page.
$this->drupalGet('/admin/config/content/formats/manage/' . $filter_format);
$assert_session->statusCodeEquals(200);
$filter_element = $assert_session->elementExists('css', '#edit-filters-filter-html-status');
$this->assertSame($status, $filter_element->isChecked(), 'Expect checked, but found uncheck.');

}

/**
* Defines an array of modules & permissions to roles.
*/
public static function providerFilterFormat(): array {
return [
[
'full_html',
TRUE,
],
[
'filtered_html',
TRUE,
],
];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: 'Module for Site Studio Installation Code.'
core_version_requirement: ^9.5 || ^10 || ^11
type: module
dependencies:
- acquia_cms_common:acquia_cms_common
- drupal:media
- cohesion_base_styles # phpcs:ignore
- cohesion_custom_styles # phpcs:ignore
- cohesion_elements # phpcs:ignore
Expand Down
20 changes: 12 additions & 8 deletions modules/acquia_cms_site_studio/acquia_cms_site_studio.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Contains install-time code for the Acquia CMS profile.
*/

use Drupal\acquia_cms_common\Facade\ConfigHandlerFacade;
use Drupal\acquia_cms_site_studio\Facade\ConfigHandlerFacade;
use Drupal\cohesion\Controller\AdministrationController;
use Drupal\cohesion_sync\Event\SiteStudioSyncFilesEvent;
use Drupal\cohesion_sync\EventSubscriber\Import\SiteStudioSyncFilesSubscriber;
Expand Down Expand Up @@ -129,14 +129,18 @@ function acquia_cms_site_studio_install($is_syncing) {
'sitestudio_config_management',
];
$module_installer->install($modules_to_install);
}
}

/**
* Implements hook_module_preinstall().
*/
function acquia_cms_site_studio_module_preinstall($module) {
\Drupal::service('acquia_cms_common.utility')->setModulePreinstallTriggered($module);
// Add text format permission to developer role.
$role = $entity_type_manager->getStorage('user_role')->load('developer');
$editors = $entity_type_manager->getStorage('editor')->loadMultiple([
'cohesion',
'filtered_html',
'full_html',
]);
foreach($editors as $editor) {
$role->grantPermission('use text format ' . $editor->id())->save(TRUE);
}
}
}

/**
Expand Down
21 changes: 20 additions & 1 deletion modules/acquia_cms_site_studio/acquia_cms_site_studio.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
* File for the Site Studio Installation Code.
*/

use Drupal\acquia_cms_common\Facade\ConfigHandlerFacade;
use Drupal\acquia_cms_site_studio\Facade\CohesionFacade;
use Drupal\acquia_cms_site_studio\Facade\ConfigHandlerFacade;
use Drupal\acquia_cms_site_studio\Form\AcquiaCmsSiteStudioSiteConfigureForm;
use Drupal\acquia_cms_site_studio\Helper\SiteStudioPermissionHelper;
use Drupal\cohesion\Controller\AdministrationController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\filter\FilterFormatInterface;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;

Expand Down Expand Up @@ -285,3 +286,21 @@ function acquia_cms_site_studio_library_info_alter(array &$libraries, string $mo
unset($libraries['core']['css']);
}
}

/**
* Implements hook_ENTITY_TYPE_insert().
*
* The permission to developer role to use newly added text format.
*
* @param \Drupal\filter\FilterFormatInterface $filter_format
* The filter format entity.
*/
function acquia_cms_site_studio_filter_format_insert(FilterFormatInterface $filter_format) {
// If the filter format entity isn't syncing, then update it.
// Otherwise, no action is needed.
if (!$filter_format->isSyncing()) {
// Add text format permission to developer role.
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load('developer');
$role->grantPermission('use text format ' . $filter_format->id())->save(TRUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ dependencies: { }
id: developer
label: 'Low Code Site Builder'
weight: -9
is_admin: null
is_admin: false
permissions:
# The above comment is only applicable till here.
- 'use text format filtered_html'
- 'use text format full_html'
- 'view the administration theme'
- 'access animate on view'
- 'access component builder elements group'
- 'access component content'
Expand All @@ -28,7 +25,6 @@ permissions:
- 'access media elements group'
- 'access menu elements group'
- 'access view elements group'
- 'use text format cohesion'
- 'access analytics'
- 'access cohesion sync'
- 'access color_picker'
Expand All @@ -53,3 +49,4 @@ permissions:
- 'administer style helpers'
- 'administer view templates'
- 'administer website settings'
- 'view the administration theme'
123 changes: 123 additions & 0 deletions modules/acquia_cms_site_studio/src/Facade/ConfigHandlerFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

namespace Drupal\acquia_cms_site_studio\Facade;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Handles the configuration and settings for Acquia Starter Kit Site Studio.
*
* @internal
* This is a totally internal part of Acquia Starter Kits and may be changed
* in any way, or removed outright, at any time without warning. External
* code should not use this class!
*/
final class ConfigHandlerFacade implements ContainerInjectionInterface {

/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;

/**
* The EntityTypeManager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;

/**
* The Module name.
*
* @var string
*/
protected string $moduleName;

/**
* ConfigHandlerFacade constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Used to obtain data from various entity types.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->configFactory = $config_factory;
$this->entityTypeManager = $entity_type_manager;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity_type.manager')
);
}

/**
* Set module name.
*
* @param string $name
* Module name.
*
* @return void
* Setting the module name.
*/
public function setModuleName(string $name): void {
$this->moduleName = $name;
}

/**
* Function to add default settings of node revision delete.
*
* @param array $settings
* Config settings data.
*
* @return void
* Saving the default settings.
*/
public function processConfigSettings(array $settings): void {
$config = $this->configFactory->getEditable("$this->moduleName.settings");
foreach ($settings as $key => $value) {
$config->set($key, $value);
}
$config->save();
}

/**
* Set third party settings for entity.
*
* @param array $entity
* Entity data.
* @param array $settings
* Third party setting data.
*
* @return void
* Saving the third party settings.
*/
public function processThirdPartySettings(array $entity, array $settings): void {
if ($entity) {
// Get the entity storage with respective entity_type.
$type = $this->entityTypeManager->getStorage($entity['entity_type']);
$entityLoad = $type->load($entity['bundle']);
// @phpstan-ignore-next-line
$getThirdPartySettings = $entityLoad ? $entityLoad->get('third_party_settings') : NULL;
// Set the third party settings.
if (!empty($entityLoad) && !isset($getThirdPartySettings[$this->moduleName])) {
foreach ($settings as $key => $value) {
// @phpstan-ignore-next-line
$entityLoad->setThirdPartySetting($this->moduleName, $key, $value);
}
$entityLoad->save();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @group acquia_cms
* @group acquia_cms_site_studio
*/
class FilterFormatFilteredHtmlTest extends BrowserTestBase {
class FilterFormatCohesionTest extends BrowserTestBase {

/**
* {@inheritdoc}
Expand Down Expand Up @@ -44,13 +44,11 @@ class FilterFormatFilteredHtmlTest extends BrowserTestBase {
*/
public function testFilterBlackListHtmlTags() {
$assert_session = $this->assertSession();
$account = $this->drupalCreateUser();
$account->addRole('administrator');
$account->save();
$account = $this->drupalCreateUser(['administer filters']);
$this->drupalLogin($account);

// Visit the filter page.
$this->drupalGet('/admin/config/content/formats/manage/filtered_html');
$this->drupalGet('/admin/config/content/formats/manage/cohesion');
$assert_session->statusCodeEquals(200);
$filter_element = $assert_session->elementExists('css', '#edit-filters-black-list-html-tags-status');
$this->assertFalse($filter_element->isChecked(), 'Expect uncheck, but found checked.');
Expand Down
Loading
Loading