diff --git a/composer.json b/composer.json index fbfca57aef988780743cf4a3f9221f464f3b548c..61c170e8f26667348a29f22b0407b7ba2a72ef27 100644 --- a/composer.json +++ b/composer.json @@ -123,17 +123,9 @@ "drupal/facets": { "https://www.drupal.org/project/facets/issues/3360426": "https://www.drupal.org/files/issues/2023-08-22/3360426-creation-of-dynamic-properties-deprecated.patch", "https://www.drupal.org/project/facets/issues/3379445": "https://www.drupal.org/files/issues/2023-10-02/hotfix-3379445-6.patch" - }, - "drupal/gin": { - "https://www.drupal.org/project/vartheme_claro/issues/3413673": "https://www.drupal.org/files/issues/2024-01-10/gin--2023-12-20--3409899-8--mr-348--68ca5dfc.patch" } } }, - "autoload": { - "classmap": [ - "scripts/composer/ScriptHandler.php" - ] - }, "repositories": [ { "type": "composer", diff --git a/modules/embedded_content/src/Form/EmbeddedContentDialogForm.php b/modules/embedded_content/src/Form/EmbeddedContentDialogForm.php index a14293b51aa8d67f68cdca0c5efd5d1801c6ccc0..cdf57aadc5261c13d34d2ed8ad56fd7eae32d19f 100644 --- a/modules/embedded_content/src/Form/EmbeddedContentDialogForm.php +++ b/modules/embedded_content/src/Form/EmbeddedContentDialogForm.php @@ -117,8 +117,8 @@ class EmbeddedContentDialogForm extends FormBase { ], ]; if ($plugin_id) { - /** @var \Drupal\embedded_content\EmbeddedContentInterface $instance */ try { + /** @var \Drupal\embedded_content\EmbeddedContentInterface $instance */ $instance = $this->embeddedContentPluginManager->createInstance($plugin_id, $config['plugin_config'] ?? []); $subform = $form['config']['plugin_config'] ?? []; $subform_state = SubformState::createForSubform($subform, $form, $form_state); @@ -197,7 +197,7 @@ class EmbeddedContentDialogForm extends FormBase { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { - /** @var \Drupal\embedded_content\EmbeddedContentInterface $instance */ + /** @var \Drupal\embedded_content\EmbeddedContentInterface $plugin_id */ $plugin_id = $form_state->getValue(['config', 'plugin_id']); if ($plugin_id) { try { diff --git a/modules/embedded_content/tests/modules/embedded_content_test/css/test.css b/modules/embedded_content/tests/modules/embedded_content_test/css/test.css deleted file mode 100644 index 42befc7751ac22c14ac67910118747e16f7b0590..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/modules/embedded_content_test/css/test.css +++ /dev/null @@ -1,3 +0,0 @@ -.test-attached-library{ - background:green; -} \ No newline at end of file diff --git a/modules/embedded_content/tests/modules/embedded_content_test/embedded_content_test.info.yml b/modules/embedded_content/tests/modules/embedded_content_test/embedded_content_test.info.yml deleted file mode 100644 index 0f37a5e206fa5f577a412b1990b7397d5faf5c33..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/modules/embedded_content_test/embedded_content_test.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: Embedded Content Test -type: module -description: "Provides testing fixtures" -package: Testing -version: VERSION -dependencies: - - drupal:embedded_content \ No newline at end of file diff --git a/modules/embedded_content/tests/modules/embedded_content_test/embedded_content_test.libraries.yml b/modules/embedded_content/tests/modules/embedded_content_test/embedded_content_test.libraries.yml deleted file mode 100644 index 8372af97bb6fb8afde1856a529cf6875d50ad15f..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/modules/embedded_content_test/embedded_content_test.libraries.yml +++ /dev/null @@ -1,4 +0,0 @@ -test: - css: - theme: - css/test.css: { } \ No newline at end of file diff --git a/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/Color.php b/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/Color.php deleted file mode 100644 index 4099ed6e0f861830967f83eb827e840d910541f3..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/Color.php +++ /dev/null @@ -1,71 +0,0 @@ -<?php - -namespace Drupal\embedded_content_test\Plugin\EmbeddedContent; - -use Drupal\embedded_content\EmbeddedContentInterface; -use Drupal\embedded_content\EmbeddedContentPluginBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; - -/** - * Renders a color sample based on the selected color. - * - * @EmbeddedContent( - * id = "color", - * label = @Translation("Color"), - * ) - */ -class Color extends EmbeddedContentPluginBase implements EmbeddedContentInterface { - - const GREEN = 'green'; - - const RED = 'red'; - - const BLUE = 'blue'; - - use StringTranslationTrait; - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return [ - 'color' => NULL, - ]; - } - - /** - * {@inheritdoc} - */ - public function build(): array { - return [ - 'sample' => [ - '#type' => 'html_tag', - '#tag' => 'div', - '#attributes' => [ - 'style' => 'background:' . $this->configuration['color'] . ';width:20px;height:20px;display:block;border-radius: 10px', - ], - ], - ]; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - - $form['color'] = [ - '#type' => 'select', - '#title' => $this->t('Color'), - '#options' => [ - self::GREEN => $this->t('Green'), - self::RED => $this->t('Red'), - self::BLUE => $this->t('Blue'), - ], - '#default_value' => $this->configuration['color'], - ]; - - return $form; - } - -} diff --git a/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/NoConfig.php b/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/NoConfig.php deleted file mode 100644 index a5391e77c4a15fe94b715b7216dae8f6b738dc0f..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/NoConfig.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -namespace Drupal\embedded_content_test\Plugin\EmbeddedContent; - -use Drupal\embedded_content\EmbeddedContentInterface; -use Drupal\embedded_content\EmbeddedContentPluginBase; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\State\State; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Renders a shape. - * - * @EmbeddedContent( - * id = "no_config", - * label = @Translation("No config"), - * ) - */ -class NoConfig extends EmbeddedContentPluginBase implements EmbeddedContentInterface, ContainerFactoryPluginInterface { - - /** - * State. - * - * @var \Drupal\Core\State\State - */ - protected $state; - - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, State $state) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->state = $state; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('state') - ); - } - - /** - * {@inheritdoc} - */ - public function build(): array { - $state = $this->state->get('embedded_content_state', 1); - $build = [ - 'sample' => [ - '#type' => 'html_tag', - '#tag' => 'div', - '#cache' => [ - 'max-age' => 0, - ], - '#attributes' => [ - 'class' => ['test-attached-library'], - ], - '#attached' => [ - 'library' => [ - 'embedded_content_test/test', - ], - ], - '#value' => $state, - ], - ]; - $state++; - $this->state->set('embedded_content_state', $state); - return $build; - } - -} diff --git a/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/Shape.php b/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/Shape.php deleted file mode 100644 index feb2e9083fb595ee440b48a874d7386439e99acb..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/modules/embedded_content_test/src/Plugin/EmbeddedContent/Shape.php +++ /dev/null @@ -1,84 +0,0 @@ -<?php - -namespace Drupal\embedded_content_test\Plugin\EmbeddedContent; - -use Drupal\embedded_content\EmbeddedContentInterface; -use Drupal\embedded_content\EmbeddedContentPluginBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Render\Markup; -use Drupal\Core\StringTranslation\StringTranslationTrait; - -/** - * Renders a shape. - * - * @EmbeddedContent( - * id = "shape", - * label = @Translation("Shape"), - * ) - */ -class Shape extends EmbeddedContentPluginBase implements EmbeddedContentInterface { - - const RECTANGLE = 'rectangle'; - - const POLYGON = 'polygon'; - - const CIRCLE = 'circle'; - - use StringTranslationTrait; - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return [ - 'shape' => NULL, - ]; - } - - /** - * {@inheritdoc} - */ - public function build(): array { - $markup = ''; - switch ($this->configuration['shape']) { - case static::RECTANGLE; - $markup = '<svg width="400" height="110"><rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)"></rect></svg>'; - break; - - case 'polygon': - $markup = '<svg height="210" width="500"><polygon points="200,10 250,190 160,210" style="fill:lime;stroke:purple;stroke-width:1"></polygon></svg>'; - break; - - case'circle': - $markup = '<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></circle></svg>'; - break; - } - return [ - 'shape' => [ - '#type' => 'html_tag', - '#tag' => 'div', - '#value' => Markup::create($markup), - ], - ]; - } - - /** - * {@inheritdoc} - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - - $form['shape'] = [ - '#type' => 'select', - '#title' => $this->t('Shape'), - '#options' => [ - self::RECTANGLE => $this->t('Rectangle'), - self::POLYGON => $this->t('Polygon'), - self::CIRCLE => $this->t('Circle'), - ], - '#default_value' => $this->configuration['shape'], - ]; - - return $form; - } - -} diff --git a/modules/embedded_content/tests/src/FunctionalJavascript/EmbeddedContentTest.php b/modules/embedded_content/tests/src/FunctionalJavascript/EmbeddedContentTest.php deleted file mode 100644 index 3282fc772041adef4a67576ab94ae03d265069ef..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/src/FunctionalJavascript/EmbeddedContentTest.php +++ /dev/null @@ -1,154 +0,0 @@ -<?php - -namespace Drupal\Tests\embedded_content\FunctionalJavascript; - -use Drupal\editor\Entity\Editor; -use Drupal\filter\Entity\FilterFormat; -use Drupal\FunctionalJavascriptTests\WebDriverTestBase; -use Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait; -use Drupal\Tests\node\Traits\NodeCreationTrait; -use Drupal\user\RoleInterface; - -/** - * Defines tests for the ckeditor5 button and javascript functionality. - * - * @group embedded_content - */ -class EmbeddedContentTest extends WebDriverTestBase { - - use CKEditor5TestTrait; - - use NodeCreationTrait; - - /** - * {@inheritdoc} - */ - protected static $modules = [ - 'node', - 'ckeditor5', - 'embedded_content', - ]; - - /** - * {@inheritdoc} - */ - protected $defaultTheme = 'stark'; - - /** - * {@inheritdoc} - */ - public function setUp(): void { - parent::setUp(); - $this->drupalCreateContentType(['type' => 'page']); - FilterFormat::create( - [ - 'format' => 'test', - 'name' => 'Ckeditor 5 with embedded content', - 'roles' => [RoleInterface::AUTHENTICATED_ID], - 'filters' => [ - 'embedded_content' => [ - 'id' => 'embedded_content', - 'provider' => 'embedded_content', - 'status' => TRUE, - 'weight' => 1, - ], - 'filter_html' => [ - 'id' => 'filter_html', - 'status' => TRUE, - 'weight' => 2, - 'settings' => [ - 'allowed_html' => '<br> <p> <embedded-content data-plugin-config data-plugin-id>', - 'filter_html_help' => TRUE, - 'filter_html_nofollow' => FALSE, - ], - ], - ], - ] - )->save(); - Editor::create( - [ - 'format' => 'test', - 'editor' => 'ckeditor5', - 'settings' => [ - 'toolbar' => [ - 'items' => ['embeddedContent', 'sourceEditing'], - ], - ], - ] - )->save(); - - $this->drupalLogin( - $this->drupalCreateUser( - [ - 'create page content', - 'edit own page content', - 'access content', - 'use embedded content', - 'use text format test', - ] - ) - ); - - } - - /** - * Tests if CKEditor 5 tooltips can be interacted with in dialogs. - */ - public function testCkeditor5EmbeddedContent() { - - $page = $this->getSession()->getPage(); - $assert_session = $this->assertSession(); - - // Add a node with text rendered via the Plain Text format. - $this->drupalGet('node/add'); - - $this->waitForEditor(); - // Ensure the editor is loaded. - $this->click('.ck-content'); - - $this->assertEditorButtonEnabled('Embedded content'); - $this->click('.ck-button'); - $assert_session->waitForText('No embedded content plugins were defined. Enable the examples module to see some examples.'); - $this->container->get('module_installer') - ->install(['embedded_content_test'], TRUE); - - // Add a node with text rendered via the Plain Text format. - $this->drupalGet('node/add'); - - $this->waitForEditor(); - // Ensure the editor is loaded. - $this->click('.ck-content'); - - $this->assertEditorButtonEnabled('Embedded content'); - $this->click('.ck-button'); - $assert_session->waitForElement('css', '.ckeditor5-embedded-content-dialog-form'); - $page->selectFieldOption('config[plugin_id]', 'Shape'); - - $assert_session->waitForElement('css', '[data-drupal-selector="edit-config-plugin-config-shape"]'); - - $page->selectFieldOption('config[plugin_config][shape]', 'polygon'); - - $this->click('.ui-dialog-buttonset button'); - $node = $assert_session->waitForElement('css', '.embedded-content-preview > div'); - $this->assertEquals('<svg height="210" width="500"><polygon points="200,10 250,190 160,210" style="fill:lime;stroke:purple;stroke-width:1"></polygon></svg>', $node->getHtml()); - - // Test if it is possible to edit a selected embedded content. - $this->click('figure.ck-widget'); - - $this->click('.ck-button'); - $element = $assert_session->waitForElement('css', '[data-drupal-selector="edit-config-plugin-config-shape"]'); - - $this->assertEquals('polygon', $element->getValue()); - $page->selectFieldOption('config[plugin_id]', 'Color'); - $assert_session->waitForElement('css', '[data-drupal-selector="edit-config-plugin-config-color"]'); - $page->selectFieldOption('config[plugin_config][color]', 'red'); - $this->click('.ui-dialog-buttonset button'); - $assert_session->waitForElement('css', '.embedded-content-preview [style="background:green;width:20px;height:20px;display:block;border-radius: 10px"]'); - - // Test if it is possible to edit on double click. - $page->find('css', '.embedded-content-preview')->doubleClick(); - $assert_session->waitForElement('css', '[data-drupal-selector="edit-config-plugin-config-color"]'); - - } - -} diff --git a/modules/embedded_content/tests/src/Kernel/EmbeddedContentTest.php b/modules/embedded_content/tests/src/Kernel/EmbeddedContentTest.php deleted file mode 100644 index 4b71670cc30a4ee4e0deb0225017841da16b74c2..0000000000000000000000000000000000000000 --- a/modules/embedded_content/tests/src/Kernel/EmbeddedContentTest.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php - -declare(strict_types=1); - -namespace Drupal\Tests\embedded_content\Kernel; - -use Drupal\Component\Serialization\Json; -use Drupal\Core\Language\Language; -use Drupal\Core\Render\RenderContext; -use Drupal\filter\FilterPluginCollection; -use Drupal\KernelTests\KernelTestBase; -use Symfony\Component\DomCrawler\Crawler; - -/** - * Defines a test for the EmbeddedContent filter. - * - * @covers \Drupal\embedded_content\Plugin\Filter\EmbeddedContent - * @group embedded_content - */ -final class EmbeddedContentTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - protected static $modules = [ - 'filter', - 'embedded_content', - 'embedded_content_test', - ]; - - /** - * The filter to test. - * - * @var \Drupal\filter\Plugin\FilterInterface - */ - protected $filter; - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - parent::setUp(); - $manager = $this->container->get('plugin.manager.filter'); - $bag = new FilterPluginCollection($manager, []); - $this->filter = $bag->get('embedded_content'); - } - - /** - * Get filtered and rendered content. - * - * @param string $content - * The content to render. - * - * @return string - * The filtered and rendered content. - */ - protected function getRenderedContent(string $content): string { - $context = new RenderContext(); - return \Drupal::service('renderer') - ->executeInRenderContext($context, fn() => (string) $this->filter->process($content, Language::LANGCODE_NOT_SPECIFIED)); - } - - /** - * Encodes plugin config. - * - * @param array $config - * Plugin config. - * - * @return string - * Encoded config. - */ - protected function encodePluginConfig(array $config): string { - return htmlspecialchars(Json::encode($config)); - } - - /** - * Tests embed filter. - */ - public function testFilter(): void { - $config = $this->encodePluginConfig( - [ - 'color' => 'green', - ] - ); - $markup = <<<HTML -<embedded-content data-plugin-config="$config" data-plugin-id="color"> </embedded-content> -HTML; - - $context = new RenderContext(); - $content = \Drupal::service('renderer') - ->executeInRenderContext($context, fn() => (string) $this->filter->process($markup, Language::LANGCODE_NOT_SPECIFIED)); - - $crawler = new Crawler($content); - - $this->assertCount(1, $crawler->filter('div[style="background:green;width:20px;height:20px;display:block;border-radius: 10px"]')); - $this->assertCount(0, $crawler->filter('meta')); - - $markup = <<<HTML -<embedded-content data-plugin-config="[]" data-plugin-id="no_config"> </embedded-content> -HTML; - - $result = $this->filter->process($markup, Language::LANGCODE_NOT_SPECIFIED); - - $this->assertEquals(0, $result->getCacheMaxAge()); - $this->assertEquals('embedded_content_test/test', $result->getAttachments()['library'][0]); - } - -} diff --git a/modules/sector_custom_blocks/modules/sector_scroll_top/src/Plugin/Block/ScrollToTop.php b/modules/sector_custom_blocks/modules/sector_scroll_top/src/Plugin/Block/ScrollToTop.php index 6d84533fe325e38521b9ff1033209e24907daa3f..b7620da50ee8d0b10c8a2f96b1590f6b6b340eab 100644 --- a/modules/sector_custom_blocks/modules/sector_scroll_top/src/Plugin/Block/ScrollToTop.php +++ b/modules/sector_custom_blocks/modules/sector_scroll_top/src/Plugin/Block/ScrollToTop.php @@ -30,8 +30,6 @@ class ScrollToTop extends BlockBase implements ContainerFactoryPluginInterface, * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); diff --git a/modules/sector_workflow/sector_workflow.module b/modules/sector_workflow/sector_workflow.module index 69ab3086eda632225f03b5abcaea89a9f93e5a1b..769e93ef13d747252a6a1fa3e95c31df495103fc 100644 --- a/modules/sector_workflow/sector_workflow.module +++ b/modules/sector_workflow/sector_workflow.module @@ -47,7 +47,7 @@ function sector_workflow_menu_local_tasks_alter(&$data, $route_name, RefinableCa } } // Stop the local tasks caching. - $cacheability->setCacheMaxAge(0); + $cacheability->mergeCacheMaxAge(0); } /** @@ -72,15 +72,17 @@ function sector_workflow_form_revision_overview_form_alter(&$form, FormStateInte if (is_numeric($key) && isset($row['select_column_two'])) { $revisionId = $row['select_column_two']['#return_value']; // Get the revision referenced in this particular row. + /** @var \Drupal\node\NodeInterface $revision */ $revision = \Drupal::entityTypeManager() ->getStorage('node') ->loadRevision($revisionId); // Get the current entity. + /** @var \Drupal\node\NodeInterface $node */ $node = \Drupal::routeMatch()->getParameter('node'); - $valid_node_and_revision = (!empty($node) && !empty($revision)); + $valid_node_and_revision = ($node instanceof NodeInterface && $revision instanceof NodeInterface); if ( $valid_node_and_revision && - $node->get('vid')->getValue() == $revision->get('vid')->getValue() && + $node->get('vid')->getValue() == $revision->getRevisionId() && !$node->isPublished() ) { // Add a class for CSS targeting. @@ -91,7 +93,7 @@ function sector_workflow_form_revision_overview_form_alter(&$form, FormStateInte $row['operations']['#prefix'] = $additionalPrefix . $existingPrefix; return; } - if ($valid_node_and_revision && $node->get('vid')->getValue() == $revision->get('vid')->getValue()) { + if ($valid_node_and_revision && $node->get('vid')->getValue() == $revision->getRevisionId()) { $revisionAuthor = $sectorWorkflow->getRevisionAuthor($node); $revisionDate = $sectorWorkflow->getRevisionDate($node); // Add a class for CSS targeting. @@ -104,7 +106,7 @@ function sector_workflow_form_revision_overview_form_alter(&$form, FormStateInte } if ( $valid_node_and_revision && - $node->get('vid')->getValue() !== $revision->get('vid')->getValue() && + $node->get('vid')->getValue() !== $revision->getRevisionId() && $node->hasField('moderation_state') && $revision->isLatestRevision() ) { diff --git a/modules/sector_workflow/src/Plugin/Block/ContentModerationBlock.php b/modules/sector_workflow/src/Plugin/Block/ContentModerationBlock.php index d21f58044f56725c3a35be6536589bbc205e8443..f13b77733bafe2fb609c741df149f7b1da957357 100644 --- a/modules/sector_workflow/src/Plugin/Block/ContentModerationBlock.php +++ b/modules/sector_workflow/src/Plugin/Block/ContentModerationBlock.php @@ -76,15 +76,16 @@ class ContentModerationBlock extends BlockBase implements ContainerFactoryPlugin */ public function build() { $build = []; - /* @var $node \Drupal\node\NodeInterface */ + /** @var \Drupal\node\NodeInterface $node */ $node = $this->routeMatch->getParameter('node'); - if (!empty($node) && $node->hasField('moderation_state') && !$node->get('moderation_state')->isEmpty()) { + if ($node && $node->hasField('moderation_state') && !$node->get('moderation_state')->isEmpty()) { // Further conditions to judge if we should render the form. // This all seems hacky. There must be a better option here than a massive if().. // TODO find out/think about it more. $validFormRender = $node->isLatestRevision() || $node->getRevisionId() == $node->id() || $node->isDefaultRevision(); if ($validFormRender) { // Get the content moderation form render array. + /** @phpstan-ignore-next-line */ $contentModerationForm = $this->formBuilder->getForm(EntityModerationForm::class, $node); if (!empty($contentModerationForm)) { // Render the form into the block. diff --git a/scripts/composer/ScriptHandler.php b/scripts/composer/ScriptHandler.php deleted file mode 100644 index a043c0f38b85603eaa79fc5685af4436002c85c9..0000000000000000000000000000000000000000 --- a/scripts/composer/ScriptHandler.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -/** - * @file - * Contains \Sector\composer\ScriptHandler. - */ - -namespace Sector\composer; - -use Composer\Script\Event; -use Composer\Semver\Comparator; -use Symfony\Component\Filesystem\Filesystem; - -class ScriptHandler { - - protected static function getDrupalRoot($project_root) { - return $project_root . '/web'; - } - - public static function createRequiredFiles(Event $event) { - $fs = new Filesystem(); - $root = static::getDrupalRoot(getcwd()); - - $dirs = [ - 'modules', - 'profiles', - 'themes', - ]; - - // Required for unit testing - foreach ($dirs as $dir) { - if (!$fs->exists($root . '/'. $dir)) { - $fs->mkdir($root . '/'. $dir); - $fs->touch($root . '/'. $dir . '/.gitkeep'); - } - } - - // Prepare the settings file for installation - if (!$fs->exists($root . '/sites/default/settings.php') and $fs->exists($root . '/sites/default/default.settings.php')) { - $fs->copy($root . '/sites/default/default.settings.php', $root . '/sites/default/settings.php'); - $fs->chmod($root . '/sites/default/settings.php', 0666); - $event->getIO()->write("Create a sites/default/settings.php file with chmod 0666"); - } - - // Prepare the services file for installation - if (!$fs->exists($root . '/sites/default/services.yml') and $fs->exists($root . '/sites/default/default.services.yml')) { - $fs->copy($root . '/sites/default/default.services.yml', $root . '/sites/default/services.yml'); - $fs->chmod($root . '/sites/default/services.yml', 0666); - $event->getIO()->write("Create a sites/default/services.yml file with chmod 0666"); - } - - // Create the files directory with chmod 0777 - if (!$fs->exists($root . '/sites/default/files')) { - $oldmask = umask(0); - $fs->mkdir($root . '/sites/default/files', 0777); - umask($oldmask); - $event->getIO()->write("Create a sites/default/files directory with chmod 0777"); - } - } - - /** - * Checks if the installed version of Composer is compatible. - * - * Composer 1.0.0 and higher consider a `composer install` without having a - * lock file present as equal to `composer update`. We do not ship with a lock - * file to avoid merge conflicts downstream, meaning that if a project is - * installed with an older version of Composer the scaffolding of Drupal will - * not be triggered. We check this here instead of in drupal-scaffold to be - * able to give immediate feedback to the end user, rather than failing the - * installation after going through the lengthy process of compiling and - * downloading the Composer dependencies. - * - * @see https://github.com/composer/composer/pull/5035 - */ - public static function checkComposerVersion(Event $event) { - $composer = $event->getComposer(); - $io = $event->getIO(); - - $version = $composer::VERSION; - - // The dev-channel of composer uses the git revision as version number, - // try to the branch alias instead. - if (preg_match('/^[0-9a-f]{40}$/i', $version)) { - $version = $composer::BRANCH_ALIAS_VERSION; - } - - // If Composer is installed through git we have no easy way to determine if - // it is new enough, just display a warning. - if ($version === '@package_version@' || $version === '@package_branch_alias_version@') { - $io->writeError('<warning>You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.</warning>'); - } - elseif (Comparator::lessThan($version, '1.0.0')) { - $io->writeError('<error>Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing</error>.'); - exit(1); - } - } - -}