commit c3fafea86e2a1944b624d0478b0d0024dabf13b5 Author: Eleo Basili Date: Wed Oct 11 19:43:11 2023 +0900 Issue #3297262 Drupal 10 manual compatibility fixes. diff --git a/form_mode_manager.info.yml b/form_mode_manager.info.yml index 572f8b5..e4c6b98 100644 --- a/form_mode_manager.info.yml +++ b/form_mode_manager.info.yml @@ -1,9 +1,8 @@ name: Form Mode Manager description: 'Provide an API to use Form modes.' type: module -core: 8.x -core_version_requirement: ^8 || ^9 package: Fields +core_version_requirement: ^8 || ^9 || ^10 configure: form_mode_manager.admin_settings dependencies: - drupal:field diff --git a/modules/examples/form_mode_manager_examples.info.yml b/modules/examples/form_mode_manager_examples.info.yml index 3de9ce6..f3ce972 100644 --- a/modules/examples/form_mode_manager_examples.info.yml +++ b/modules/examples/form_mode_manager_examples.info.yml @@ -1,9 +1,7 @@ name: Form Mode Manager examples type: module description: Form Mode Manager allows to use form_mode implement on Drupal 8 on each Entity. -core: 8.x -core_version_requirement: ^8 || ^9 -package: Examples +core_version_requirement: ^8 || ^9 || ^10 dependencies: - drupal:node - drupal:image diff --git a/modules/examples/tests/src/Functional/FormModeManagerExamplesTest.php b/modules/examples/tests/src/Functional/FormModeManagerExamplesTest.php index 3645484..409cc24 100644 --- a/modules/examples/tests/src/Functional/FormModeManagerExamplesTest.php +++ b/modules/examples/tests/src/Functional/FormModeManagerExamplesTest.php @@ -38,7 +38,7 @@ class FormModeManagerExamplesTest extends BrowserTestBase { /** * {@inheritdoc} */ - public function setUp() { + public function setUp(): void { parent::setUp(); // Theme needs to be set before enabling form_mode_manager_examples because, // of dependency. diff --git a/modules/form_mode_theme_switcher/form_mode_manager_theme_switcher.info.yml b/modules/form_mode_theme_switcher/form_mode_manager_theme_switcher.info.yml index ab4d316..fc89942 100644 --- a/modules/form_mode_theme_switcher/form_mode_manager_theme_switcher.info.yml +++ b/modules/form_mode_theme_switcher/form_mode_manager_theme_switcher.info.yml @@ -2,7 +2,7 @@ name: Form Mode Manager Theme Switcher type: module description: Allows to define theme applicable per form_mode using form mode manager. core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 package: Fields configure: form_mode_manager.theme_switcher_settings dependencies: diff --git a/modules/form_mode_user_roles_assign/form_mode_user_roles_assign.info.yml b/modules/form_mode_user_roles_assign/form_mode_user_roles_assign.info.yml index 2c18efb..641c65b 100644 --- a/modules/form_mode_user_roles_assign/form_mode_user_roles_assign.info.yml +++ b/modules/form_mode_user_roles_assign/form_mode_user_roles_assign.info.yml @@ -2,7 +2,7 @@ name: Form Mode Manager User Roles Assign type: module description: Allows to define automatic roles assignements for user register form. core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 package: Fields configure: form_mode_manager.admin_settings_roles_assign dependencies: diff --git a/src/Form/FormModeManagerDisplayEditForm.php b/src/Form/FormModeManagerDisplayEditForm.php index a6483fe..ef9d300 100644 --- a/src/Form/FormModeManagerDisplayEditForm.php +++ b/src/Form/FormModeManagerDisplayEditForm.php @@ -9,8 +9,12 @@ use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Field\FieldTypePluginManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteBuilderInterface; -use Drupal\field_ui\Form\EntityFormDisplayEditForm; +use Drupal\field_ui\Form\EntityDisplayFormBase; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\PluginSettingsInterface; +use Drupal\Core\Url; +use Drupal\field_ui\FieldUI; /** * Form Mode Manager enhancements for edit form of the EntityFormDisplay. @@ -22,7 +26,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * and light way to add Form Mode Manager custom comportements like field_ui, * way with `EntityFormDisplayEditForm`. */ -class FormModeManagerDisplayEditForm extends EntityFormDisplayEditForm { +class FormModeManagerDisplayEditForm extends EntityDisplayFormBase { + + /** + * {@inheritdoc} + */ + protected $displayContext = 'form'; /** * The cache tags invalidator. @@ -53,9 +62,15 @@ class FormModeManagerDisplayEditForm extends EntityFormDisplayEditForm { * The cache tags invalidator. * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder * The route builder service. + * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface|null $entity_display_repository + * (optional) The entity display_repository. + * @param \Drupal\Core\Entity\EntityFieldManagerInterface|null $entity_field_manager + * (optional) The entity field manager. */ public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, EntityDisplayRepositoryInterface $entity_display_repository, EntityFieldManagerInterface $entity_field_manager, CacheTagsInvalidatorInterface $cache_tags_invalidator, RouteBuilderInterface $route_builder) { parent::__construct($field_type_manager, $plugin_manager, $entity_display_repository, $entity_field_manager); + $this->entityDisplayRepository = $entity_display_repository; + $this->entityFieldManager = $entity_field_manager; $this->cacheTagsInvalidator = $cache_tags_invalidator; $this->routeBuilder = $route_builder; } @@ -74,6 +89,120 @@ class FormModeManagerDisplayEditForm extends EntityFormDisplayEditForm { ); } + /** + * {@inheritdoc} + */ + protected function buildFieldRow(FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) { + $field_row = parent::buildFieldRow($field_definition, $form, $form_state); + + $field_name = $field_definition->getName(); + + // Update the (invisible) title of the 'plugin' column. + $field_row['plugin']['#title'] = $this->t('Formatter for @title', ['@title' => $field_definition->getLabel()]); + if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $this->entity->getRenderer($field_name))) { + $plugin_type_info = $plugin->getPluginDefinition(); + $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' ' . $plugin_type_info['label'] . ''; + } + + return $field_row; + } + + /** + * {@inheritdoc} + */ + protected function getEntityDisplay($entity_type_id, $bundle, $mode) { + return $this->entityDisplayRepository->getFormDisplay($entity_type_id, $bundle, $mode); + } + + /** + * {@inheritdoc} + */ + protected function getDefaultPlugin($field_type) { + return $this->fieldTypes[$field_type]['default_widget'] ?? NULL; + } + + /** + * {@inheritdoc} + */ + protected function getDisplayModes() { + return $this->entityDisplayRepository->getFormModes($this->entity->getTargetEntityTypeId()); + } + + /** + * {@inheritdoc} + */ + protected function getDisplayModeOptions() { + return $this->entityDisplayRepository->getFormModeOptions($this->entity->getTargetEntityTypeId()); + } + + /** + * {@inheritdoc} + */ + protected function getDisplayModesLink() { + return [ + '#type' => 'link', + '#title' => $this->t('Manage form modes'), + '#url' => Url::fromRoute('entity.entity_form_mode.collection'), + ]; + } + + /** + * {@inheritdoc} + */ + protected function getTableHeader() { + return [ + $this->t('Field'), + $this->t('Weight'), + $this->t('Parent'), + $this->t('Region'), + ['data' => $this->t('Widget'), 'colspan' => 3], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getOverviewUrl($mode) { + $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId()); + return Url::fromRoute('entity.entity_form_display.' . $this->entity->getTargetEntityTypeId() . '.form_mode', [ + 'form_mode_name' => $mode, + ] + FieldUI::getRouteBundleParameter($entity_type, $this->entity->getTargetBundle())); + } + + /** + * {@inheritdoc} + */ + protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) { + $settings_form = []; + // Invoke hook_field_widget_third_party_settings_form(), keying resulting + // subforms by module name. + $this->moduleHandler->invokeAllWith( + 'field_widget_third_party_settings_form', + function (callable $hook, string $module) use (&$settings_form, $plugin, $field_definition, &$form, $form_state) { + $settings_form[$module] = $hook( + $plugin, + $field_definition, + $this->entity->getMode(), + $form, + $form_state + ); + } + ); + return $settings_form; + } + + /** + * {@inheritdoc} + */ + protected function alterSettingsSummary(array &$summary, PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition) { + $context = [ + 'widget' => $plugin, + 'field_definition' => $field_definition, + 'form_mode' => $this->entity->getMode(), + ]; + $this->moduleHandler->alter('field_widget_settings_summary', $summary, $context); + } + /** * {@inheritdoc} * diff --git a/tests/src/Functional/DisplayFormModeTestTrait.php b/tests/src/Functional/DisplayFormModeTestTrait.php index eae0bef..c5e16ee 100644 --- a/tests/src/Functional/DisplayFormModeTestTrait.php +++ b/tests/src/Functional/DisplayFormModeTestTrait.php @@ -9,6 +9,8 @@ use Drupal\Core\Entity\Entity\EntityFormMode; */ trait DisplayFormModeTestTrait { + protected $defaultTheme = 'stark'; + /** * Creates a Form Mode based on default settings. * diff --git a/tests/src/Functional/FormModeManagerBase.php b/tests/src/Functional/FormModeManagerBase.php index 89f143c..2990e46 100644 --- a/tests/src/Functional/FormModeManagerBase.php +++ b/tests/src/Functional/FormModeManagerBase.php @@ -21,6 +21,7 @@ abstract class FormModeManagerBase extends BrowserTestBase { * @var string[] */ protected static $modules = [ + 'block', 'entity_test', 'field', 'field_ui', @@ -109,7 +110,7 @@ abstract class FormModeManagerBase extends BrowserTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Setup correct blocks in regions. diff --git a/tests/src/Functional/FormModeManagerRouteTest.php b/tests/src/Functional/FormModeManagerRouteTest.php index 1d80293..23961e2 100644 --- a/tests/src/Functional/FormModeManagerRouteTest.php +++ b/tests/src/Functional/FormModeManagerRouteTest.php @@ -11,6 +11,8 @@ use Drupal\user\Entity\Role; */ class FormModeManagerRouteTest extends FormModeManagerBase { + protected $defaultTheme = 'stark'; + /** * An user with administrative permissions. * @@ -235,7 +237,8 @@ class FormModeManagerRouteTest extends FormModeManagerBase { $this->drupalGet("admin/structure/types/manage/{$node_type_fmm2->id()}/form-display"); $edit = ["display_modes_custom[$node_form_mode_id]" => TRUE]; - $this->drupalPostForm("admin/structure/types/manage/{$node_type_fmm2->id()}/form-display", $edit, t('Save')); + $this->drupalGet("admin/structure/types/manage/{$node_type_fmm2->id()}/form-display"); + $this->submitForm($edit, t('Save')); $this->drupalGet("node/add-list/$node_form_mode_id"); $this->assertSession()->linkExists($this->nodeTypeFmm1->label()); diff --git a/tests/src/Functional/FormModeManagerUiTest.php b/tests/src/Functional/FormModeManagerUiTest.php index c224dc9..59523d8 100644 --- a/tests/src/Functional/FormModeManagerUiTest.php +++ b/tests/src/Functional/FormModeManagerUiTest.php @@ -15,6 +15,8 @@ class FormModeManagerUiTest extends FormModeManagerBase { use TaxonomyTestTrait; + protected $defaultTheme = 'stark'; + /** * Stores the node content used by this test. * @@ -74,7 +76,7 @@ class FormModeManagerUiTest extends FormModeManagerBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Hide field for already existing form modes. @@ -336,7 +338,8 @@ class FormModeManagerUiTest extends FormModeManagerBase { $this->drupalGet("admin/config/people/accounts/form-display"); $edit = ["display_modes_custom[{$this->formModeManager->getFormModeMachineName($user_form_mode->id())}]" => TRUE]; - $this->drupalPostForm("admin/config/people/accounts/form-display", $edit, t('Save')); + $this->drupalGet("admin/config/people/accounts/form-display"); + $this->submitForm($edit, t('Save')); $this->drupalLogin($this->adminUser); $this->drupalGet('admin/people'); @@ -356,7 +359,8 @@ class FormModeManagerUiTest extends FormModeManagerBase { $this->drupalGet("admin/structure/taxonomy/manage/{$this->vocabulary->id()}/overview/form-display"); $edit = ["display_modes_custom[{$this->formModeManager->getFormModeMachineName($term_form_mode->id())}]" => TRUE]; - $this->drupalPostForm("admin/structure/taxonomy/manage/{$this->vocabulary->id()}/overview/form-display", $edit, t('Save')); + $this->drupalGet("admin/structure/taxonomy/manage/{$this->vocabulary->id()}/overview/form-display"); + $this->submitForm($edit, t('Save')); Role::load($this->adminUser->getRoles()[1]) ->grantPermission('administer taxonomy')