diff options
Diffstat (limited to 'core/modules/field')
9 files changed, 43 insertions, 47 deletions
diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 1819df65669d..ee5db3615262 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -16,10 +16,6 @@ use Drupal\Core\Form\FormStateInterface; require_once __DIR__ . '/field.purge.inc'; /** - * @} End of "defgroup field". - */ - -/** * Assembles a partial entity structure with initial IDs. * * @param object $ids diff --git a/core/modules/field/src/Hook/FieldHooks.php b/core/modules/field/src/Hook/FieldHooks.php index aa759522f458..e94e084ea3e3 100644 --- a/core/modules/field/src/Hook/FieldHooks.php +++ b/core/modules/field/src/Hook/FieldHooks.php @@ -257,6 +257,10 @@ class FieldHooks { } /** + * @} End of "defgroup field". + */ + + /** * Implements hook_config_import_steps_alter(). */ #[Hook('config_import_steps_alter')] @@ -313,8 +317,8 @@ class FieldHooks { /** * Implements hook_ENTITY_TYPE_update() for 'field_storage_config'. * - * Reset the field handler settings, when the storage target_type is changed on - * an entity reference field. + * Reset the field handler settings, when the storage target_type is changed + * on an entity reference field. */ #[Hook('field_storage_config_update')] public function fieldStorageConfigUpdate(FieldStorageConfigInterface $field_storage): void { @@ -330,13 +334,14 @@ class FieldHooks { if ($class !== $item_class && !is_subclass_of($class, $item_class)) { return; } - // If target_type changed, reset the handler in the fields using that storage. + // If target_type changed, reset the handler in the fields using that + // storage. if ($field_storage->getSetting('target_type') !== $field_storage->getOriginal()->getSetting('target_type')) { foreach ($field_storage->getBundles() as $bundle) { $field = FieldConfig::loadByName($field_storage->getTargetEntityTypeId(), $bundle, $field_storage->getName()); - // Reset the handler settings. This triggers field_field_config_presave(), - // which will take care of reassigning the handler to the correct - // derivative for the new target_type. + // Reset the handler settings. This triggers + // field_field_config_presave(), which will take care of reassigning the + // handler to the correct derivative for the new target_type. $field->setSetting('handler_settings', []); $field->save(); } @@ -394,9 +399,9 @@ class FieldHooks { return; } // In case we removed all the target bundles allowed by the field in - // EntityReferenceItem::onDependencyRemoval() or field_entity_bundle_delete() - // we have to log a critical message because the field will not function - // correctly anymore. + // EntityReferenceItem::onDependencyRemoval() or + // field_entity_bundle_delete() we have to log a critical message because + // the field will not function correctly anymore. $handler_settings = $field->getSetting('handler_settings'); if (isset($handler_settings['target_bundles']) && $handler_settings['target_bundles'] === []) { \Drupal::logger('entity_reference')->critical('The %field_name entity reference field (entity_type: %entity_type, bundle: %bundle) no longer has any valid bundle it can reference. The field is not working correctly anymore and has to be adjusted.', [ diff --git a/core/modules/field/tests/modules/field_third_party_test/src/Hook/FieldThirdPartyTestHooks.php b/core/modules/field/tests/modules/field_third_party_test/src/Hook/FieldThirdPartyTestHooks.php index 369575020135..dd9a4167ba53 100644 --- a/core/modules/field/tests/modules/field_third_party_test/src/Hook/FieldThirdPartyTestHooks.php +++ b/core/modules/field/tests/modules/field_third_party_test/src/Hook/FieldThirdPartyTestHooks.php @@ -9,6 +9,9 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\WidgetInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\Render\Element\Number; +use Drupal\Core\Render\Element\Textfield; +use Drupal\Core\Render\ElementInfoManagerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; /** @@ -18,17 +21,17 @@ class FieldThirdPartyTestHooks { use StringTranslationTrait; + public function __construct(protected ElementInfoManagerInterface $elementInfoManager) {} + /** * Implements hook_field_widget_third_party_settings_form(). */ #[Hook('field_widget_third_party_settings_form')] public function fieldWidgetThirdPartySettingsForm(WidgetInterface $plugin, FieldDefinitionInterface $field_definition, $form_mode, $form, FormStateInterface $form_state): array { - $element['field_test_widget_third_party_settings_form'] = [ - '#type' => 'textfield', - '#title' => $this->t('3rd party widget settings form'), - '#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'field_test_widget_third_party_settings_form'), - ]; - return $element; + $textfield = $this->elementInfoManager->fromClass(Textfield::class); + $textfield->title = $this->t('3rd party widget settings form'); + $textfield->default_value = $plugin->getThirdPartySetting('field_third_party_test', 'field_test_widget_third_party_settings_form'); + return $textfield->toRenderable('field_test_widget_third_party_settings_form'); } /** @@ -36,12 +39,10 @@ class FieldThirdPartyTestHooks { */ #[Hook('field_widget_third_party_settings_form')] public function fieldWidgetThirdPartySettingsFormAdditionalImplementation(WidgetInterface $plugin, FieldDefinitionInterface $field_definition, $form_mode, $form, FormStateInterface $form_state): array { - $element['second_field_widget_third_party_settings_form'] = [ - '#type' => 'number', - '#title' => $this->t('Second 3rd party widget settings form'), - '#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'second_field_widget_third_party_settings_form'), - ]; - return $element; + $number = $this->elementInfoManager->fromClass(Number::class); + $number->title = $this->t('Second 3rd party widget settings form'); + $number->default_value = $plugin->getThirdPartySetting('field_third_party_test', 'second_field_widget_third_party_settings_form'); + return $number->toRenderable('second_field_widget_third_party_settings_form'); } /** @@ -57,12 +58,10 @@ class FieldThirdPartyTestHooks { */ #[Hook('field_formatter_third_party_settings_form')] public function fieldFormatterThirdPartySettingsForm(FormatterInterface $plugin, FieldDefinitionInterface $field_definition, $view_mode, $form, FormStateInterface $form_state): array { - $element['field_test_field_formatter_third_party_settings_form'] = [ - '#type' => 'textfield', - '#title' => $this->t('3rd party formatter settings form'), - '#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'), - ]; - return $element; + $textfield = $this->elementInfoManager->fromClass(Textfield::class); + $textfield->title = $this->t('3rd party formatter settings form'); + $textfield->default_value = $plugin->getThirdPartySetting('field_third_party_test', 'field_test_field_formatter_third_party_settings_form'); + return $textfield->toRenderable('field_test_field_formatter_third_party_settings_form'); } /** @@ -70,12 +69,10 @@ class FieldThirdPartyTestHooks { */ #[Hook('field_formatter_third_party_settings_form')] public function fieldFormatterThirdPartySettingsFormAdditionalImplementation(FormatterInterface $plugin, FieldDefinitionInterface $field_definition, $view_mode, $form, FormStateInterface $form_state): array { - $element['second_field_formatter_third_party_settings_form'] = [ - '#type' => 'number', - '#title' => $this->t('Second 3rd party formatter settings form'), - '#default_value' => $plugin->getThirdPartySetting('field_third_party_test', 'second_field_formatter_third_party_settings_form'), - ]; - return $element; + $number = $this->elementInfoManager->fromClass(Number::class); + $number->title = $this->t('Second 3rd party formatter settings form'); + $number->default_value = $plugin->getThirdPartySetting('field_third_party_test', 'second_field_formatter_third_party_settings_form'); + return $number->toRenderable('second_field_formatter_third_party_settings_form'); } /** diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php index d8496e30e99b..407fdd794a45 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php @@ -192,7 +192,7 @@ class EntityReferenceAdminTest extends BrowserTestBase { $this->assertSession()->pageTextContains('Multiple content items match this reference;'); $this->assertSession()->pageTextContains($node1->getTitle() . ' (' . $node1->id() . ')'); $this->assertSession()->pageTextContains($node2->getTitle() . ' (' . $node2->id() . ')'); - $this->assertSession()->pageTextContains('Specify the one you want by appending the id in parentheses, like "' . $node2->getTitle() . ' (' . $node2->id() . ')' . '".'); + $this->assertSession()->pageTextContains('Specify the one you want by appending the id in parentheses, like "' . $node2->getTitle() . ' (' . $node2->id() . ')".'); $edit = [ 'title[0][value]' => 'Test', diff --git a/core/modules/field/tests/src/Functional/FunctionalString/StringFieldTest.php b/core/modules/field/tests/src/Functional/FunctionalString/StringFieldTest.php index de14164bd807..48a5c652c8c8 100644 --- a/core/modules/field/tests/src/Functional/FunctionalString/StringFieldTest.php +++ b/core/modules/field/tests/src/Functional/FunctionalString/StringFieldTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Drupal\Tests\field\Functional\FunctionalString; -use Drupal\Component\Render\FormattableMarkup; use Drupal\entity_test\Entity\EntityTest; use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; @@ -95,7 +94,7 @@ class StringFieldTest extends BrowserTestBase { $this->drupalGet('entity_test/add'); $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", ''); $this->assertSession()->fieldNotExists("{$field_name}[0][format]"); - $this->assertSession()->responseContains(new FormattableMarkup('placeholder="A placeholder on @widget_type"', ['@widget_type' => $widget_type])); + $this->assertSession()->responseContains('placeholder="A placeholder on ' . $widget_type . '"'); // Submit with some value. $value = $this->randomMachineName(); diff --git a/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php b/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php index 129f28576d61..76907277eae1 100644 --- a/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php +++ b/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Drupal\Tests\field\FunctionalJavascript\EntityReference; use Behat\Mink\Element\NodeElement; -use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Url; use Drupal\FunctionalJavascriptTests\WebDriverTestBase; use Drupal\Tests\field_ui\Traits\FieldUiJSTestTrait; @@ -317,10 +316,9 @@ class EntityReferenceAdminTest extends WebDriverTestBase { // Try to select the views handler. $this->drupalGet($bundle_path . '/fields/' . $field_name); $page->findField('settings[handler]')->setValue('views'); - $views_text = (string) new FormattableMarkup('No eligible views were found. <a href=":create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href=":existing">existing view</a>.', [ - ':create' => Url::fromRoute('views_ui.add')->toString(), - ':existing' => Url::fromRoute('entity.view.collection')->toString(), - ]); + $create = Url::fromRoute('views_ui.add')->toString(); + $existing = Url::fromRoute('entity.view.collection')->toString(); + $views_text = 'No eligible views were found. <a href="' . $create . '">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href="' . $existing . '">existing view</a>.'; $assert_session->waitForElement('xpath', '//a[contains(text(), "Create a view")]'); $assert_session->responseContains($views_text); diff --git a/core/modules/field/tests/src/Kernel/FieldCrudTest.php b/core/modules/field/tests/src/Kernel/FieldCrudTest.php index 278f8dbc87c3..bf1e0cf5c575 100644 --- a/core/modules/field/tests/src/Kernel/FieldCrudTest.php +++ b/core/modules/field/tests/src/Kernel/FieldCrudTest.php @@ -313,7 +313,7 @@ class FieldCrudTest extends FieldKernelTestBase { $this->assertCount(0, $fields, 'A deleted field is marked for deletion.'); // Try to load the field normally and make sure it does not show up. - $field = FieldConfig::load('entity_test.' . '.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']); + $field = FieldConfig::load('entity_test.' . $this->fieldDefinition['bundle'] . '.' . $this->fieldDefinition['field_name']); $this->assertTrue(empty($field), 'Field was deleted'); // Make sure the other field is not deleted. diff --git a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php index f845abeba457..849dd2402125 100644 --- a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php +++ b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php @@ -357,7 +357,7 @@ class FieldStorageCrudTest extends FieldKernelTestBase { $this->assertEmpty($field_storage, 'Field storage was deleted'); // Try to load the field normally and make sure it does not show up. - $field = FieldConfig::load('entity_test.' . '.' . $field_definition['bundle'] . '.' . $field_definition['field_name']); + $field = FieldConfig::load('entity_test.' . $field_definition['bundle'] . '.' . $field_definition['field_name']); $this->assertEmpty($field, 'Field was deleted'); // Make sure the other field and its storage are not deleted. diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php index ca81ab17602b..20ea2c954b2c 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceLabelDescriptionTest.php @@ -13,6 +13,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase; * Tests migration of field label and description translations. * * @group migrate_drupal_6 + * @group #slow */ class MigrateFieldInstanceLabelDescriptionTest extends MigrateDrupal6TestBase implements MigrateDumpAlterInterface { |