diff --git a/composer.json b/composer.json index 70b9656143352602852e6e14ceaba2e8b7940290..fad9420edcc610535666895d1f53057f58f3dfa1 100644 --- a/composer.json +++ b/composer.json @@ -119,7 +119,7 @@ "drupal/entity_reference_revisions": "1.9", "drupal/exif_orientation": "^1.1", "drupal/externalauth": "1.4", - "drupal/field_group": "3.2", + "drupal/field_group": "3.3", "drupal/field_permissions": "1.1", "drupal/file_browser": "1.3", "drupal/focal_point": "1.5", diff --git a/composer.lock b/composer.lock index 64eb5186f56a01690f3fcec1c7420b528df6cb68..4914f3295f52b548ffc600a4ca339f0d67624980 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": "a5f0981514b2536f2a1e090ac5f97a48", + "content-hash": "64edb915395ca7970e617e4c3abc9081", "packages": [ { "name": "alchemy/zippy", @@ -4247,17 +4247,17 @@ }, { "name": "drupal/field_group", - "version": "3.2.0", + "version": "3.3.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/field_group.git", - "reference": "8.x-3.2" + "reference": "8.x-3.3" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/field_group-8.x-3.2.zip", - "reference": "8.x-3.2", - "shasum": "2020bbfe40f6ba43bc733ae7c8761632572433a0" + "url": "https://ftp.drupal.org/files/projects/field_group-8.x-3.3.zip", + "reference": "8.x-3.3", + "shasum": "c7a423b1d7643ee40dd1543d72fa04e8ac1756e4" }, "require": { "drupal/core": "^8.8 || ^9" @@ -4268,8 +4268,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-3.2", - "datestamp": "1628513585", + "version": "8.x-3.3", + "datestamp": "1663516404", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 4385f4dc537826a45398459beb1978567d6118c7..3155f55dd8b7b43440b7d6cd98d9b4b099102979 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -4370,18 +4370,18 @@ }, { "name": "drupal/field_group", - "version": "3.2.0", - "version_normalized": "3.2.0.0", + "version": "3.3.0", + "version_normalized": "3.3.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/field_group.git", - "reference": "8.x-3.2" + "reference": "8.x-3.3" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/field_group-8.x-3.2.zip", - "reference": "8.x-3.2", - "shasum": "2020bbfe40f6ba43bc733ae7c8761632572433a0" + "url": "https://ftp.drupal.org/files/projects/field_group-8.x-3.3.zip", + "reference": "8.x-3.3", + "shasum": "c7a423b1d7643ee40dd1543d72fa04e8ac1756e4" }, "require": { "drupal/core": "^8.8 || ^9" @@ -4392,8 +4392,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-3.2", - "datestamp": "1628513585", + "version": "8.x-3.3", + "datestamp": "1663516404", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" @@ -4410,10 +4410,6 @@ "name": "Hydra", "homepage": "https://www.drupal.org/user/647364" }, - { - "name": "Stalski", - "homepage": "https://www.drupal.org/user/322618" - }, { "name": "jyve", "homepage": "https://www.drupal.org/user/591438" @@ -4422,6 +4418,10 @@ "name": "nils.destoop", "homepage": "https://www.drupal.org/user/361625" }, + { + "name": "Stalski", + "homepage": "https://www.drupal.org/user/322618" + }, { "name": "swentel", "homepage": "https://www.drupal.org/user/107403" diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 86538cd69e2ece14afdbb7aa7b2e414b1446db28..aa5631ac92ba39918ada0e4f9d05ca0888e77151 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'osu-asc-webservices/d8-upstream', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '156f3f78d20a1a074c22fd04a7e1276490ea29fd', + 'reference' => '00cdf6fbded26d147a7c7b7180f4866078b0b7e8', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -785,9 +785,9 @@ 'dev_requirement' => false, ), 'drupal/field_group' => array( - 'pretty_version' => '3.2.0', - 'version' => '3.2.0.0', - 'reference' => '8.x-3.2', + 'pretty_version' => '3.3.0', + 'version' => '3.3.0.0', + 'reference' => '8.x-3.3', 'type' => 'drupal-module', 'install_path' => __DIR__ . '/../../web/modules/field_group', 'aliases' => array(), @@ -1585,7 +1585,7 @@ 'osu-asc-webservices/d8-upstream' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => '156f3f78d20a1a074c22fd04a7e1276490ea29fd', + 'reference' => '00cdf6fbded26d147a7c7b7180f4866078b0b7e8', 'type' => 'project', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/web/modules/field_group/CHANGELOG.txt b/web/modules/field_group/CHANGELOG.txt index c73d2a03011d7e5730faaf77537c4d53e8829f30..3fa12be6703a6638e62217f4ec808647333dad88 100644 --- a/web/modules/field_group/CHANGELOG.txt +++ b/web/modules/field_group/CHANGELOG.txt @@ -20,11 +20,13 @@ - Missing hook_help. - Missing UI for description text for field groups. - Field groups default region should never be null. -- Revert "Issue #2991400 by DuaelFr: Field groups default region should never be null". +- Revert "Issue #2991400 by DuaelFr: Field groups default region should never + be null". - Field groups default region should never be null. - How to create horizontal tabs with 8.x-3.x ?. - XSS patch horizontal-tabs.js. -- Allow modules to define form elements beneath field groups before they are created. +- Allow modules to define form elements beneath field groups before they are + created. - Field_group_migrate.info.yml should not contain "version: VERSION". - 2998205: Fix call to member function errors when the plugin was not found. - PHP message: Error: Call to a member function process() on null. @@ -48,7 +50,8 @@ - Add option to set group label classes for HTML element type. - Fix migration tests. - Fix migrate unit test + accordion. -- Getting d6_field_group plugin must define the source_module property Error When Using migrate-upgrade. +- Getting d6_field_group plugin must define the source_module property Error + When Using migrate-upgrade. - Field groups are not compatible with field layout. - Accordion items with children with errors not open. - Accordion doesn't work. @@ -63,12 +66,16 @@ - Branch tests are failing. - . - Creating Duplicate Fieldgroup Name Overwrites Existing Fieldgroup. -- Field groups are not compatible with field layout. Part 1: Make sure regions are changed when changing layout. +- Field groups are not compatible with field layout. Part 1: Make sure regions + are changed when changing layout. - Typo in Field Group Formatter Plugin HtmlElement::prerender. -- Revert "Issue #2846589 by huzooka: Typo in Field Group Formatter Plugin HtmlElement::prerender". +- Revert "Issue #2846589 by huzooka: Typo in Field Group Formatter Plugin + HtmlElement::prerender". - Undefined index: form_display. - Typo in Field Group Formatter Plugin HtmlElement::prerender. - Replace all deprecated uses. -- MessageWarning: Invalid argument supplied for foreach() in field_group_info_groups() (line 663 of modules/contrib/field_group/field_group.module). +- MessageWarning: Invalid argument supplied for foreach() in + field_group_info_groups() + (line 663 of modules/contrib/field_group/field_group.module). - Replace removed formBuilder->setError with formstate->setError. - Undefined index: id in template_preprocess_fieldset() notice. diff --git a/web/modules/field_group/README.txt b/web/modules/field_group/README.txt index 5a2a7ddb58849ca1726773481b81909464dbf5cc..d642551783322513173544d60714482f2e3e965c 100644 --- a/web/modules/field_group/README.txt +++ b/web/modules/field_group/README.txt @@ -67,7 +67,8 @@ view detail page of the entity, while that done in the managed_form_display will be reflected in the add/edit form of the entity. -- Create field groups -- -This section explains how to create groups of fields according to the type chosen. +This section explains how to create groups of fields according to the type +chosen. - Fieldsets : This group of fields makes the internal content in a fieldset. It is possible to add a title and a caption (which appears at the bottom of the fieldset). @@ -76,22 +77,24 @@ This section explains how to create groups of fields according to the type chose - Details Sidebar: Similar to Details. You can configure them to be open (normal fieldset) or collapsed and move them in the sidebar on the node form. - - Html element : This fieldgroup renders the inner content in a HTML element. - You can configure attributes and label element. -The following two groupings works differently because you must associate them with -an other grouping. - - Accordions : This group of fields makes the child groups as a jQuery accordion. - As a first step you must create an Accordions group. You can set a - label and choose an effect. Then you can create an Accordion - Item as a child. This group can contain fields. + - Html element : This fieldgroup renders the inner content in a HTML + element. You can configure attributes and label element. +The following two groupings works differently because you must associate them +with another grouping. + - Accordions : This group of fields makes the child groups as a jQuery + accordion. As a first step you must create an Accordions + group. You can set a label and choose an effect. Then you + can create an Accordion Item as a child. This group can + contain fields. - Tabs : This fieldgroup renders child groups in its own tabs wrapper. As a first step you must create an Tabs group. You can set - choose if you want that your tabs are show horizontally or vertically. - Then, you can create Tab as a child and choose one to be open by default. + choose if you want that your tabs are show horizontally or + vertically. Then, you can create Tab as a child and choose + one to be open by default. This group can contain fields. For all groups, you can add id or classes. -You can also choose if you want to mark a group as required if one of his fields is -require (except for Accordions and Tabs : you must passed by their children). +You can also choose if you want to mark a group as required if one of his fields +is require (except for Accordions and Tabs : you must passed by their children). MAINTAINERS ----------- diff --git a/web/modules/field_group/contrib/field_group_migrate/field_group_migrate.info.yml b/web/modules/field_group/contrib/field_group_migrate/field_group_migrate.info.yml index b0a31916f37c427d45d9365f3bf311acba22ef98..68e9e9544f362e7226e66ac629cbc7cbb90f191d 100644 --- a/web/modules/field_group/contrib/field_group_migrate/field_group_migrate.info.yml +++ b/web/modules/field_group/contrib/field_group_migrate/field_group_migrate.info.yml @@ -6,7 +6,7 @@ core_version_requirement: ^8.8 || ^9 dependencies: - field_group:field_group -# Information added by Drupal.org packaging script on 2021-08-09 -version: '8.x-3.2' +# Information added by Drupal.org packaging script on 2022-09-18 +version: '8.x-3.3' project: 'field_group' -datestamp: 1628513588 +datestamp: 1663516405 diff --git a/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d6/FieldGroup.php b/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d6/FieldGroup.php index 6438e5fba6fdbc536e228ed5fd113dbbef2295e4..ac6df889e870cd7ff52d17369632f0f56a7c0d8e 100644 --- a/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d6/FieldGroup.php +++ b/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d6/FieldGroup.php @@ -58,7 +58,7 @@ public function prepareRow(Row $row) { } /** - * + * {@inheritdoc} */ protected function transformEntityFormDisplaySettings(Row $row) { $row->setSourceProperty('extracted_settings', $row->getSourceProperty('settings/form')); @@ -102,11 +102,15 @@ protected function transformEntityFormDisplaySettings(Row $row) { } /** - * + * {@inheritdoc} */ protected function transformEntityViewDisplaySettings(Row $row) { $row->setSourceProperty('extracted_settings', $row->getSourceProperty('settings/display')); - $view_modes = array_diff(array_keys($row->getSourceProperty('extracted_settings')), ['label', 'description', 'weight']); + $view_modes = array_diff(array_keys($row->getSourceProperty('extracted_settings')), [ + 'label', + 'description', + 'weight', + ]); $view_modes = array_filter($view_modes, function ($value) { return !is_numeric($value); }); @@ -151,9 +155,6 @@ protected function transformEntityViewDisplaySettings(Row $row) { break; } - /** - * @todo: ? - */ if ($view_mode == 'full') { $view_mode = 'default'; } diff --git a/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d7/FieldGroup.php b/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d7/FieldGroup.php index ac9a3a2689512a4913049c3489524283ba8bad81..a5fbb0def68a372e6b7995f0db648abb4a11dc5f 100644 --- a/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d7/FieldGroup.php +++ b/web/modules/field_group/contrib/field_group_migrate/src/Plugin/migrate/source/d7/FieldGroup.php @@ -2,8 +2,13 @@ namespace Drupal\field_group_migrate\Plugin\migrate\source\d7; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\State\StateInterface; +use Drupal\field_group\FieldGroupFormatterPluginManager; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Drupal 7 field_group source. @@ -16,6 +21,51 @@ */ class FieldGroup extends DrupalSqlBase { + /** + * The field group formatter plugin manager. + * + * @var \Drupal\field_group\FieldGroupFormatterPluginManager + */ + protected $fieldGroupFormatterManager; + + /** + * Constructs a new FieldGroup migrate source plugin instance. + * + * @param array $configuration + * A configuration array containing information about the plugin instance. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\migrate\Plugin\MigrationInterface|null $migration + * The current migration plugin, if available. + * @param \Drupal\Core\State\StateInterface $state + * The state service. + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + * @param \Drupal\field_group\FieldGroupFormatterPluginManager $field_group_formatter_manager + * The field group formatter plugin manager. + */ + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityTypeManagerInterface $entity_type_manager, FieldGroupFormatterPluginManager $field_group_formatter_manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_type_manager); + $this->fieldGroupFormatterManager = $field_group_formatter_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $migration, + $container->get('state'), + $container->get('entity_type.manager'), + $container->get('plugin.manager.field_group.formatters') + ); + } + /** * {@inheritdoc} */ @@ -51,6 +101,8 @@ public function prepareRow(Row $row) { 'format_type' => $data['format_type'], 'region' => 'content', ]; + unset($settings['format_settings']['label']); + switch ($data['format_type']) { case 'div': $settings['format_type'] = 'html_element'; @@ -84,8 +136,22 @@ public function prepareRow(Row $row) { case 'html-element': $settings['format_type'] = 'html_element'; break; + } + // Add default settings. + $context = $row->getSourceProperty('mode') === 'form' ? 'form' : 'view'; + $default_settings = $this->fieldGroupFormatterManager->prepareConfiguration($settings['format_type'], $context, $settings); + $settings['format_settings'] += $default_settings['settings']; + + // Clean up obsolete settings. + switch ($settings['format_type']) { + case 'tabs': + // "Tabs" does not have a "formatter" configuration, but it might be + // present when the source field group was "htabs". + unset($settings['format_settings']['formatter']); + break; } + $row->setSourceProperty('settings', $settings); return parent::prepareRow($row); } diff --git a/web/modules/field_group/contrib/field_group_migrate/tests/fixtures/drupal7.php b/web/modules/field_group/contrib/field_group_migrate/tests/fixtures/drupal7.php index 347b5f73ff5e353237ba3c7f7b9d2a92150690a9..29a67b8153e4a3df5b47dd502ebd2fb27e2b5791 100644 --- a/web/modules/field_group/contrib/field_group_migrate/tests/fixtures/drupal7.php +++ b/web/modules/field_group/contrib/field_group_migrate/tests/fixtures/drupal7.php @@ -103,7 +103,7 @@ 'bundle' => 'user', 'mode' => 'default', 'parent_name' => '', - 'data' => 'a:5:{s:5:"label";s:17:"User group parent";s:6:"weight";i:1;s:8:"children";a:0:{}s:11:"format_type";s:3:"div";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}', + 'data' => 'a:5:{s:5:"label";s:17:"User group parent";s:6:"weight";i:1;s:8:"children";a:1:{i:0;s:16:"group_user_child";}s:11:"format_type";s:3:"div";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}', ]) ->values([ 'id' => '3', @@ -113,7 +113,7 @@ 'bundle' => 'user', 'mode' => 'default', 'parent_name' => 'group_user', - 'data' => 'a:5:{s:5:"label";s:16:"User group child";s:6:"weight";i:99;s:8:"children";a:1:{i:0;s:12:"user_picture";}s:11:"format_type";s:4:"tabs";s:15:"format_settings";a:2:{s:5:"label";s:16:"User group child";s:17:"instance_settings";a:2:{s:7:"classes";s:16:"user-group-child";s:2:"id";s:33:"group_article_node_article_teaser";}}}', + 'data' => 'a:5:{s:5:"label";s:16:"User group child";s:6:"weight";s:2:"99";s:8:"children";a:2:{i:0;s:15:"group_user_tab1";i:1;s:15:"group_user_tab2";}s:11:"format_type";s:4:"tabs";s:15:"format_settings";a:2:{s:5:"label";s:16:"User group child";s:17:"instance_settings";a:2:{s:2:"id";s:33:"group_article_node_article_teaser";s:7:"classes";s:16:"user-group-child";}}}', ]) ->values([ 'id' => '4', @@ -122,8 +122,8 @@ 'entity_type' => 'node', 'bundle' => 'article', 'mode' => 'teaser', - 'parent_name' => '', - 'data' => 'a:5:{s:5:"label";s:10:"htab group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:1:{s:7:"classes";s:10:"htab-group";}}}', + 'parent_name' => 'group_article_htabs', + 'data' => 'a:5:{s:5:"label";s:10:"htab group";s:6:"weight";s:1:"2";s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:1:{s:7:"classes";s:10:"htab-group";}}}', ]) ->values([ 'id' => '5', @@ -133,7 +133,7 @@ 'bundle' => 'page', 'mode' => 'form', 'parent_name' => '', - 'data' => 'a:5:{s:5:"label";s:15:"Node form group";s:6:"weight";i:0;s:8:"children";a:0:{}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}', + 'data' => 'a:5:{s:5:"label";s:15:"Node form group";s:6:"weight";s:1:"0";s:8:"children";a:1:{i:0;s:14:"group_page_tab";}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}', ]) ->values([ 'id' => '6', @@ -142,8 +142,58 @@ 'entity_type' => 'node', 'bundle' => 'article', 'mode' => 'form', + 'parent_name' => 'group_article_htabs', + 'data' => 'a:5:{s:5:"label";s:15:"htab form group";s:6:"weight";s:1:"2";s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}', + ]) + ->values([ + 'id' => '7', + 'identifier' => 'group_user_tab1|user|user|default', + 'group_name' => 'group_user_tab1', + 'entity_type' => 'user', + 'bundle' => 'user', + 'mode' => 'default', + 'parent_name' => 'group_user_child', + 'data' => 'a:5:{s:5:"label";s:10:"User tab 1";s:6:"weight";s:2:"99";s:8:"children";a:1:{i:0;s:10:"field_file";}s:11:"format_type";s:3:"tab";s:15:"format_settings";a:3:{s:5:"label";s:10:"User tab 1";s:17:"instance_settings";a:2:{s:7:"classes";s:15:"vtab vtab--open";s:11:"description";s:0:"";}s:9:"formatter";s:4:"open";}}', + ]) + ->values([ + 'id' => '8', + 'identifier' => 'group_user_tab2|user|user|default', + 'group_name' => 'group_user_tab2', + 'entity_type' => 'user', + 'bundle' => 'user', + 'mode' => 'default', + 'parent_name' => 'group_user_child', + 'data' => 'a:5:{s:5:"label";s:10:"User tab 2";s:6:"weight";s:3:"100";s:8:"children";a:1:{i:0;s:13:"field_integer";}s:11:"format_type";s:3:"tab";s:15:"format_settings";a:3:{s:5:"label";s:10:"User tab 2";s:17:"instance_settings";a:2:{s:7:"classes";s:17:"vtab vtab--closed";s:11:"description";s:0:"";}s:9:"formatter";s:6:"closed";}}', + ]) + ->values([ + 'id' => '9', + 'identifier' => 'group_article_htabs|node|article|form', + 'group_name' => 'group_article_htabs', + 'entity_type' => 'node', + 'bundle' => 'article', + 'mode' => 'form', 'parent_name' => '', - 'data' => 'a:5:{s:5:"label";s:15:"htab form group";s:6:"weight";i:2;s:8:"children";a:1:{i:0;s:11:"field_image";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:1:{s:17:"instance_settings";a:0:{}}}', + 'data' => 'a:5:{s:5:"label";s:15:"Horizontal tabs";s:6:"weight";s:1:"1";s:8:"children";a:1:{i:0;s:13:"group_article";}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:2:{s:9:"formatter";s:0:"";s:17:"instance_settings";a:2:{s:7:"classes";s:37:"group-article-htabs field-group-htabs";s:2:"id";s:0:"";}}}', + ]) + ->values([ + 'id' => '10', + 'identifier' => 'group_article_htabs|node|article|teaser', + 'group_name' => 'group_article_htabs', + 'entity_type' => 'node', + 'bundle' => 'article', + 'mode' => 'teaser', + 'parent_name' => '', + 'data' => 'a:5:{s:5:"label";s:15:"Horizontal tabs";s:6:"weight";s:1:"1";s:8:"children";a:1:{i:0;s:13:"group_article";}s:11:"format_type";s:5:"htabs";s:15:"format_settings";a:2:{s:5:"label";s:15:"Horizontal tabs";s:17:"instance_settings";a:2:{s:2:"id";s:0:"";s:7:"classes";s:0:"";}}}', + ]) + ->values([ + 'id' => '11', + 'identifier' => 'group_page_tab|node|page|form', + 'group_name' => 'group_page_tab', + 'entity_type' => 'node', + 'bundle' => 'page', + 'mode' => 'form', + 'parent_name' => 'group_page', + 'data' => 'a:5:{s:5:"label";s:14:"Horizontal tab";s:6:"weight";s:2:"17";s:8:"children";a:1:{i:0;s:16:"field_text_plain";}s:11:"format_type";s:4:"htab";s:15:"format_settings";a:3:{s:5:"label";s:14:"Horizontal tab";s:17:"instance_settings";a:3:{s:15:"required_fields";i:1;s:7:"classes";s:31:"group-page-tab field-group-htab";s:11:"description";s:0:"";}s:9:"formatter";s:4:"open";}}', ]) ->execute(); diff --git a/web/modules/field_group/contrib/field_group_migrate/tests/src/Functional/MigrateUiFieldGroupTest.php b/web/modules/field_group/contrib/field_group_migrate/tests/src/Functional/MigrateUiFieldGroupTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d4859cb7afad48ae439211d067c2251abcb6ae4c --- /dev/null +++ b/web/modules/field_group/contrib/field_group_migrate/tests/src/Functional/MigrateUiFieldGroupTest.php @@ -0,0 +1,198 @@ +<?php + +namespace Drupal\Tests\field_group_migrate\Functional; + +use Drupal\Core\Url; +use Drupal\Tests\field_group_migrate\Traits\FieldGroupMigrationAssertionsTrait; +use Drupal\Tests\migrate_drupal_ui\Functional\MigrateUpgradeTestBase; + +/** + * Tests migration of field groups with Migrate Drupal UI. + * + * @group field_group_migrate + */ +class MigrateUiFieldGroupTest extends MigrateUpgradeTestBase { + + use FieldGroupMigrationAssertionsTrait; + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'field_group_migrate', + 'field_ui', + 'migrate_drupal_ui', + 'telephone', + ]; + + /** + * {@inheritdoc} + */ + protected function getSourceBasePath() { + return drupal_get_path('module', 'migrate_drupal_ui') . '/tests/src/Functional/d7/files'; + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + // Field Group's migration database fixture extends Drupal core's fixture. + $this->loadFixture(drupal_get_path('module', 'migrate_drupal') . '/tests/fixtures/drupal7.php'); + $this->loadFixture(drupal_get_path('module', 'field_group_migrate') . '/tests/fixtures/drupal7.php'); + } + + /** + * Tests the result of the field group migration. + */ + public function testFieldGroupMigrate() { + $page = $this->getSession()->getPage(); + $this->executeMigrateUpgradeViaUi(); + + $this->assertNodeArticleDefaultForm(); + $this->assertNodePageDefaultForm(); + $this->assertNodeArticleTeaserDisplay(); + $this->assertNodePageDefaultDisplay(); + $this->assertUserDefaultDisplay(); + + // Re-save every field group's configuration to ensure that the migrated + // settings aren't changed. + $this->drupalGet(Url::fromRoute('entity.entity_form_display.node.default', [ + 'node_type' => 'article', + ])); + $page->findButton('group_article_htabs_group_settings_edit')->click(); + $page->findButton('Update')->click(); + $page->findButton('group_article_group_settings_edit')->click(); + $this->submitForm([], 'Save'); + + $this->drupalGet(Url::fromRoute('entity.entity_form_display.node.default', [ + 'node_type' => 'page', + ])); + $page->findButton('group_page_group_settings_edit')->click(); + $page->findButton('Update')->click(); + $page->findButton('group_page_tab_group_settings_edit')->click(); + $this->submitForm([], 'Save'); + + $this->drupalGet(Url::fromRoute('entity.entity_view_display.node.view_mode', [ + 'node_type' => 'article', + 'view_mode_name' => 'teaser', + ])); + $page->findButton('group_article_htabs_group_settings_edit')->click(); + $page->findButton('Update')->click(); + $page->findButton('group_article_group_settings_edit')->click(); + $this->submitForm([], 'Save'); + + $this->drupalGet(Url::fromRoute('entity.entity_view_display.node.default', [ + 'node_type' => 'page', + ])); + $page->findButton('group_page_group_settings_edit')->click(); + $this->submitForm([], 'Save'); + + $this->drupalGet(Url::fromRoute('entity.entity_view_display.user.default')); + $page->findButton('group_user_group_settings_edit')->click(); + $page->findButton('Update')->click(); + $page->findButton('group_user_child_group_settings_edit')->click(); + $page->findButton('Update')->click(); + $page->findButton('group_user_tab1_group_settings_edit')->click(); + $page->findButton('Update')->click(); + $page->findButton('group_user_tab2_group_settings_edit')->click(); + $this->submitForm([], 'Save'); + + // Re-test the migrated field group configurations. + $this->assertNodeArticleDefaultForm(); + $this->assertNodePageDefaultForm(); + $this->assertNodeArticleTeaserDisplay(); + $this->assertNodePageDefaultDisplay(); + $this->assertUserDefaultDisplay(); + } + + /** + * Submits the Migrate Upgrade source connection and files form. + */ + protected function submitMigrateUpgradeSourceConnectionForm() { + $connection_options = $this->sourceDatabase->getConnectionOptions(); + $this->drupalGet('/upgrade'); + $session = $this->assertSession(); + $session->responseContains("Upgrade a site by importing its files and the data from its database into a clean and empty new install of Drupal"); + + $this->drupalPostForm(NULL, [], 'Continue'); + $session->pageTextContains('Provide credentials for the database of the Drupal site you want to upgrade.'); + + $driver = $connection_options['driver']; + + // Use the driver connection form to get the correct options out of the + // database settings. This supports all of the databases we test against. + $drivers = drupal_get_database_types(); + $form = $drivers[$driver]->getFormOptions($connection_options); + $connection_options = array_intersect_key($connection_options, $form + $form['advanced_options']); + $version = $this->getLegacyDrupalVersion($this->sourceDatabase); + $edit = [ + $driver => $connection_options, + 'source_private_file_path' => $this->getSourceBasePath(), + 'version' => $version, + 'source_base_path' => $this->getSourceBasePath(), + ]; + + if (count($drivers) !== 1) { + $edit['driver'] = $driver; + } + $edits = $this->translatePostValues($edit); + + $this->drupalPostForm(NULL, $edits, 'Review upgrade'); + } + + /** + * Executes the upgrade process with Migrate Drupal UI. + */ + protected function executeMigrateUpgradeViaUi() { + $this->submitMigrateUpgradeSourceConnectionForm(); + $assert_session = $this->assertSession(); + $assert_session->pageTextNotContains('Resolve all issues below to continue the upgrade.'); + + // When complete node migration is executed, Drupal 8.9 and above (even 9.x) + // will complain about content id conflicts. Drupal 8.8 and below won't. + // @see https://www.drupal.org/node/2928118 + // @see https://www.drupal.org/node/3105503 + if ($this->getSession()->getPage()->findButton('I acknowledge I may lose data. Continue anyway.')) { + $this->drupalPostForm(NULL, [], 'I acknowledge I may lose data. Continue anyway.'); + $assert_session->statusCodeEquals(200); + } + + // Perform the upgrade. + $this->drupalPostForm(NULL, [], 'Perform upgrade'); + $this->assertText('Congratulations, you upgraded Drupal!'); + + // Have to reset all the statics after migration to ensure entities are + // loadable. + $this->resetAll(); + } + + /** + * {@inheritdoc} + */ + protected function getEntityCounts() { + return []; + } + + /** + * {@inheritdoc} + */ + protected function getAvailablePaths() { + return []; + } + + /** + * {@inheritdoc} + */ + protected function getMissingPaths() { + return []; + } + + /** + * {@inheritdoc} + */ + protected function getEntityCountsIncremental() { + return []; + } + +} diff --git a/web/modules/field_group/contrib/field_group_migrate/tests/src/Kernel/Migrate/d7/MigrateFieldGroupTest.php b/web/modules/field_group/contrib/field_group_migrate/tests/src/Kernel/Migrate/d7/MigrateFieldGroupTest.php index 71c20bd0efef8889c1fb9c014b0ae332dde0dd59..3557802702b794ae5f2cb2627998eefa03b59228 100644 --- a/web/modules/field_group/contrib/field_group_migrate/tests/src/Kernel/Migrate/d7/MigrateFieldGroupTest.php +++ b/web/modules/field_group/contrib/field_group_migrate/tests/src/Kernel/Migrate/d7/MigrateFieldGroupTest.php @@ -2,6 +2,9 @@ namespace Drupal\Tests\field_group_migrate\Kernel\Migrate\d7; +use Drupal\Core\Entity\Entity\EntityFormDisplay; +use Drupal\Core\Entity\Entity\EntityViewDisplay; +use Drupal\Tests\field_group_migrate\Traits\FieldGroupMigrationAssertionsTrait; use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; /** @@ -11,6 +14,8 @@ */ class MigrateFieldGroupTest extends MigrateDrupal7TestBase { + use FieldGroupMigrationAssertionsTrait; + /** * {@inheritdoc} */ @@ -48,72 +53,22 @@ protected function setUp() { ]); } - /** - * Asserts various aspects of a migrated field group. - * - * @param $id - * The id of the entity display to which the field group applies. - * @param $type - * The destination type. - * @param $group_name - * The name of the field group. - * @param $expected_label - * The expected label. - * @param int $expected_weight - * The expected label. - * @param array $expected_format_settings - * The expected format settings. - * @param string $expected_format_type - * The expected format type. - * @param array $expected_children - * The expected children. - * @param string $expected_parent_name - * The expected parent name. - */ - protected function assertEntity($id, $type, $group_name, $expected_label, $expected_weight = 0, $expected_format_settings = [], $expected_format_type = 'tabs', $expected_children = [], $expected_parent_name = '') { - /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity */ - $entity = \Drupal::entityTypeManager() - ->getStorage($type) - ->load($id); - $field_group_settings = $entity->getThirdPartySettings('field_group'); - $this->assertNotEmpty($field_group_settings); - $this->assertArrayHasKey($group_name, $field_group_settings); - - $field_group = $field_group_settings[$group_name]; - $this->assertEquals($expected_label, $field_group['label']); - $this->assertEquals($expected_format_settings, $field_group['format_settings']); - $this->assertEquals($expected_children, $field_group['children']); - $this->assertEquals($expected_parent_name, $field_group['parent_name']); - $this->assertEquals($expected_weight, $field_group['weight']); - $this->assertEquals($expected_format_type, $field_group['format_type']); - } - /** * Test field group migration from Drupal 7 to 8. */ public function testFieldGroup() { - $this->assertEntity('node.page.default', 'entity_view_display', 'group_page', 'Node group', 0, ['direction' => 'horizontal']); - $this->assertEntity('user.user.default', 'entity_view_display', 'group_user', 'User group parent', 1, ['element' => 'div'], 'html_element'); - $this->assertEntity('user.user.default', 'entity_view_display', 'group_user_child', 'User group child', 99, ['direction' => 'vertical', 'label' => 'User group child', 'classes' => 'user-group-child', 'id' => 'group_article_node_article_teaser'], 'tabs', ['user_picture'], 'group_user'); - $this->assertEntity('node.article.teaser', 'entity_view_display', 'group_article', 'htab group', 2, ['classes' => 'htab-group'], 'tab', ['field_image']); - + $this->assertNodeArticleTeaserDisplay(); + $this->assertNodePageDefaultDisplay(); + $this->assertUserDefaultDisplay(); // Check an entity_view_display without a field group. - /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $entity */ - $entity = \Drupal::entityTypeManager() - ->getStorage('entity_view_display') - ->load('node.page.teaser'); - $field_group_settings = $entity->getThirdPartySettings('field_group'); - $this->assertEmpty($field_group_settings); - - $this->assertEntity('node.page.default', 'entity_form_display', 'group_page', 'Node form group', 0, ['direction' => 'horizontal']); - $this->assertEntity('node.article.default', 'entity_form_display', 'group_article', 'htab form group', 2, [], 'tab', ['field_image']); + $page_teaser_display = EntityViewDisplay::load('node.page.teaser'); + $this->assertEmpty($page_teaser_display->getThirdPartySettings('field_group')); + $this->assertNodeArticleDefaultForm(); + $this->assertNodePageDefaultForm(); // Check an entity_form_display without a field group. - $entity = \Drupal::entityTypeManager() - ->getStorage('entity_form_display') - ->load('node.blog.default'); - $field_group_settings = $entity->getThirdPartySettings('field_group'); - $this->assertEmpty($field_group_settings); + $blog_form = EntityFormDisplay::load('node.blog.default'); + $this->assertEmpty($blog_form->getThirdPartySettings('field_group')); } } diff --git a/web/modules/field_group/contrib/field_group_migrate/tests/src/Traits/FieldGroupMigrationAssertionsTrait.php b/web/modules/field_group/contrib/field_group_migrate/tests/src/Traits/FieldGroupMigrationAssertionsTrait.php new file mode 100644 index 0000000000000000000000000000000000000000..3ed5b9b763f05ee11b088a9791db47614f79c053 --- /dev/null +++ b/web/modules/field_group/contrib/field_group_migrate/tests/src/Traits/FieldGroupMigrationAssertionsTrait.php @@ -0,0 +1,238 @@ +<?php + +namespace Drupal\Tests\field_group_migrate\Traits; + +use Drupal\Core\Entity\Display\EntityDisplayInterface; +use Drupal\Core\Entity\Entity\EntityFormDisplay; +use Drupal\Core\Entity\Entity\EntityViewDisplay; + +/** + * Trait for testing migrated Field Group settings. + */ +trait FieldGroupMigrationAssertionsTrait { + + /** + * Tests article node form display's field group settings. + */ + protected function assertNodeArticleDefaultForm() { + $form_display_default = EntityFormDisplay::load('node.article.default'); + assert($form_display_default instanceof EntityDisplayInterface); + $this->assertEquals([ + 'group_article' => [ + 'children' => ['field_image'], + 'parent_name' => 'group_article_htabs', + 'weight' => 2, + 'label' => 'htab form group', + 'format_settings' => [ + 'classes' => '', + 'id' => '', + 'formatter' => 'closed', + 'description' => '', + 'required_fields' => TRUE, + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tab', + 'region' => 'content', + ], + 'group_article_htabs' => [ + 'children' => ['group_article'], + 'parent_name' => '', + 'weight' => 1, + 'label' => 'Horizontal tabs', + 'format_settings' => [ + 'direction' => 'horizontal', + 'classes' => 'group-article-htabs field-group-htabs', + 'id' => '', + 'width_breakpoint' => 640, + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tabs', + 'region' => 'content', + ], + ], $form_display_default->getThirdPartySettings('field_group')); + } + + /** + * Tests page node form display's field group settings. + */ + protected function assertNodePageDefaultForm() { + $form_display_default = EntityFormDisplay::load('node.page.default'); + assert($form_display_default instanceof EntityDisplayInterface); + $this->assertEquals([ + 'group_page' => [ + 'children' => ['group_page_tab'], + 'parent_name' => '', + 'weight' => 0, + 'label' => 'Node form group', + 'format_settings' => [ + 'direction' => 'horizontal', + 'classes' => '', + 'id' => '', + 'width_breakpoint' => 640, + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tabs', + 'region' => 'content', + ], + 'group_page_tab' => [ + 'children' => ['field_text_plain'], + 'parent_name' => 'group_page', + 'weight' => 17, + 'label' => 'Horizontal tab', + 'format_settings' => [ + 'classes' => 'group-page-tab field-group-htab', + 'id' => '', + 'formatter' => 'open', + 'description' => '', + 'required_fields' => TRUE, + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tab', + 'region' => 'content', + ], + ], $form_display_default->getThirdPartySettings('field_group')); + } + + /** + * Tests node teaser display's field group settings. + */ + protected function assertNodeArticleTeaserDisplay() { + $view_display_default = EntityViewDisplay::load('node.article.teaser'); + assert($view_display_default instanceof EntityDisplayInterface); + $this->assertEquals([ + 'group_article' => [ + 'children' => ['field_image'], + 'parent_name' => 'group_article_htabs', + 'weight' => 2, + 'label' => 'htab group', + 'format_settings' => [ + 'classes' => 'htab-group', + 'id' => '', + 'formatter' => 'closed', + 'description' => '', + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tab', + 'region' => 'content', + ], + 'group_article_htabs' => [ + 'children' => ['group_article'], + 'parent_name' => '', + 'weight' => 1, + 'label' => 'Horizontal tabs', + 'format_settings' => [ + 'classes' => '', + 'id' => '', + 'direction' => 'horizontal', + 'width_breakpoint' => 640, + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tabs', + 'region' => 'content', + ], + ], $view_display_default->getThirdPartySettings('field_group')); + } + + /** + * Tests page default display's field group settings. + */ + protected function assertNodePageDefaultDisplay() { + $view_display_default = EntityViewDisplay::load('node.page.default'); + assert($view_display_default instanceof EntityDisplayInterface); + $this->assertEquals([ + 'group_page' => [ + 'children' => [], + 'parent_name' => '', + 'weight' => 0, + 'label' => 'Node group', + 'format_settings' => [ + 'direction' => 'horizontal', + 'classes' => '', + 'id' => '', + 'width_breakpoint' => 640, + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tabs', + 'region' => 'content', + ], + ], $view_display_default->getThirdPartySettings('field_group')); + } + + /** + * Tests user default display's field group settings. + */ + protected function assertUserDefaultDisplay() { + $view_display_default = EntityViewDisplay::load('user.user.default'); + assert($view_display_default instanceof EntityDisplayInterface); + $this->assertEquals([ + 'group_user' => [ + 'children' => [ + 'group_user_child', + ], + 'parent_name' => '', + 'weight' => 1, + 'label' => 'User group parent', + 'format_settings' => [ + 'element' => 'div', + 'show_label' => FALSE, + 'label_element' => 'h3', + 'label_element_classes' => '', + 'attributes' => '', + 'effect' => 'none', + 'speed' => 'fast', + 'id' => '', + 'classes' => '', + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'html_element', + 'region' => 'content', + ], + 'group_user_child' => [ + 'children' => ['group_user_tab1', 'group_user_tab2'], + 'parent_name' => 'group_user', + 'weight' => 99, + 'label' => 'User group child', + 'format_settings' => [ + 'classes' => 'user-group-child', + 'id' => 'group_article_node_article_teaser', + 'direction' => 'vertical', + 'width_breakpoint' => 640, + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tabs', + 'region' => 'content', + ], + 'group_user_tab1' => [ + 'children' => ['field_file'], + 'parent_name' => 'group_user_child', + 'weight' => 99, + 'label' => 'User tab 1', + 'format_settings' => [ + 'classes' => 'vtab vtab--open', + 'id' => '', + 'formatter' => 'open', + 'description' => '', + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tab', + 'region' => 'content', + ], + 'group_user_tab2' => [ + 'children' => ['field_integer'], + 'parent_name' => 'group_user_child', + 'weight' => 100, + 'label' => 'User tab 2', + 'format_settings' => [ + 'classes' => 'vtab vtab--closed', + 'id' => '', + 'formatter' => 'closed', + 'description' => '', + 'show_empty_fields' => FALSE, + ], + 'format_type' => 'tab', + 'region' => 'content', + ], + ], $view_display_default->getThirdPartySettings('field_group')); + } + +} diff --git a/web/modules/field_group/contrib/field_group_migrate/tests/src/Unit/Migrate/d7/FieldGroupTest.php b/web/modules/field_group/contrib/field_group_migrate/tests/src/Unit/Migrate/d7/FieldGroupTest.php index 5a43c278385351bcfce3363de90dea5a123cdf30..84d72670c9688c8f1f27d03fba9b0a6bb97f91cc 100644 --- a/web/modules/field_group/contrib/field_group_migrate/tests/src/Unit/Migrate/d7/FieldGroupTest.php +++ b/web/modules/field_group/contrib/field_group_migrate/tests/src/Unit/Migrate/d7/FieldGroupTest.php @@ -13,6 +13,9 @@ class FieldGroupTest extends MigrateSqlSourceTestBase { const PLUGIN_CLASS = 'Drupal\field_group_migrate\Plugin\migrate\source\d7\FieldGroup'; + /** + * {@inheritdoc} + */ protected $migrationConfiguration = [ 'id' => 'test', 'source' => [ @@ -20,6 +23,9 @@ class FieldGroupTest extends MigrateSqlSourceTestBase { ], ]; + /** + * {@inheritdoc} + */ protected $expectedResults = [ [ 'id' => '1', @@ -95,7 +101,7 @@ protected function setUp() { * {@inheritdoc} */ public function providerSource() { - // @TODO FIX. + // @todo Fix source. return []; } diff --git a/web/modules/field_group/field_group.api.php b/web/modules/field_group/field_group.api.php index a81977953f016db9eacb91cc3758d1aa6d7fc0d8..4da33db28fcbde99f2a530ed348c99027b768161 100644 --- a/web/modules/field_group/field_group.api.php +++ b/web/modules/field_group/field_group.api.php @@ -38,7 +38,10 @@ function hook_field_group_pre_render(array &$element, &$group, &$rendering_objec $manager = Drupal::service('plugin.manager.field_group.formatters'); $plugin = $manager->getInstance([ 'format_type' => $group->format_type, - 'configuration' => ['label' => $group->label, 'settings' => $group->format_settings], + 'configuration' => [ + 'label' => $group->label, + 'settings' => $group->format_settings, + ], 'group' => $group, ]); $plugin->preRender($element, $rendering_object); @@ -79,9 +82,9 @@ function hook_field_group_build_pre_render_alter(array &$element) { * * @param array $element * The element being processed. - * @param $group + * @param object $group * The group info. - * @param $complete_form + * @param object $complete_form * The complete form. */ function hook_field_group_form_process(array &$element, &$group, &$complete_form) { @@ -97,9 +100,9 @@ function hook_field_group_form_process(array &$element, &$group, &$complete_form * * @param array $element * The element being processed. - * @param $group + * @param object $group * The group info. - * @param $complete_form + * @param object $complete_form * The complete form. */ function hook_field_group_form_process_alter(array &$element, &$group, &$complete_form) { @@ -116,8 +119,8 @@ function hook_field_group_form_process_alter(array &$element, &$group, &$complet * @param array $element * The element being processed. * @param \Drupal\Core\Form\FormStateInterface $form_state - * The form state - * @param $complete_form + * The form state. + * @param object $complete_form * The complete form. */ function hook_field_group_form_process_build_alter(array &$element, FormStateInterface $form_state, &$complete_form) { @@ -131,14 +134,13 @@ function hook_field_group_form_process_build_alter(array &$element, FormStateInt /** * Hook into the deletion event of a fieldgroup. * - * @param $group + * @param object $group * The deleted group. */ function hook_field_group_delete_field_group($group) { // Extra cleanup code. } - /** * @} End of "addtogroup hooks". */ diff --git a/web/modules/field_group/field_group.info.yml b/web/modules/field_group/field_group.info.yml index 1b207b580cd4a4bce833a1023a3d708eaccd81a7..59e05bd1c9bbdd3ff2ec8cea7be958076e0a6ab9 100644 --- a/web/modules/field_group/field_group.info.yml +++ b/web/modules/field_group/field_group.info.yml @@ -6,7 +6,7 @@ core_version_requirement: ^8.8 || ^9 dependencies: - drupal:field -# Information added by Drupal.org packaging script on 2021-08-09 -version: '8.x-3.2' +# Information added by Drupal.org packaging script on 2022-09-18 +version: '8.x-3.3' project: 'field_group' -datestamp: 1628513588 +datestamp: 1663516405 diff --git a/web/modules/field_group/field_group.install b/web/modules/field_group/field_group.install index 2e2dbe1764231cc527965a5512d831e7cb3f816c..c3e3186e23d04cff14ac045fb55e3e22a163fb6d 100644 --- a/web/modules/field_group/field_group.install +++ b/web/modules/field_group/field_group.install @@ -19,7 +19,7 @@ function field_group_requirements($phase) { 'title' => t('Field Group'), 'value' => t('jQuery UI Accordion not enabled'), 'description' => t('If you want to use the Field Group accordion formatter, you will need to install the <a href=":link" target="_blank">jQuery UI Accordion</a> module.', [':link' => 'https://www.drupal.org/project/jquery_ui_accordion']), - 'severity' => REQUIREMENT_WARNING, + 'severity' => REQUIREMENT_INFO, ]; } else { @@ -56,8 +56,7 @@ function field_group_update_8302() { } } catch (\Exception $e) { - return - t('If you want to use the Field Group accordion formatter, you will need to install the <a href=":link" target="_blank">jQuery UI Accordion</a> module.', + return t('If you want to use the Field Group accordion formatter, you will need to install the <a href=":link" target="_blank">jQuery UI Accordion</a> module.', [':link' => 'https://www.drupal.org/project/jquery_ui_accordion']); } } diff --git a/web/modules/field_group/field_group.libraries.yml b/web/modules/field_group/field_group.libraries.yml index f5aed67001d1fd7e08ace8ff730b7f991284c3ab..553640f5b7784ea193010e2591179137aaded51d 100644 --- a/web/modules/field_group/field_group.libraries.yml +++ b/web/modules/field_group/field_group.libraries.yml @@ -23,24 +23,36 @@ formatter.accordion: js: formatters/accordion/accordion.js: {} dependencies: - - core/jquery.ui.accordion + - core/jquery + - core/jquery.once + - jquery_ui_accordion/accordion formatter.html_element: js: formatters/html_element/html-element.js: {} + dependencies: + - core/jquery + - core/jquery.once formatter.fieldset: js: formatters/fieldset/fieldset.js: {} + dependencies: + - core/jquery + - core/jquery.once formatter.details: js: formatters/details/details.js: {} + dependencies: + - core/jquery formatter.tabs: js: formatters/tabs/tabs.js: {} dependencies: + - core/jquery + - core/jquery.once - core/modernizr element.horizontal_tabs: @@ -51,5 +63,7 @@ element.horizontal_tabs: component: formatters/tabs/horizontal-tabs.css: {} dependencies: + - core/jquery + - core/jquery.once - core/drupal.collapse - core/modernizr diff --git a/web/modules/field_group/field_group.module b/web/modules/field_group/field_group.module index 52b0cbd37cf10c62eb4d53849a4fdc81911a468b..6008cb85bc9322119aff13e0d13f385883189f0e 100644 --- a/web/modules/field_group/field_group.module +++ b/web/modules/field_group/field_group.module @@ -5,8 +5,6 @@ * Allows administrators to attach field groups. */ -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\ds\Ds; use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Entity\Display\EntityDisplayInterface; use Drupal\Core\Entity\Entity\EntityFormDisplay; @@ -15,6 +13,8 @@ use Drupal\Core\Form\ConfirmFormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\ds\Ds; use Drupal\field_group\Element\VerticalTabs; use Drupal\field_group\FormatterHelper; @@ -33,6 +33,20 @@ function field_group_help($route_name, RouteMatchInterface $route_match) { } } +/** + * Implements hook_module_implements_alter(). + */ +function field_group_module_implements_alter(&$implementations, $hook) { + switch ($hook) { + // Move our hook_form_alter() implementation to the end of the list. + case 'form_alter': + $group = $implementations['field_group']; + unset($implementations['field_group']); + $implementations['field_group'] = $group; + break; + } +} + /** * Implements hook_library_info_alter(). */ @@ -44,7 +58,7 @@ function field_group_library_info_alter(&$libraries, $extension) { if (\Drupal::moduleHandler()->moduleExists('jquery_ui_accordion')) { $libraries['formatter.accordion']['dependencies'] = ['jquery_ui_accordion/accordion']; } - elseif (version_compare(\Drupal::VERSION, 9) > 0 ) { + elseif (version_compare(\Drupal::VERSION, 9) > 0) { $libraries['formatter.accordion']['js'] = []; $libraries['formatter.accordion']['dependencies'] = []; } @@ -178,14 +192,19 @@ function field_group_element_info_alter(array &$info) { $info['vertical_tabs']['#pre_render'] = []; } - $info['vertical_tabs']['#process'][] = [VerticalTabs::class, 'processGroup']; - $info['vertical_tabs']['#pre_render'][] = [VerticalTabs::class, 'preRenderGroup']; + $info['vertical_tabs']['#process'][] = [ + VerticalTabs::class, + 'processGroup', + ]; + $info['vertical_tabs']['#pre_render'][] = [ + VerticalTabs::class, + 'preRenderGroup', + ]; } } /** * Implements hook_form_FORM_ID_alter(). - * Using hook_form_field_ui_form_display_overview_form_alter. */ function field_group_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) { $form_state->loadInclude('field_group', 'inc', 'includes/field_ui'); @@ -194,7 +213,6 @@ function field_group_form_entity_form_display_edit_form_alter(&$form, FormStateI /** * Implements hook_form_FORM_ID_alter(). - * Using hook_form_field_ui_display_overview_form_alter. */ function field_group_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) { $form_state->loadInclude('field_group', 'inc', 'includes/field_ui'); @@ -207,7 +225,7 @@ function field_group_form_entity_view_display_edit_form_alter(&$form, FormStateI function field_group_field_info_max_weight($entity_type, $bundle, $context, $context_mode) { // Prevent recursion. // @see https://www.drupal.org/project/drupal/issues/2966137 - static $recursion_tracker = []; + $recursion_tracker = &drupal_static(__FUNCTION__, []); // Track the entity display. $key = $entity_type . ':' . $bundle . ':' . $context . ':' . $context_mode; @@ -259,6 +277,7 @@ function field_group_form_alter(array &$form, FormStateInterface $form_state) { field_group_attach_groups($form, $context); $form['#process'][] = [FormatterHelper::class, 'formProcess']; + $form['#pre_render'][] = [FormatterHelper::class, 'formGroupPreRender']; } } @@ -301,7 +320,10 @@ function field_group_form_media_library_add_form_upload_alter(&$form, FormStateI ]; field_group_attach_groups($form['media'][$delta]['fields'], $context); - $form['media'][$delta]['fields']['#process'][] = [FormatterHelper::class, 'formProcess']; + $form['media'][$delta]['fields']['#process'][] = [ + FormatterHelper::class, + 'formProcess', + ]; } } @@ -325,7 +347,10 @@ function field_group_form_layout_builder_update_block_alter(&$form, FormStateInt ]; field_group_attach_groups($form['settings']['block_form'], $context); - $form['settings']['block_form']['#process'][] = [FormatterHelper::class, 'formProcess']; + $form['settings']['block_form']['#process'][] = [ + FormatterHelper::class, + 'formProcess', + ]; } /** @@ -363,7 +388,7 @@ function field_group_entity_view_alter(&$build, EntityInterface $entity, EntityD } } - // If DS is enabled, no pre render is needed (DS adds fieldgroup preprocessing). + // If DS is enabled, no pre render is needed (preprocessing included in DS). if (!$ds_enabled) { $build['#pre_render'][] = [FormatterHelper::class, 'entityViewPrender']; } @@ -400,12 +425,17 @@ function field_group_conditional_fields_children($entity_type, $bundle_name) { * @param array $element * Form that is being rendered. * - * @deprecated Use field_group_form_process instead. - * * @return array + * Prerendered form. + * + * @deprecated in field_group:3.1.0 and is removed from field_group:4.0.0. + * Use field_group_form_process() instead. + * + * @see https://www.drupal.org/project/field_group/issues/3147495 */ function field_group_form_pre_render(array $element) { - return field_group_form_process($element); + $element = field_group_form_process($element); + return FormatterHelper::formGroupPreRender($element); } /** @@ -419,6 +449,7 @@ function field_group_form_pre_render(array $element) { * The complete form structure. * * @return array + * Processed form. */ function field_group_form_process(array &$element, FormStateInterface $form_state = NULL, array &$form = []) { return FormatterHelper::formProcess($element, $form_state, $form); @@ -443,7 +474,10 @@ function field_group_field_group_form_process(array &$element, &$group, &$comple $manager = Drupal::service('plugin.manager.field_group.formatters'); $plugin = $manager->getInstance([ 'format_type' => $group->format_type, - 'configuration' => ['label' => $group->label, 'settings' => $group->format_settings], + 'configuration' => [ + 'label' => $group->label, + 'settings' => $group->format_settings, + ], 'group' => $group, ]); if ($plugin) { @@ -453,15 +487,8 @@ function field_group_field_group_form_process(array &$element, &$group, &$comple /** * Implements hook_field_group_pre_render(). - * - * @param array $element - * Group beïng rendered. - * @param object $group - * The Field group info. - * @param $rendering_object - * The entity / form beïng rendered */ -function field_group_field_group_pre_render(&$element, &$group, &$rendering_object) { +function field_group_field_group_pre_render(array &$element, &$group, &$rendering_object) { // Add all field_group format types to the js settings. $element['#attached']['drupalSettings']['field_group'] = [ $group->format_type => [ @@ -490,25 +517,16 @@ function field_group_field_group_pre_render(&$element, &$group, &$rendering_obje /** * Implements hook_field_group_form_process_build_alter(). - * - * @param array $element - * Element being processed. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - * @param array $form - * The complete form structure. */ -function field_group_field_group_form_process_build_alter(array &$element, $form_state = NULL, &$form = []) { +function field_group_field_group_form_process_build_alter(array &$element, FormStateInterface $form_state = NULL, array &$form = []) { $groups = array_keys($element['#fieldgroups']); field_group_remove_empty_form_groups($element, $groups, $element['#entity_type']); } /** * Implements hook_field_group_build_pre_render_alter(). - * - * @param array $element */ -function field_group_field_group_build_pre_render_alter(&$element) { +function field_group_field_group_build_pre_render_alter(array &$element) { // Someone is doing a node view, in a node view. Reset content. if (isset($element['#node']->content) && count($element['#node']->content) > 0) { $element['#node']->content = []; @@ -531,11 +549,11 @@ function field_group_field_group_build_pre_render_alter(&$element) { * Attach groups to the (form) build. * * @param array $element - * The part of the form. + * The current element. * @param array $context * The contextual information. */ -function field_group_attach_groups(&$element, $context) { +function field_group_attach_groups(array &$element, array $context) { if ($context['mode'] == '_custom') { return; @@ -564,9 +582,9 @@ function field_group_attach_groups(&$element, $context) { /** * Pre-render callback for entity views. * - * @param preprocess $vars + * @param array $vars * Variables. - * @param $context + * @param string $context * The display context (entity type, form or view). * * @return array @@ -644,15 +662,15 @@ function field_group_build_entity_groups(array &$vars, $context = 'view') { * The current element to analyse for grouping. * @param array $vars * Rendering vars from the entity being viewed. - * @param array $context + * @param string $context * The display context (entity type, form or view). */ -function field_group_fields_nest(&$element, &$vars = NULL, $context = NULL) { +function field_group_fields_nest(array &$element, array &$vars = NULL, $context = NULL) { // Create all groups and keep a flat list of references to these groups. $group_references = []; foreach ($element['#fieldgroups'] as $group_name => $group) { - // Construct own weight, as some fields (for example preprocess fields) don't have weight set. + // Set own weight, as some fields (e.g. preprocess fields) don't set it. if (!isset($element[$group_name])) { $element[$group_name] = []; } @@ -683,7 +701,7 @@ function field_group_fields_nest(&$element, &$vars = NULL, $context = NULL) { $key = field_group_get_content_element_key($context); if (!isset($element['#fieldgroups'][$child_name]) && isset($vars[$key][$child_name])) { - // ECK marks his default properties as printed, while it is not printed yet. + // ECK marks default properties as printed, while not printed yet. if ($context === 'eck_entity' && !empty($vars[$key][$child_name]['#printed'])) { $vars[$key][$child_name]['#printed'] = FALSE; } @@ -701,8 +719,8 @@ function field_group_fields_nest(&$element, &$vars = NULL, $context = NULL) { // Form being viewed. else { // Block denied fields (#access) before they are put in groups. - // Fields (not groups) that don't have children (like field_permissions) are removed - // in field_group_field_group_build_pre_render_alter. + // Fields (not groups) that don't have children (like field_permissions) + // are removed in field_group_field_group_build_pre_render_alter. if (isset($element[$child_name]) && (!isset($element[$child_name]['#access']) || $element[$child_name]['#access'])) { // If this is a group, we have to use a reference to keep the reference // list intact (but if it is a field we don't mind). @@ -715,7 +733,7 @@ function field_group_fields_nest(&$element, &$vars = NULL, $context = NULL) { $group_references[$parent_name]['#weight'] = $element['#fieldgroups'][$parent_name]->weight; } - // The child has been copied to its parent: remove it from the root element. + // The child has been copied to parent: remove it from the root element. unset($element[$child_name]); } @@ -734,10 +752,13 @@ function field_group_fields_nest(&$element, &$vars = NULL, $context = NULL) { * Ror entity display elements managed by field layout. * * @param array $element - * @param $vars - * @param $context + * The part of the form. + * @param array $vars + * Rendering vars from the entity being viewed. + * @param string $context + * The display context (entity type, form or view). */ -function field_group_field_layout_fields_nest(array &$element, &$vars = NULL, $context = NULL) { +function field_group_field_layout_fields_nest(array &$element, array &$vars = NULL, $context = NULL) { // Create all groups and keep a flat list of references to these groups. $group_references = []; foreach ($element['#fieldgroups'] as $group_name => $group) { @@ -775,7 +796,7 @@ function field_group_field_layout_fields_nest(array &$element, &$vars = NULL, $c $key = field_group_get_content_element_key($context); if (!isset($element['#fieldgroups'][$child_name]) && isset($vars[$key]['_field_layout'][$region][$child_name])) { - // ECK marks his default properties as printed, while it is not printed yet. + // ECK marks default properties as printed, while not printed yet. if ($context === 'eck_entity' && !empty($vars[$key]['_field_layout'][$region][$child_name]['#printed'])) { $vars[$key]['_field_layout'][$region][$child_name]['#printed'] = FALSE; } @@ -801,16 +822,16 @@ function field_group_field_layout_fields_nest(array &$element, &$vars = NULL, $c /** * Function to pre render the field group element. * - * @see field_group_fields_nest() - * - * @param $element + * @param array $element * Render array of group element that needs to be created. - * @param $group + * @param object $group * Object with the group information. - * @param $rendering_object - * The entity / form beïng rendered. + * @param object $rendering_object + * The entity / form being rendered. + * + * @see field_group_fields_nest() */ -function field_group_pre_render(& $element, $group, & $rendering_object) { +function field_group_pre_render(array &$element, $group, &$rendering_object) { // Only run the pre_render function if the group has elements. // $group->group_name. @@ -839,10 +860,11 @@ function field_group_pre_render(& $element, $group, & $rendering_object) { * This allows entity modules to specify their content element for field group * support, or other modules to add entity module support. * - * @param $context + * @param string $context * The display context (entity type, form or view). * * @return string + * Content element key. */ function field_group_get_content_element_key($context = 'default') { $keys = &drupal_static('field_group_content_elements'); @@ -864,7 +886,7 @@ function field_group_get_content_element_key($context = 'default') { /** * Saves a group definition. * - * @param \stdClass $group + * @param object $group * A group definition. * @param \Drupal\Core\Entity\Display\EntityDisplayInterface $display * The display to update if known. @@ -874,7 +896,7 @@ function field_group_get_content_element_key($context = 'default') { * * @throws \Drupal\Core\Entity\EntityStorageException */ -function field_group_group_save($group, $display = NULL) { +function field_group_group_save($group, EntityDisplayInterface $display = NULL) { if ($display === NULL) { if ($group->context == 'form') { $display = EntityFormDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode); @@ -919,7 +941,7 @@ function field_group_group_save($group, $display = NULL) { /** * Delete a field group. * - * @param $group + * @param object $group * A group definition. * * @throws \Drupal\Core\Entity\EntityStorageException @@ -933,7 +955,7 @@ function field_group_delete_field_group($group) { } /** - * @var $display \Drupal\Core\Entity\Display\EntityDisplayInterface + * @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */ if (isset($display)) { $display->unsetThirdPartySetting('field_group', $group->group_name); @@ -946,16 +968,17 @@ function field_group_delete_field_group($group) { /** * Get all groups. * - * @param $entity_type + * @param string $entity_type * The name of the entity. - * @param $bundle + * @param string $bundle * The name of the bundle. - * @param $context + * @param string $context * The context of the view mode (form or view) - * @param $mode + * @param string $mode * The view mode. * * @return array + * Info array. */ function field_group_info_groups($entity_type, $bundle, $context, $mode) { if ($context == 'form') { @@ -991,18 +1014,19 @@ function field_group_info_groups($entity_type, $bundle, $context, $mode) { /** * Loads a group definition. * - * @param $group_name + * @param string $group_name * The name of the group. - * @param $entity_type + * @param string $entity_type * The name of the entity. - * @param $bundle + * @param string $bundle * The name of the bundle. - * @param $context + * @param string $context * The context of the view mode (form or view) - * @param $mode + * @param string $mode * The view mode to load. * * @return mixed + * Field group. */ function field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode) { $groups = field_group_info_groups($entity_type, $bundle, $context, $mode); @@ -1020,12 +1044,13 @@ function field_group_load_field_group($group_name, $entity_type, $bundle, $conte * The name of the entity. * @param string $bundle * The bundle for the entity. - * @param $context + * @param string $context * The context of the view mode (form or view) * @param string $mode * The view mode context the group will be rendered. * * @return bool + * TRUE if group exists. */ function field_group_exists($group_name, $entity_type, $bundle, $context, $mode) { return (bool) field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode); @@ -1041,7 +1066,7 @@ function field_group_exists($group_name, $entity_type, $bundle, $context, $mode) * @param string $entity_type * The entity type. */ -function field_group_remove_empty_form_groups(&$element, $groups, $entity_type) { +function field_group_remove_empty_form_groups(array &$element, array $groups, $entity_type) { $exceptions = ['user__account', 'comment__author']; $children = Element::getVisibleChildren($element); @@ -1071,6 +1096,22 @@ function field_group_remove_empty_form_groups(&$element, $groups, $entity_type) foreach (array_keys($empty_groups) as $group_name) { $element[$group_name]['#access'] = FALSE; } + + // Check access on translations. + $route_name = \Drupal::routeMatch()->getRouteName(); + $is_add_translation_route = $route_name === 'entity.node.content_translation_add'; + if ($is_add_translation_route) { + foreach ($groups as $group_name) { + if ($element[$group_name]['#type'] == 'details' && isset($element[$group_name]['#group'])) { + if (isset($element['advanced']) && isset($element['advanced']['#access']) && !$element['advanced']['#access']) { + $element['advanced']['#access'] = TRUE; + // Show meta element as well. + $element['meta']['#access'] = TRUE; + } + } + } + } + } /** @@ -1082,8 +1123,9 @@ function field_group_remove_empty_form_groups(&$element, $groups, $entity_type) * Array of group objects. * * @return bool + * TRUE if group is empty. */ -function field_group_remove_empty_display_groups(& $element, $groups) { +function field_group_remove_empty_display_groups(array &$element, array $groups) { $empty_child = TRUE; $empty_group = TRUE; diff --git a/web/modules/field_group/formatters/accordion/accordion.js b/web/modules/field_group/formatters/accordion/accordion.js index a114af701e10eb3d2a92bc194ec9c929e00f1187..9551a0c00f6661cff73eae574367fbc3d468c12d 100644 --- a/web/modules/field_group/formatters/accordion/accordion.js +++ b/web/modules/field_group/formatters/accordion/accordion.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides the processing logic for accordion. + */ + (function ($) { 'use strict'; @@ -39,7 +44,7 @@ var $firstErrorItem = false; - // Add required fields mark to any element containing required fields + // Add required fields mark to any element containing required fields. wrapper.find('div.field-group-accordion-item').each(function (i) { var $this = $(this); diff --git a/web/modules/field_group/formatters/details/details.js b/web/modules/field_group/formatters/details/details.js index c3d87b8b531fbb7a562968476c805d0e53a83f76..5df3f511b4af1251dabcda431e337efead1e12bd 100644 --- a/web/modules/field_group/formatters/details/details.js +++ b/web/modules/field_group/formatters/details/details.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides the processing logic for details element. + */ + (function ($) { 'use strict'; diff --git a/web/modules/field_group/formatters/fieldset/fieldset.js b/web/modules/field_group/formatters/fieldset/fieldset.js index f52e9dd534f5decbcb147acfd21d755939e7c179..b0f0085715e2d7e5d2344c9124dfad9120b3d011 100644 --- a/web/modules/field_group/formatters/fieldset/fieldset.js +++ b/web/modules/field_group/formatters/fieldset/fieldset.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides the processing logic for fieldsets. + */ + (function ($) { 'use strict'; @@ -8,7 +13,7 @@ /** * This script adds the required and error classes to the fieldset wrapper. */ - Drupal.behaviors.fieldGroupDFieldset = { + Drupal.behaviors.fieldGroupFieldset = { attach: function (context) { $(context).find('.field-group-fieldset').once('field-group-fieldset').each(function () { diff --git a/web/modules/field_group/formatters/html_element/html-element.js b/web/modules/field_group/formatters/html_element/html-element.js index d1f1922a92874794f44f0f07c44bad8f185f460a..9dd89462c4e4a2a0f4362e890fb3287caa066a27 100644 --- a/web/modules/field_group/formatters/html_element/html-element.js +++ b/web/modules/field_group/formatters/html_element/html-element.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides the processing logic for html elements. + */ + (function ($) { 'use strict'; @@ -19,7 +24,7 @@ } else { - // Add required field markers if needed + // Add required field markers if needed. if (group_info.settings.show_label && $wrapper.is('.required-fields') && ($wrapper.find('[required]').length > 0 || $wrapper.find('.form-required').length > 0)) { $wrapper.find(group_info.settings.label_element + ':first').addClass('form-required'); } @@ -27,7 +32,7 @@ }); }, - renderCollapsible: function($wrapper) { + renderCollapsible: function ($wrapper) { // Turn the legend into a clickable link, but retain span.field-group-format-toggler // for CSS positioning. @@ -35,7 +40,7 @@ var $link = $('<a class="field-group-title" href="#"></a>'); $link.prepend($toggler.contents()); - // Add required field markers if needed + // Add required field markers if needed. if ($wrapper.is('.required-fields') && ($wrapper.find('[required]').length > 0 || $wrapper.find('.form-required').length > 0)) { $link.addClass('form-required'); } diff --git a/web/modules/field_group/formatters/tabs/horizontal-tabs.css b/web/modules/field_group/formatters/tabs/horizontal-tabs.css index 5aa784f928ecebbf95dff5396f54e46767bf871e..fe320e7d55cb650b50411a812d6b9855b574995f 100644 --- a/web/modules/field_group/formatters/tabs/horizontal-tabs.css +++ b/web/modules/field_group/formatters/tabs/horizontal-tabs.css @@ -39,7 +39,7 @@ } /* Layout of each tab */ -.horizontal-tabs .horizontal-tab-button { +.horizontal-tabs .horizontal-tab-button { background: #eee; border-right: 1px solid #ccc; /* LTR */ padding-top: 0; @@ -121,4 +121,3 @@ div.field-group-htabs-wrapper .field-group-format-wrapper { clear: both; padding: 0 0 0.6em; } - diff --git a/web/modules/field_group/formatters/tabs/horizontal-tabs.js b/web/modules/field_group/formatters/tabs/horizontal-tabs.js index 4ed238d795b00d2cd3ffb5bfbd27a347df22c339..083a55ac03fdda130d018b97ee59516d00aa5406 100644 --- a/web/modules/field_group/formatters/tabs/horizontal-tabs.js +++ b/web/modules/field_group/formatters/tabs/horizontal-tabs.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides horizontal tabs logic. + */ + (function ($, Drupal) { 'use strict'; @@ -6,9 +11,7 @@ Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {}; /** - * This script transforms a set of fieldsets into a stack of horizontal - * tabs. Another tab pane can be selected by clicking on the respective - * tab. + * Transforms a set of fieldsets into a stack of horizontal tabs. * * Each tab may have a summary which can be updated by another * script. For that to work, each fieldset has an associated @@ -26,14 +29,14 @@ return; } - $(context).find('[data-horizontal-tabs]').once('horizontal-tabs').each(function() { + $(context).find('[data-horizontal-tabs]').once('horizontal-tabs').each(function () { var horizontal_tabs_clearfix = this; $(this).find('> [data-horizontal-tabs-panes]').each(function () { var $this = $(this).addClass('horizontal-tabs-panes'); var focusID = $(':hidden.horizontal-tabs-active-tab', this).val(); var tab_focus; - // Check if there are some details that can be converted to horizontal-tabs + // Check if there are some details that can be converted to horizontal-tabs. var $details = $this.find('> details'); if ($details.length === 0) { return; @@ -231,6 +234,7 @@ * @param {object} settings * An object with the following keys: * - title: The name of the tab. + * * @return {object} * This function has to return an object with at least these keys: * - item: The root tab jQuery element diff --git a/web/modules/field_group/formatters/tabs/tabs.js b/web/modules/field_group/formatters/tabs/tabs.js index 9e1bdb4003f740ea26f1a98434599e12c6ac2302..50fb8ad7bb0baf433139d50928efb3b0327c2166 100644 --- a/web/modules/field_group/formatters/tabs/tabs.js +++ b/web/modules/field_group/formatters/tabs/tabs.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides the processing logic for tabs. + */ + (function ($) { 'use strict'; @@ -13,7 +18,7 @@ if (group_info.context === 'form') { - // Add required fields mark to any element containing required fields + // Add required fields mark to any element containing required fields. var direction = group_info.settings.direction; $(context).find('[data-' + direction + '-tabs-panes]').each(function () { var errorFocussed = false; diff --git a/web/modules/field_group/includes/field_ui.inc b/web/modules/field_group/includes/field_ui.inc index 8aefeb677e4805e3e9f9959a6d33583f775aa798..d6ee0e8427687aa7a83a22315f144fa6d89e811f 100644 --- a/web/modules/field_group/includes/field_ui.inc +++ b/web/modules/field_group/includes/field_ui.inc @@ -2,32 +2,34 @@ /** * @file - * Field_group.field_ui.inc is a file that contains most functions - * needed on the Fields UI Manage forms (display and fields). + * Fields UI Manage forms functions (display and fields). */ -use Drupal\field_group\FieldgroupUi; -use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\Display\EntityFormDisplayInterface; +use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityDisplayBase; -use Drupal\Component\Utility\Html; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; use Drupal\Core\Render\Element; +use Drupal\field_group\FieldgroupUi; use Drupal\field_group\FormatterHelper; use Drupal\field_ui\Form\EntityDisplayFormBase; /** + * Getting form parameters. + * * Helper function to get the form parameters to use while * building the fields and display overview form. * - * @param $form - * + * @param array $form + * Form. * @param \Drupal\Core\Entity\EntityDisplayBase $display + * Display object. * - * @return \stdClass + * @return object + * Form parameters. */ -function field_group_field_ui_form_params($form, EntityDisplayBase $display) { +function field_group_field_ui_form_params(array $form, EntityDisplayBase $display) { $params = new stdClass(); $params->entity_type = $display->getTargetEntityTypeId(); @@ -43,8 +45,8 @@ function field_group_field_ui_form_params($form, EntityDisplayBase $display) { foreach ($params->groups as $name => $group) { if (!empty($group->children)) { foreach ($group->children as $child) { - // Field UI js sometimes can trigger an endless loop. Check if the parent - // of this field is not a child. + // Field UI js sometimes can trigger an endless loop. Check if the + // parent of this field is not a child. if ($child !== $group->parent_name) { $params->parents[$child] = $name; } @@ -53,7 +55,7 @@ function field_group_field_ui_form_params($form, EntityDisplayBase $display) { } // Get possible regions. - // TODO remove the field layout part when it's remove from in core. + // @todo Remove the field layout part when it's remove from in core. // see https://www.drupal.org/project/field_group/issues/3086019 $ds_info = $display->getThirdPartySettings('ds'); $field_layout_info = $display->getThirdPartySettings('field_layout'); @@ -82,8 +84,10 @@ function field_group_field_ui_form_params($form, EntityDisplayBase $display) { * Helper function to get context from entity display. * * @param \Drupal\Core\Entity\EntityDisplayBase $display + * Display. * * @return string + * Context. */ function field_group_get_context_from_display(EntityDisplayBase $display) { if ($display instanceof EntityFormDisplayInterface) { @@ -150,7 +154,7 @@ function field_group_field_ui_display_form_alter(&$form, FormStateInterface $for // Check the currently selected formatter, and merge persisted values for // formatter settings for the group. - // This needs to be done first, so all fields are updated before creating form elements. + // Firstly updating all fields before creating form elements. if (isset($refresh_rows) && $refresh_rows == $name) { $settings = isset($form_state_values['fields'][$name]) ? $form_state_values['fields'][$name] : (isset($form_state->getUserInput()['fields'][$name]) ? $form_state->getUserInput()['fields'][$name] : NULL); if (array_key_exists('settings_edit', $settings)) { @@ -212,7 +216,7 @@ function field_group_field_ui_display_form_alter(&$form, FormStateInterface $for ], ]; - // For view settings. Add a spacer cell. We can't use colspan because of the javascript . + // For view settings. Add a spacer cell. Can't use colspan because of JS. if ($params->context == 'view') { $table[$name] += [ 'spacer' => [ @@ -237,7 +241,10 @@ function field_group_field_ui_display_form_alter(&$form, FormStateInterface $for [$form_state->getBuildInfo()['callback_object'], 'multistepSubmit'], ], '#ajax' => [ - 'callback' => [$form_state->getBuildInfo()['callback_object'], 'multistepAjax'], + 'callback' => [ + $form_state->getBuildInfo()['callback_object'], + 'multistepAjax', + ], 'wrapper' => 'field-display-overview-wrapper', 'effect' => 'fade', ], @@ -289,10 +296,13 @@ function field_group_field_ui_display_form_alter(&$form, FormStateInterface $for '#type' => 'image_button', '#name' => $name . '_group_settings_edit', '#src' => 'core/misc/icons/787878/cog.svg', - '#attributes' => ['class' => ['field-plugin-settings-edit'], 'alt' => t('Edit')], + '#attributes' => [ + 'class' => ['field-plugin-settings-edit'], + 'alt' => t('Edit'), + ], '#op' => 'edit', - // Do not check errors for the 'Edit' button, but make sure we get - // the value of the 'plugin type' select. + // Do not check errors for the 'Edit' button, but make sure we get + // the value of the 'plugin type' select. '#limit_validation_errors' => [['fields', $name, 'type']], '#prefix' => '<div class="field-plugin-settings-edit-wrapper">', '#suffix' => '</div>', @@ -339,7 +349,7 @@ function field_group_field_ui_display_form_alter(&$form, FormStateInterface $for $group_check = field_group_load_field_group($group_name, $params->entity_type, $params->bundle, $params->context, $params->mode); if (isset($parent_requirements[$group_check->format_type])) { if (!$group_check->parent_name || field_group_load_field_group($group_check->parent_name, $params->entity_type, $params->bundle, $params->context, $params->mode)->format_type != $parent_requirements[$group_check->format_type]['parent']) { - \Drupal::messenger()->addMessage(t($parent_requirements[$group_check->format_type]['message']), 'warning', FALSE); + \Drupal::messenger()->addMessage($parent_requirements[$group_check->format_type]['message'], 'warning', FALSE); } } } @@ -410,9 +420,10 @@ function field_group_field_ui_create_vertical_tabs(&$form, &$form_state, $params * @param array $row * A field or field_group row. * - * @return String the current region. + * @return string + * The current region. */ -function field_group_display_overview_row_region($row) { +function field_group_display_overview_row_region(array $row) { // We already cleaned region when building the form. return $row['region']['#value']; } @@ -425,7 +436,7 @@ function field_group_display_overview_row_region($row) { * @param \Drupal\Core\Form\FormStateInterface $form_state * The state of the form. */ -function field_group_field_overview_submit($form, FormStateInterface $form_state) { +function field_group_field_overview_submit(array $form, FormStateInterface $form_state) { $form_values = $form_state->getValue('fields'); /** @@ -473,7 +484,8 @@ function field_group_field_overview_submit($form, FormStateInterface $form_state $group->parent_name = $form_values[$group_name]['parent']; $group->weight = $form_values[$group_name]['weight']; - // If region is changed, make sure the group ends up in an existing region. + // If region is changed, make sure the group ends up in an existing + // region. $group->region = !in_array($form_values[$group_name]['region'], $layout_regions) ? $default_region : $form_values[$group_name]['region']; $old_format_type = $group->format_type; @@ -482,7 +494,8 @@ function field_group_field_overview_submit($form, FormStateInterface $form_state $group->format_settings = $field_group_form_state[$group_name]->format_settings; } - // If the format type is changed, make sure we have all required format settings. + // If the format type is changed, make sure we have all required format + // settings. if ($group->format_type != $old_format_type) { $group->format_settings += $manager->getDefaultSettings($group->format_type, $context); } @@ -503,10 +516,14 @@ function field_group_field_overview_submit($form, FormStateInterface $form_state /** * Creates a form for field_group formatters. * - * @param Object $group + * @param object $group * The FieldGroup object. + * @param array $form + * Nested array of form elements that comprise the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The state of the form. */ -function field_group_format_settings_form(&$group, $form, $form_state) { +function field_group_format_settings_form(&$group, array $form, FormStateInterface $form_state) { $manager = \Drupal::service('plugin.manager.field_group.formatters'); $plugin = $manager->getInstance([ 'format_type' => $group->format_type, @@ -525,13 +542,17 @@ function field_group_format_settings_form(&$group, $form, $form_state) { } /** + * Update callback. + * * Update the row so that the group variables are updated. * The rendering of the elements needs the updated defaults. * - * @param Object $group + * @param object $group + * The group object. * @param array $settings + * Configuration settings. */ -function field_group_formatter_row_update(& $group, $settings) { +function field_group_formatter_row_update(&$group, array $settings) { // If the row has changed formatter type, update the group object. if (!empty($settings['format']['type']) && $settings['format']['type'] != $group->format_type) { $group->format_type = $settings['format']['type']; @@ -542,12 +563,12 @@ function field_group_formatter_row_update(& $group, $settings) { /** * Update handler for field_group configuration settings. * - * @param Object $group + * @param object $group * The group object. * @param array $settings * Configuration settings. */ -function field_group_formatter_settings_update(& $group, $settings) { +function field_group_formatter_settings_update(&$group, array $settings) { // For format changes we load the defaults. if (empty($settings['settings_edit_form']['settings'])) { @@ -565,10 +586,11 @@ function field_group_formatter_settings_update(& $group, $settings) { * * @param string $group_name * The name of the group. - * @param Object $group + * @param object $group * The group object. * - * @return Array ready to be rendered. + * @return array + * Render array. */ function field_group_format_settings_summary($group_name, $group) { @@ -596,14 +618,17 @@ function field_group_format_settings_summary($group_name, $group) { } /** - * Validate handler to validate saving existing fieldgroups from one view mode or form to another. + * Validate handler. + * + * Validate when saving existing fieldgroups from one view mode or form to + * another. */ function field_group_field_ui_clone_field_groups_validate($form, FormStateInterface $form_state) { $form_state_values = $form_state->getValues(); $field_group_params = $form_state->get('field_group_params'); - list($context, $mode) = explode('.', $form_state_values['fieldgroup_clone']); + [$context, $mode] = explode('.', $form_state_values['fieldgroup_clone']); $source_groups = field_group_info_groups($field_group_params->entity_type, $field_group_params->bundle, $context, $mode); // Check for types are not known in current mode. @@ -632,7 +657,9 @@ function field_group_field_ui_clone_field_groups_validate($form, FormStateInterf } /** - * Submit handler to save existing fieldgroups from one view mode or form to another. + * Submit handler. + * + * Saving existing fieldgroups from one view mode or form to another. */ function field_group_field_ui_clone_field_groups($form, FormStateInterface $form_state) { diff --git a/web/modules/field_group/js/field_group.field_ui.js b/web/modules/field_group/js/field_group.field_ui.js index 7aba6df1c62dccbb46ee78be1e79bb3f15cb9a1f..d02626751e794b997718917a44b53fdd4589e37a 100644 --- a/web/modules/field_group/js/field_group.field_ui.js +++ b/web/modules/field_group/js/field_group.field_ui.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides the fieldgroup behaviors for field UI. + */ + (function ($) { 'use strict'; @@ -55,7 +60,6 @@ } }; - /** * Row handlers for the 'Manage display' screen. */ diff --git a/web/modules/field_group/js/field_group.js b/web/modules/field_group/js/field_group.js index 8933dc65eb2d9badb81ab950c83a61734b7c7d1c..c8ff69edd28abc88faf80d123ac15f670c243030 100644 --- a/web/modules/field_group/js/field_group.js +++ b/web/modules/field_group/js/field_group.js @@ -1,3 +1,8 @@ +/** + * @file + * Provides the core logic for fieldgroup. + */ + (function ($) { 'use strict'; diff --git a/web/modules/field_group/src/Annotation/FieldGroupFormatter.php b/web/modules/field_group/src/Annotation/FieldGroupFormatter.php index d7acb983dd38f4ed679399504f1c6106da465919..c157e5612db7c1e39504723883bfd05daffea1ae 100644 --- a/web/modules/field_group/src/Annotation/FieldGroupFormatter.php +++ b/web/modules/field_group/src/Annotation/FieldGroupFormatter.php @@ -61,6 +61,8 @@ class FieldGroupFormatter extends Plugin { public $format_types = []; /** + * Formatter weight. + * * An integer to determine the weight of this formatter relative to other * formatter in the Field UI when selecting a formatter for a given group. * diff --git a/web/modules/field_group/src/Element/HorizontalTabs.php b/web/modules/field_group/src/Element/HorizontalTabs.php index e3c642d8d14200f0b9cbb7e64e8a829395732810..ee8567bb1aa867ebb06943f911b6f0d7573dbded 100644 --- a/web/modules/field_group/src/Element/HorizontalTabs.php +++ b/web/modules/field_group/src/Element/HorizontalTabs.php @@ -65,8 +65,8 @@ public static function preRenderGroup($element) { elseif (!empty($element['#group_details'])) { // Intentionally empty to clarify the flow; we simply return $element. } - // Otherwise, this element belongs to a group and the group exists, so we do - // not render it. + // Otherwise, this element belongs to a group and the group exists, so we + // do not render it. elseif (Element::children($element['#groups'][$group])) { $element['#printed'] = TRUE; } diff --git a/web/modules/field_group/src/Element/HtmlElement.php b/web/modules/field_group/src/Element/HtmlElement.php index cdb78c5bff1701f2ec817bb144be08869e28e23a..e32e1dd27ce8a3a0c7decf63c7c08b51ca1a3d41 100644 --- a/web/modules/field_group/src/Element/HtmlElement.php +++ b/web/modules/field_group/src/Element/HtmlElement.php @@ -4,6 +4,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element\RenderElement; +use Drupal\Core\Template\Attribute; /** * Provides a render element for a html element. @@ -51,11 +52,19 @@ public static function processHtmlElement(array &$element, FormStateInterface $f $element['#attached']['library'][] = 'field_group/core'; // Add the required classes for the js. - $element['#attributes']['class'][] = 'field-group-html-element'; - $element['#attributes']['class'][] = 'fieldgroup-collapsible'; - $element['#attributes']['class'][] = 'effect-' . $element['#effect']; + $classes = [ + 'field-group-html-element', + 'fieldgroup-collapsible', + 'effect-' . $element['#effect'], + ]; if (!empty($element['#speed'])) { - $element['#attributes']['class'][] = 'speed-' . $element['#speed']; + $classes[] = 'speed-' . $element['#speed']; + } + if ($element['#attributes'] instanceof Attribute) { + $element['#attributes']->addClass($classes); + } + else { + $element['#attributes']['classes'] = array_merge($element['#attributes']['classes'], $classes); } // Add jquery ui effects library for the blind effect. diff --git a/web/modules/field_group/src/Element/VerticalTabs.php b/web/modules/field_group/src/Element/VerticalTabs.php index c8a212d209fe22fc551be21ec8ca2a984d8707e3..ff075f329fc32ef5f74995823006aa85f95e81d7 100644 --- a/web/modules/field_group/src/Element/VerticalTabs.php +++ b/web/modules/field_group/src/Element/VerticalTabs.php @@ -21,7 +21,7 @@ class VerticalTabs implements RenderCallbackInterface { * @return array * The modified element with all group members. */ - public static function preRenderGroup($element) { + public static function preRenderGroup(array $element) { // The element may be rendered outside of a Form API context. if (!isset($element['#parents']) || !isset($element['#groups'])) { return $element; @@ -41,8 +41,8 @@ public static function preRenderGroup($element) { elseif (!empty($element['#group_details'])) { // Intentionally empty to clarify the flow; we simply return $element. } - // Otherwise, this element belongs to a group and the group exists, so we do - // not render it. + // Otherwise, this element belongs to a group and the group exists, + // so we do not render it. elseif (Element::children($element['#groups'][$group])) { $element['#printed'] = TRUE; } @@ -81,7 +81,7 @@ public static function preRenderGroup($element) { * @return array * The processed element. */ - public static function processGroup(&$element, FormStateInterface $form_state, &$complete_form) { + public static function processGroup(array &$element, FormStateInterface $form_state, array &$complete_form) { $groups = &$form_state->getGroups(); $element['#groups'] = &$groups; diff --git a/web/modules/field_group/src/FieldGroupFormatterBase.php b/web/modules/field_group/src/FieldGroupFormatterBase.php index 0c56d8e3958cd599711b12076371896d44753aab..a3b584039e14e89fa9d6dd04810e4aec7cf032be 100644 --- a/web/modules/field_group/src/FieldGroupFormatterBase.php +++ b/web/modules/field_group/src/FieldGroupFormatterBase.php @@ -54,7 +54,7 @@ abstract class FieldGroupFormatterBase extends PluginSettingsBase implements Fie * The plugin_id for the formatter. * @param mixed $plugin_definition * The plugin implementation definition. - * @param \stdClass $group + * @param object $group * The group object. * @param array $settings * The formatter settings. diff --git a/web/modules/field_group/src/FieldGroupFormatterInterface.php b/web/modules/field_group/src/FieldGroupFormatterInterface.php index fc9dc82c48aa6ab795d32d58ee3dabea5e8849f1..ed1a514ee37eba883d82550a2d326184472b5334 100644 --- a/web/modules/field_group/src/FieldGroupFormatterInterface.php +++ b/web/modules/field_group/src/FieldGroupFormatterInterface.php @@ -12,33 +12,40 @@ interface FieldGroupFormatterInterface extends PluginInspectionInterface { /** - * Allows the field group formatter to manipulate the field group array and attach the formatters elements. - * The process method is called in the #process part of theme layer, and is currently used for forms. - * The preRender method is called in the #pre_render part of the theme layer, and is currently used for entity displays. + * Field formatter process function. + * + * Allows the field group formatter to manipulate the field group array and + * attach the formatters elements. The process method is called in the + * #process part of theme layer, and is currently used for forms. The + * preRender method is called in the #pre_render part of the theme layer, + * and is currently used for entity displays. * * @param array $element * The field group render array. * @param object $processed_object * The object / entity beïng processed. */ - public function process(&$element, $processed_object); + public function process(array &$element, $processed_object); /** - * Allows the field group formatter to manipulate the field group array and attach the formatters rendering element. + * Field formatter prerender function. + * + * Allows the field group formatter to manipulate the field group array and + * attach the formatters rendering element. * * @param array $element * The field group render array. * @param object $rendering_object * The object / entity beïng rendered. */ - public function preRender(&$element, $rendering_object); + public function preRender(array &$element, $rendering_object); /** * Returns a form to configure settings for the formatter. * * Invoked in field_group_field_ui_display_form_alter to allow - * administrators to configure the formatter. The field_group module takes care - * of handling submitted form values. + * administrators to configure the formatter. The field_group module takes + * care of handling submitted form values. * * @return array * The form elements for the formatter settings. diff --git a/web/modules/field_group/src/FieldGroupFormatterPluginManager.php b/web/modules/field_group/src/FieldGroupFormatterPluginManager.php index f93afbe1683893f3319ee1a0c440e188e4b760d6..26a690c396fe654b6b3c75e6610b5840a07af541 100644 --- a/web/modules/field_group/src/FieldGroupFormatterPluginManager.php +++ b/web/modules/field_group/src/FieldGroupFormatterPluginManager.php @@ -100,6 +100,7 @@ public function getInstance(array $options) { * The context to prepare configuration for. * @param array $configuration * The configuration of the group. + * * @return array * The display properties with defaults added. */ diff --git a/web/modules/field_group/src/FieldgroupUi.php b/web/modules/field_group/src/FieldgroupUi.php index 1c0c98c54444c23e76cec8de89e91d95ae55dab9..2ee67b2ce4123b6d35e0b5e53dab3395b7e698f1 100644 --- a/web/modules/field_group/src/FieldgroupUi.php +++ b/web/modules/field_group/src/FieldgroupUi.php @@ -55,7 +55,7 @@ public static function getFieldUiRoute($group) { /** * Get the field group delete route for a given group. * - * @param \stdClass $group + * @param object $group * The group to delete. * * @return \Drupal\Core\Url diff --git a/web/modules/field_group/src/Form/FieldGroupDeleteForm.php b/web/modules/field_group/src/Form/FieldGroupDeleteForm.php index b4556d553d77e5dfe29dc612ce4e0eb8bb3d9880..ca6a36695e2db1fe9b0479535a15495629f8a9a4 100644 --- a/web/modules/field_group/src/Form/FieldGroupDeleteForm.php +++ b/web/modules/field_group/src/Form/FieldGroupDeleteForm.php @@ -2,11 +2,11 @@ namespace Drupal\field_group\Form; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\field_group\FieldgroupUi; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -95,7 +95,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) { field_group_delete_field_group($this->fieldGroup); - $this->messenger->addMessage($this->t('The group %group has been deleted from the %type content type.', ['%group' => $this->fieldGroup->label, '%type' => $bundle_label])); + $this->messenger->addMessage($this->t('The group %group has been deleted from the %type content type.', [ + '%group' => $this->fieldGroup->label, + '%type' => $bundle_label, + ])); // Redirect. $form_state->setRedirectUrl($this->getCancelUrl()); diff --git a/web/modules/field_group/src/FormatterHelper.php b/web/modules/field_group/src/FormatterHelper.php index 4b840721582a7ea003725c0eb3a9fe97743f5d7b..469b4a6bce6549bb42e587b1a5c0aa783b69d4df 100644 --- a/web/modules/field_group/src/FormatterHelper.php +++ b/web/modules/field_group/src/FormatterHelper.php @@ -4,6 +4,7 @@ use Drupal; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Element; use Drupal\Core\Security\TrustedCallbackInterface; /** @@ -40,6 +41,7 @@ public static function formatterOptions($type) { * Entity being rendered. * * @return array + * The update entity view. */ public static function entityViewPrender(array $element) { field_group_build_entity_groups($element, 'view'); @@ -57,6 +59,7 @@ public static function entityViewPrender(array $element) { * The complete form structure. * * @return array + * The updated form. */ public static function formProcess(array &$element, FormStateInterface $form_state = NULL, array &$form = []) { if (empty($element['#field_group_form_process'])) { @@ -73,11 +76,19 @@ public static function formProcess(array &$element, FormStateInterface $form_sta } $group_parents = $element['#array_parents']; - $group_parents[] = empty($group->parent_name) ? $group->region : $group->parent_name; + if (empty($group->parent_name)) { + if (isset($group->region)) { + $group_parents[] = $group->region; + } + } + else { + $group_parents[] = $group->parent_name; + } $group_references[$group_name] = &$element[$group_name]; $element[$group_name]['#group'] = implode('][', $group_parents); - // Use array parents to set the group name. This will cover multilevel forms (eg paragraphs). + // Use array parents to set the group name. + // This will cover multilevel forms (eg paragraphs). $parents = $element['#array_parents']; $parents[] = $group_name; $element[$group_name]['#parents'] = $parents; @@ -114,13 +125,65 @@ public static function formProcess(array &$element, FormStateInterface $form_sta return $element; } + /** + * Pre render callback for rendering groups in forms. + * + * @param array $element + * Form that is being rendered. + * + * @return array + * The updated group. + */ + public static function formGroupPreRender(array $element) { + // Open any closed field groups that contain elements with errors. + if (!empty($element['#fieldgroups'])) { + foreach ($element['#fieldgroups'] as $fieldgroup) { + $closed = isset($element[$fieldgroup->group_name]['#open']) && !$element[$fieldgroup->group_name]['#open']; + if ($closed) { + foreach ($fieldgroup->children as $child) { + if (static::groupElementsContainErrors($element[$child])) { + $element[$fieldgroup->group_name]['#open'] = TRUE; + break; + } + } + } + } + } + + return $element; + } + + /** + * Determines if an elements array contains validation errors. + * + * @param array $elements + * The elements array to check for errors. + * + * @return bool + * TRUE if the elements array contains validation errors, otherwise FALSE. + */ + protected static function groupElementsContainErrors(array $elements) { + // Any errors at this level of the elements array? + if (!empty($elements['#errors']) || !empty($elements['#children_errors'])) { + return TRUE; + } + + // Dive down. + foreach (Element::children($elements) as $child) { + if (static::groupElementsContainErrors($elements[$child])) { + return TRUE; + } + } + + // No errors. + return FALSE; + } /** * {@inheritdoc} */ public static function trustedCallbacks() { - return ['entityViewPrender', 'formProcess']; + return ['entityViewPrender', 'formProcess', 'formGroupPreRender']; } - } diff --git a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Accordion.php b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Accordion.php index 75444dfd71799fc73f5c40416c94520679fc27c3..0379e8e06213fae8807f5b15e83cf8f6e58aa0a3 100644 --- a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Accordion.php +++ b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Accordion.php @@ -2,9 +2,9 @@ namespace Drupal\field_group\Plugin\field_group\FieldGroupFormatter; -use Drupal\field_group\Element\Accordion as AccordionElement; use Drupal\Component\Utility\Html; use Drupal\Core\Form\FormState; +use Drupal\field_group\Element\Accordion as AccordionElement; use Drupal\field_group\FieldGroupFormatterBase; /** @@ -66,7 +66,10 @@ public function settingsForm() { $form['effect'] = [ '#title' => $this->t('Effect'), '#type' => 'select', - '#options' => ['none' => $this->t('None'), 'bounceslide' => $this->t('Bounce slide')], + '#options' => [ + 'none' => $this->t('None'), + 'bounceslide' => $this->t('Bounce slide'), + ], '#default_value' => $this->getSetting('effect'), '#weight' => 2, ]; diff --git a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/AccordionItem.php b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/AccordionItem.php index d163f85e0e4784be632eb93dbd924e2eb4be095c..b738f432b79ce472f0c26a133787b7b5be53480e 100644 --- a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/AccordionItem.php +++ b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/AccordionItem.php @@ -55,7 +55,7 @@ public function process(&$element, $processed_object) { } if ($this->getSetting('formatter') == 'open') { - $element['#open'] = TRUE; + $element['#open'] = TRUE; } foreach ($element as $key => $value) { diff --git a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Details.php b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Details.php index 2da178a3772b2cbdcc5dbe7431b068ce6d2ff60a..079b85c0b2577d1ecf2f4d64206354164c703508 100644 --- a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Details.php +++ b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Details.php @@ -6,7 +6,7 @@ use Drupal\field_group\FieldGroupFormatterBase; /** - * Details element. + * Plugin implementation of the 'details' formatter. * * @FieldGroupFormatter( * id = "details", diff --git a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Fieldset.php b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Fieldset.php index bf2e2b7be2df34fd2009dec84bd74328b763ca54..24c917c4c51628be0aa434c001362aaca81d5bd6 100644 --- a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Fieldset.php +++ b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Fieldset.php @@ -30,6 +30,7 @@ public function process(&$element, $processed_object) { '#title' => $this->getLabel(), '#attributes' => [], '#description' => $this->getSetting('description'), + '#description_display' => 'after', // Prevent \Drupal\content_translation\ContentTranslationHandler::addTranslatabilityClue() // from adding an incorrect suffix to the field group title. '#multilingual' => TRUE, diff --git a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/HtmlElement.php b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/HtmlElement.php index e527817bb936276adcbb335dab513cd8f9d6bd42..9bdf1707bb2db2d1cdf904f29837a7868c82dc76 100644 --- a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/HtmlElement.php +++ b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/HtmlElement.php @@ -57,7 +57,8 @@ public function process(&$element, $processed_object) { if (!isset($element_attributes['class'])) { $element_attributes['class'] = []; } - // If user also entered class in the attributes textfield, force it to an array. + // If user also entered class in the attributes textfield, force it to an + // array. else { $element_attributes['class'] = [$element_attributes['class']]; } @@ -247,6 +248,7 @@ public static function defaultContextSettings($context) { 'effect' => 'none', 'speed' => 'fast', 'attributes' => '', + 'show_empty_fields' => FALSE, ] + parent::defaultSettings($context); if ($context == 'form') { diff --git a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tab.php b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tab.php index ba2c728baa24f7a4984207ed1b1279cb18cd13ef..233e4ca31e8db5f36f2e62d399fbbb65320d4ab7 100644 --- a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tab.php +++ b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tab.php @@ -115,6 +115,7 @@ public static function defaultContextSettings($context) { $defaults = [ 'formatter' => 'closed', 'description' => '', + 'show_empty_fields' => FALSE, ] + parent::defaultSettings($context); if ($context == 'form') { diff --git a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tabs.php b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tabs.php index 56553c4a9cad128d4829050fe5ccc33f09513451..a1984d3a138a2cf45cbb2b8f562845ccf30ccce4 100644 --- a/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tabs.php +++ b/web/modules/field_group/src/Plugin/field_group/FieldGroupFormatter/Tabs.php @@ -77,8 +77,10 @@ public function preRender(&$element, $rendering_object) { $element = HorizontalTabs::processHorizontalTabs($element, $form_state, $complete_form); } - // Make sure the group has 1 child. This is needed to succeed at form_pre_render_vertical_tabs(). - // Skipping this would force us to move all child groups to this array, making it an un-nestable. + // Make sure the group has 1 child. This needed to succeed at + // form_pre_render_vertical_tabs(). + // Skipping this would force us to move all child groups to this array, + // making it an un-nestable. $element['group']['#groups'][$this->group->group_name] = [0 => []]; $element['group']['#groups'][$this->group->group_name]['#group_exists'] = TRUE; @@ -134,6 +136,7 @@ public static function defaultContextSettings($context) { return [ 'direction' => 'vertical', 'width_breakpoint' => 640, + 'show_empty_fields' => FALSE, ] + parent::defaultContextSettings($context); } diff --git a/web/modules/field_group/tests/modules/field_group_test/field_group_test.info.yml b/web/modules/field_group/tests/modules/field_group_test/field_group_test.info.yml index c7f5b784d13ff5e13a67551c9f1666ec7434339e..ec32cb7cd5ffd135e7d221de24814b8451aa81aa 100644 --- a/web/modules/field_group/tests/modules/field_group_test/field_group_test.info.yml +++ b/web/modules/field_group/tests/modules/field_group_test/field_group_test.info.yml @@ -5,7 +5,7 @@ package: 'Fields' type: module hidden: TRUE -# Information added by Drupal.org packaging script on 2021-08-09 -version: '8.x-3.2' +# Information added by Drupal.org packaging script on 2022-09-18 +version: '8.x-3.3' project: 'field_group' -datestamp: 1628513588 +datestamp: 1663516405 diff --git a/web/modules/field_group/tests/src/Functional/EntityDisplayTest.php b/web/modules/field_group/tests/src/Functional/EntityDisplayTest.php index 5f0060ab37e11a6d6ba92d1371586b935a035429..df2920c6d177012e5f65da224abc8dd6dc1397e7 100644 --- a/web/modules/field_group/tests/src/Functional/EntityDisplayTest.php +++ b/web/modules/field_group/tests/src/Functional/EntityDisplayTest.php @@ -23,7 +23,7 @@ class EntityDisplayTest extends BrowserTestBase { 'field_test', 'field_ui', 'field_group', - 'field_group_test' + 'field_group_test', ]; /** @@ -64,7 +64,10 @@ public function setUp() { // Create content type, with underscores. $type_name = strtolower($this->randomMachineName(8)) . '_test'; - $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]); + $type = $this->drupalCreateContentType([ + 'name' => $type_name, + 'type' => $type_name, + ]); $this->type = $type->id(); /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */ $display = \Drupal::entityTypeManager() @@ -153,7 +156,8 @@ public function testHtmlElement() { ]; $group = $this->createGroup('node', $this->type, 'view', 'default', $data); - // $groups = field_group_info_groups('node', 'article', 'view', 'default', TRUE);. + // $groups = + // field_group_info_groups('node', 'article', 'view', 'default', TRUE);. $this->drupalGet('node/' . $this->node->id()); // Test group ids and classes. diff --git a/web/modules/field_group/tests/src/Functional/FieldGroupTestTrait.php b/web/modules/field_group/tests/src/Functional/FieldGroupTestTrait.php index a4c2d7776502bbd1503636b716ece2c9f9a7077f..cd5e9d58c144f4d16e352a9866d274833ef6992e 100644 --- a/web/modules/field_group/tests/src/Functional/FieldGroupTestTrait.php +++ b/web/modules/field_group/tests/src/Functional/FieldGroupTestTrait.php @@ -2,8 +2,6 @@ namespace Drupal\Tests\field_group\Functional; -use Drupal; - /** * Provides common functionality for the FieldGroup test classes. */ @@ -32,7 +30,7 @@ protected function createGroup($entity_type, $bundle, $context, $mode, array $da $data['format_settings'] = []; } - $data['format_settings'] += Drupal::service('plugin.manager.field_group.formatters')->getDefaultSettings($data['format_type'], $context); + $data['format_settings'] += \Drupal::service('plugin.manager.field_group.formatters')->getDefaultSettings($data['format_type'], $context); $group_name_without_prefix = isset($data['group_name']) && is_string($data['group_name']) ? preg_replace('/^group_/', '', $data['group_name']) diff --git a/web/modules/field_group/tests/src/Functional/ManageDisplayTest.php b/web/modules/field_group/tests/src/Functional/ManageDisplayTest.php index 610d3c9414b703b27f9500af066af5dbeaeb814a..bedec3633ca4cbd4fb473ccb873705892f60687c 100644 --- a/web/modules/field_group/tests/src/Functional/ManageDisplayTest.php +++ b/web/modules/field_group/tests/src/Functional/ManageDisplayTest.php @@ -49,7 +49,10 @@ public function setUp() { // Create content type, with underscores. $type_name = 'll4ma_test'; - $type = $this->drupalCreateContentType(['name' => $type_name, 'type' => $type_name]); + $type = $this->drupalCreateContentType([ + 'name' => $type_name, + 'type' => $type_name, + ]); $this->type = $type->id(); } @@ -117,7 +120,10 @@ public function testDeleteGroup() { $this->drupalGet('admin/structure/types/manage/' . $this->type . '/form-display/' . $group->group_name . '/delete'); $this->submitForm([], 'Delete'); - $this->assertSession()->responseContains(t('The group %label has been deleted from the %type content type.', ['%label' => $group->label, '%type' => $this->type])); + $this->assertSession()->responseContains(t('The group %label has been deleted from the %type content type.', [ + '%label' => $group->label, + '%type' => $this->type, + ])); // Test that group is not in the $groups array. \Drupal::entityTypeManager() @@ -135,7 +141,10 @@ public function testDeleteGroup() { $this->drupalGet('admin/structure/types/manage/' . $this->type . '/display/' . $group->group_name . '/delete'); $this->submitForm([], 'Delete'); - $this->assertSession()->responseContains(t('The group %label has been deleted from the %type content type.', ['%label' => $group->label, '%type' => $this->type])); + $this->assertSession()->responseContains(t('The group %label has been deleted from the %type content type.', [ + '%label' => $group->label, + '%type' => $this->type, + ])); // Test that group is not in the $groups array. \Drupal::entityTypeManager() diff --git a/web/modules/field_group/tests/src/FunctionalJavascript/FieldGroupUiTest.php b/web/modules/field_group/tests/src/FunctionalJavascript/FieldGroupUiTest.php index 48b9eb4efb0ebafd2a65e13d1b5bc824a54de89b..a650aeb4fe47ca88c17fe032f445e6203a2ba7c8 100644 --- a/web/modules/field_group/tests/src/FunctionalJavascript/FieldGroupUiTest.php +++ b/web/modules/field_group/tests/src/FunctionalJavascript/FieldGroupUiTest.php @@ -24,7 +24,7 @@ class FieldGroupUiTest extends WebDriverTestBase { public static $modules = ['node', 'field_ui', 'field_group']; /** - * The current tested node type + * The current tested node type. * * @var string */