From 72b680f59373bfe6fadb8bd775ed078588fd5ad1 Mon Sep 17 00:00:00 2001 From: Michael Lee <lee.5151@osu.edu> Date: Mon, 23 May 2022 14:01:19 -0400 Subject: [PATCH] Upgrading drupal/allowed_formats (1.3.0 => 1.5.0) --- composer.json | 2 +- composer.lock | 41 +++++++++----- vendor/composer/installed.json | 41 ++++++++++---- vendor/composer/installed.php | 10 ++-- .../allowed_formats/allowed_formats.info.yml | 8 +-- .../allowed_formats/allowed_formats.module | 30 +++++++--- .../allowed_formats.post_update.php | 34 +++++++++++ web/modules/allowed_formats/composer.json | 37 ++++++++++++ .../config/schema/allowed_formats.schema.yml | 14 +++-- .../allowed_formats_base_fields_test.info.yml | 6 +- .../src/Functional/AllowedFormatsTest.php | 56 +++++++++++-------- 11 files changed, 204 insertions(+), 75 deletions(-) create mode 100644 web/modules/allowed_formats/allowed_formats.post_update.php create mode 100644 web/modules/allowed_formats/composer.json diff --git a/composer.json b/composer.json index 7b9f890c76..983ddd5bf2 100644 --- a/composer.json +++ b/composer.json @@ -90,7 +90,7 @@ "drupal/addtocalendar": "3.2", "drupal/admin_toolbar": "3.1.0", "drupal/administerusersbyrole": "3.0", - "drupal/allowed_formats": "1.3", + "drupal/allowed_formats": "1.5", "drupal/anchor_link": "1.9", "drupal/better_exposed_filters": "5.0", "drupal/block_field": "1.0.0-rc2", diff --git a/composer.lock b/composer.lock index de80c3e923..eb2a91fc64 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ddbb6bfcc5492e80908375b84ecb45bb", + "content-hash": "26c2b8b285d17e928ff630e8f4787e0d", "packages": [ { "name": "alchemy/zippy", @@ -1843,26 +1843,26 @@ }, { "name": "drupal/allowed_formats", - "version": "1.3.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/allowed_formats.git", - "reference": "8.x-1.3" + "reference": "8.x-1.5" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/allowed_formats-8.x-1.3.zip", - "reference": "8.x-1.3", - "shasum": "4c3c036d7b41428d6e22b61f1219de0ab012feec" + "url": "https://ftp.drupal.org/files/projects/allowed_formats-8.x-1.5.zip", + "reference": "8.x-1.5", + "shasum": "dbf61bee7aec87beaa2cf307c1d0d9d5b896328c" }, "require": { - "drupal/core": "^8.7.7 || ^9" + "drupal/core": "^8.8 || ^9" }, "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.3", - "datestamp": "1592909219", + "version": "8.x-1.5", + "datestamp": "1648060331", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -1875,18 +1875,31 @@ ], "authors": [ { - "name": "floretan", - "homepage": "https://www.drupal.org/user/66163" + "name": "Northern Commerce (formerly Digital Echidna)", + "homepage": "https://www.drupal.org/northern-commerce-formerly-digital-echidna", + "role": "Supporting organization" + }, + { + "name": "Jordan Thompson (nord102)", + "homepage": "https://www.drupal.org/u/nord102", + "role": "Maintainer" + }, + { + "name": "Wunder", + "homepage": "https://www.drupal.org/wunder", + "role": "Supporting organization" }, { - "name": "nord102", - "homepage": "https://www.drupal.org/user/3471419" + "name": "Florian Loretan (floretan)", + "homepage": "https://www.drupal.org/u/floretan", + "role": "Maintainer" } ], "description": "Limit which text formats are available for each field instance.", "homepage": "https://www.drupal.org/project/allowed_formats", "support": { - "source": "https://git.drupalcode.org/project/allowed_formats" + "source": "http://cgit.drupalcode.org/allowed_formats", + "issues": "https://www.drupal.org/project/issues/allowed_formats" } }, { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 86c3899c9d..9b86767a2d 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -1890,27 +1890,27 @@ }, { "name": "drupal/allowed_formats", - "version": "1.3.0", - "version_normalized": "1.3.0.0", + "version": "1.5.0", + "version_normalized": "1.5.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/allowed_formats.git", - "reference": "8.x-1.3" + "reference": "8.x-1.5" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/allowed_formats-8.x-1.3.zip", - "reference": "8.x-1.3", - "shasum": "4c3c036d7b41428d6e22b61f1219de0ab012feec" + "url": "https://ftp.drupal.org/files/projects/allowed_formats-8.x-1.5.zip", + "reference": "8.x-1.5", + "shasum": "dbf61bee7aec87beaa2cf307c1d0d9d5b896328c" }, "require": { - "drupal/core": "^8.7.7 || ^9" + "drupal/core": "^8.8 || ^9" }, "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-1.3", - "datestamp": "1592909219", + "version": "8.x-1.5", + "datestamp": "1648060331", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -1924,14 +1924,31 @@ ], "authors": [ { - "name": "floretan", - "homepage": "https://www.drupal.org/user/66163" + "name": "Northern Commerce (formerly Digital Echidna)", + "homepage": "https://www.drupal.org/northern-commerce-formerly-digital-echidna", + "role": "Supporting organization" + }, + { + "name": "Jordan Thompson (nord102)", + "homepage": "https://www.drupal.org/u/nord102", + "role": "Maintainer" + }, + { + "name": "Wunder", + "homepage": "https://www.drupal.org/wunder", + "role": "Supporting organization" + }, + { + "name": "Florian Loretan (floretan)", + "homepage": "https://www.drupal.org/u/floretan", + "role": "Maintainer" } ], "description": "Limit which text formats are available for each field instance.", "homepage": "https://www.drupal.org/project/allowed_formats", "support": { - "source": "https://git.drupalcode.org/project/allowed_formats" + "source": "http://cgit.drupalcode.org/allowed_formats", + "issues": "https://www.drupal.org/project/issues/allowed_formats" }, "install-path": "../../web/modules/allowed_formats" }, diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 39a00312f7..f2d9fab622 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -5,7 +5,7 @@ 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => 'e84dd64613669ee59f663ea0db62b53e321ee2c8', + 'reference' => 'bc02f6fd4109ae90aaed2f0870deb0779978d71c', 'name' => 'osu-asc-webservices/d8-upstream', 'dev' => true, ), @@ -308,12 +308,12 @@ ), ), 'drupal/allowed_formats' => array( - 'pretty_version' => '1.3.0', - 'version' => '1.3.0.0', + 'pretty_version' => '1.5.0', + 'version' => '1.5.0.0', 'type' => 'drupal-module', 'install_path' => __DIR__ . '/../../web/modules/allowed_formats', 'aliases' => array(), - 'reference' => '8.x-1.3', + 'reference' => '8.x-1.5', 'dev_requirement' => false, ), 'drupal/anchor_link' => array( @@ -2101,7 +2101,7 @@ 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), - 'reference' => 'e84dd64613669ee59f663ea0db62b53e321ee2c8', + 'reference' => 'bc02f6fd4109ae90aaed2f0870deb0779978d71c', 'dev_requirement' => false, ), 'pantheon-systems/quicksilver-pushback' => array( diff --git a/web/modules/allowed_formats/allowed_formats.info.yml b/web/modules/allowed_formats/allowed_formats.info.yml index cef7368645..95135c550a 100644 --- a/web/modules/allowed_formats/allowed_formats.info.yml +++ b/web/modules/allowed_formats/allowed_formats.info.yml @@ -1,12 +1,12 @@ name: Allowed Formats description: Limit which text formats are available for each field instance. type: module -core_version_requirement: ^8.7.7 || ^9 +core_version_requirement: ^8.8 || ^9 dependencies: - drupal:field - drupal:filter -# Information added by Drupal.org packaging script on 2020-06-23 -version: '8.x-1.3' +# Information added by Drupal.org packaging script on 2022-03-23 +version: '8.x-1.5' project: 'allowed_formats' -datestamp: 1592909221 +datestamp: 1648060332 diff --git a/web/modules/allowed_formats/allowed_formats.module b/web/modules/allowed_formats/allowed_formats.module index bc2a3a42f8..dbab0cab12 100644 --- a/web/modules/allowed_formats/allowed_formats.module +++ b/web/modules/allowed_formats/allowed_formats.module @@ -26,16 +26,33 @@ function allowed_formats_form_field_config_edit_form_alter(array &$form, FormSta $options[$format->id()] = $format->label(); } - $form['third_party_settings']['allowed_formats'] = [ + $settings = $field->getThirdPartySettings('allowed_formats'); + $form['third_party_settings']['allowed_formats']['allowed_formats'] = [ '#type' => 'checkboxes', '#title' => t('Allowed formats'), '#options' => $options, - '#default_value' => $field->getThirdPartySettings('allowed_formats'), + '#default_value' => !empty($settings['allowed_formats']) ? $settings['allowed_formats'] : [], '#description' => t('Restrict which text formats are allowed, given the user has the required permissions. If no text formats are selected, then all the ones the user has access to will be available.'), ]; + + $form['#validate'][] = 'allowed_formats_form_field_config_edit_form_validate'; } } +/** + * Validation handler for field_config_edit_form. + */ +function allowed_formats_form_field_config_edit_form_validate(array &$form, FormStateInterface $form_state) { + // Restructure options to store the value as a sequence. + $form_parents = [ + 'third_party_settings', + 'allowed_formats', + 'allowed_formats', + ]; + $value = $form_state->getValue($form_parents); + $form_state->setValue($form_parents, array_keys(array_filter($value))); +} + /** * Implements hook_field_widget_third_party_settings_form(). */ @@ -72,7 +89,7 @@ function allowed_formats_field_widget_form_alter(&$element, FormStateInterface $ // Read configuration if available. This is possible for bundle fields or // base fields overridden using a BaseFieldOverride. $field_configuration = $field_definition->getConfig($field_definition->getTargetBundle()); - $allowed_formats_setting = $field_configuration->getThirdPartySettings('allowed_formats'); + $allowed_formats_setting = $field_configuration->getThirdPartySetting('allowed_formats', 'allowed_formats'); } else { // Base fields don't support third party settings so use an ordinary @@ -81,11 +98,8 @@ function allowed_formats_field_widget_form_alter(&$element, FormStateInterface $ $allowed_formats_setting = $field_definition->getSetting('allowed_formats'); } - if (isset($allowed_formats_setting) && is_array($allowed_formats_setting)) { - $allowed_formats = array_filter($allowed_formats_setting); - if (!empty($allowed_formats)) { - $element['#allowed_formats'] = $allowed_formats; - } + if (!empty($allowed_formats_setting) && is_array($allowed_formats_setting)) { + $element['#allowed_formats'] = $allowed_formats_setting; } /** @var \Drupal\Core\Field\WidgetInterface $widget */ diff --git a/web/modules/allowed_formats/allowed_formats.post_update.php b/web/modules/allowed_formats/allowed_formats.post_update.php new file mode 100644 index 0000000000..6a7a5c10b0 --- /dev/null +++ b/web/modules/allowed_formats/allowed_formats.post_update.php @@ -0,0 +1,34 @@ +<?php + +/** + * @file + * Post update functions for Allowed Formats module. + */ + +use Drupal\field\Entity\FieldConfig; + +/** + * Updates existing configuration to store allowed_formats as sequence. + */ +function allowed_formats_post_update_store_allowed_formats_as_sequence() { + foreach (FieldConfig::loadMultiple() as $field_config) { + /** @var \Drupal\field\Entity\FieldConfig $field_config */ + if (in_array($field_config->getType(), _allowed_formats_field_types(), TRUE)) { + $allowed_formats = $field_config->getThirdPartySettings('allowed_formats'); + if (!empty($allowed_formats)) { + // Don't do anything if the configuration is already a sequence. + if (isset($allowed_formats['allowed_formats']) && is_array($allowed_formats['allowed_formats'])) { + continue; + } + // Unset existing configuration. + foreach ($allowed_formats as $key => $value) { + $field_config->unsetThirdPartySetting('allowed_formats', $key); + } + $field_config->setThirdPartySetting('allowed_formats', 'allowed_formats', array_values(array_filter($allowed_formats))); + $field_config->save(); + } + } + } + + return t('Allowed formats in field configuration has been updated.'); +} diff --git a/web/modules/allowed_formats/composer.json b/web/modules/allowed_formats/composer.json new file mode 100644 index 0000000000..42b0ecaaee --- /dev/null +++ b/web/modules/allowed_formats/composer.json @@ -0,0 +1,37 @@ +{ + "name": "drupal/allowed_formats", + "description": "Limit which text formats are available for each field instance.", + "type": "drupal-module", + "homepage": "https://www.drupal.org/project/allowed_formats", + "license": "GPL-2.0-or-later", + "minimum-stability": "dev", + "authors": [ + { + "name": "Northern Commerce (formerly Digital Echidna)", + "homepage": "https://www.drupal.org/northern-commerce-formerly-digital-echidna", + "role": "Supporting organization" + }, + { + "name": "Jordan Thompson (nord102)", + "homepage": "https://www.drupal.org/u/nord102", + "role": "Maintainer" + }, + { + "name": "Wunder", + "homepage": "https://www.drupal.org/wunder", + "role": "Supporting organization" + }, + { + "name": "Florian Loretan (floretan)", + "homepage": "https://www.drupal.org/u/floretan", + "role": "Maintainer" + } + ], + "support": { + "issues": "https://www.drupal.org/project/issues/allowed_formats", + "source": "http://cgit.drupalcode.org/allowed_formats" + }, + "require": { + "drupal/core": "^8.8 || ^9" + } +} diff --git a/web/modules/allowed_formats/config/schema/allowed_formats.schema.yml b/web/modules/allowed_formats/config/schema/allowed_formats.schema.yml index 56a61824ab..f1e96a7bd4 100644 --- a/web/modules/allowed_formats/config/schema/allowed_formats.schema.yml +++ b/web/modules/allowed_formats/config/schema/allowed_formats.schema.yml @@ -1,9 +1,13 @@ field.field.*.*.*.third_party.allowed_formats: - type: sequence - label: Allowed formats - sequence: - type: string - label: Allowed format + type: mapping + label: 'Allowed formats configuration' + mapping: + allowed_formats: + type: sequence + label: Allowed formats + sequence: + type: string + label: Allowed format field.widget.third_party.allowed_formats: type: mapping diff --git a/web/modules/allowed_formats/tests/modules/allowed_formats_base_fields_test/allowed_formats_base_fields_test.info.yml b/web/modules/allowed_formats/tests/modules/allowed_formats_base_fields_test/allowed_formats_base_fields_test.info.yml index 6fba0b8350..366d4379b4 100644 --- a/web/modules/allowed_formats/tests/modules/allowed_formats_base_fields_test/allowed_formats_base_fields_test.info.yml +++ b/web/modules/allowed_formats/tests/modules/allowed_formats_base_fields_test/allowed_formats_base_fields_test.info.yml @@ -7,7 +7,7 @@ dependencies: drupal:taxonomy drupal:allowed_formats -# Information added by Drupal.org packaging script on 2020-06-23 -version: '8.x-1.3' +# Information added by Drupal.org packaging script on 2022-03-23 +version: '8.x-1.5' project: 'allowed_formats' -datestamp: 1592909221 +datestamp: 1648060332 diff --git a/web/modules/allowed_formats/tests/src/Functional/AllowedFormatsTest.php b/web/modules/allowed_formats/tests/src/Functional/AllowedFormatsTest.php index ea2109be72..ce22e98dfe 100644 --- a/web/modules/allowed_formats/tests/src/Functional/AllowedFormatsTest.php +++ b/web/modules/allowed_formats/tests/src/Functional/AllowedFormatsTest.php @@ -5,6 +5,7 @@ use Drupal\filter\Entity\FilterFormat; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Tests the basic functionality of Allowed Formats. @@ -15,6 +16,7 @@ class AllowedFormatsTest extends BrowserTestBase { // Provides shortcut method createVocabulary(). use TaxonomyTestTrait; + use StringTranslationTrait; /** * {@inheritdoc} @@ -53,8 +55,14 @@ class AllowedFormatsTest extends BrowserTestBase { protected function setUp() { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(['administer filters', 'administer entity_test fields']); - $this->webUser = $this->drupalCreateUser(['administer entity_test content', 'administer taxonomy']); + $this->adminUser = $this->drupalCreateUser([ + 'administer filters', + 'administer entity_test fields', + ]); + $this->webUser = $this->drupalCreateUser([ + 'administer entity_test content', + 'administer taxonomy', + ]); } /** @@ -81,28 +89,30 @@ public function testAllowedFormats() { // Change the Allowed Formats settings of the test field created by // entity_test_install(). $this->drupalLogin($this->adminUser); - $this->drupalPostForm('entity_test/structure/entity_test/fields/entity_test.entity_test.field_test_text', [ - 'third_party_settings[allowed_formats][' . $format1->id() . ']' => TRUE, - 'third_party_settings[allowed_formats][' . $format2->id() . ']' => TRUE, - ], t('Save settings')); + $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.field_test_text'); + $this->submitForm([ + 'third_party_settings[allowed_formats][allowed_formats][' . $format1->id() . ']' => TRUE, + 'third_party_settings[allowed_formats][allowed_formats][' . $format2->id() . ']' => TRUE, + ], $this->t('Save settings')); // Display the creation form. $this->drupalLogin($this->webUser); $this->drupalGet('entity_test/add'); - $this->assertFieldByName("field_test_text[0][value]", NULL, 'Widget is displayed'); - $this->assertFieldByName("field_test_text[0][format]", NULL, 'Format selector is displayed'); + $this->assertSession()->fieldExists("field_test_text[0][value]"); + $this->assertSession()->fieldExists("field_test_text[0][format]"); // Change field to allow only one format. $this->drupalLogin($this->adminUser); - $this->drupalPostForm('entity_test/structure/entity_test/fields/entity_test.entity_test.field_test_text', [ - 'third_party_settings[allowed_formats][' . $format2->id() . ']' => FALSE, - ], t('Save settings')); + $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.field_test_text'); + $this->submitForm([ + 'third_party_settings[allowed_formats][allowed_formats][' . $format2->id() . ']' => FALSE, + ], $this->t('Save settings')); // We shouldn't have the 'format' selector since only one format is allowed. $this->drupalLogin($this->webUser); $this->drupalGet('entity_test/add'); - $this->assertFieldByName("field_test_text[0][value]", NULL, 'Widget is displayed'); - $this->assertNoFieldByName("field_test_text[0][format]", NULL, 'Format selector is not displayed'); + $this->assertSession()->fieldExists("field_test_text[0][value]"); + $this->assertSession()->fieldNotExists("field_test_text[0][format]"); } /** @@ -139,11 +149,11 @@ public function testBaseFields() { // available. $this->drupalLogin($this->webUser); $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add'); - $this->assertFieldByName("description[0][value]", NULL, 'Widget is displayed'); - $this->assertFieldByName("description[0][format]", NULL, 'Format selector is displayed'); - $this->assertOption('edit-description-0-format--2', 'basic_html'); - $this->assertOption('edit-description-0-format--2', 'restricted_html'); - $this->assertOption('edit-description-0-format--2', 'full_html'); + $this->assertSession()->fieldExists("description[0][value]"); + $this->assertSession()->fieldExists("description[0][format]"); + $this->assertSession()->optionExists('edit-description-0-format--2', 'basic_html'); + $this->assertSession()->optionExists('edit-description-0-format--2', 'restricted_html'); + $this->assertSession()->optionExists('edit-description-0-format--2', 'full_html'); // Enable our test module, which disallows using the 'full_html' format // using the allowed_formats functionality. @@ -152,11 +162,11 @@ public function testBaseFields() { // Display the term creation form again and check that 'full_html' is // not available as expected. $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add'); - $this->assertFieldByName("description[0][value]", NULL, 'Widget is displayed'); - $this->assertFieldByName("description[0][format]", NULL, 'Format selector is displayed'); - $this->assertOption('edit-description-0-format--2', 'basic_html'); - $this->assertOption('edit-description-0-format--2', 'restricted_html'); - $this->assertNoOption('edit-description-0-format--2', 'full_html'); + $this->assertSession()->fieldExists("description[0][value]"); + $this->assertSession()->fieldExists("description[0][format]"); + $this->assertSession()->optionExists('edit-description-0-format--2', 'basic_html'); + $this->assertSession()->optionExists('edit-description-0-format--2', 'restricted_html'); + $this->assertSession()->optionNotExists('edit-description-0-format--2', 'full_html'); } } -- GitLab